@@ -425,51 +425,75 @@ private ReviewFeatureResponseDTO getReviewFeatureDTO(final BindingSet bindings)
425
425
426
426
427
427
private ReviewDTO getReviewDTO (final BindingSet bindings ) {
428
- ReviewDTO ReviewDTO = new ReviewDTO ();
428
+ ReviewDTO reviewDTO = new ReviewDTO ();
429
+
429
430
if (existsShortReviewBinding (bindings )) {
430
431
if (bindings .getBinding ("id" ) != null && bindings .getBinding ("id" ).getValue () != null ) {
431
432
String idValue = bindings .getBinding ("id" ).getValue ().stringValue ();
432
- ReviewDTO .setId (idValue );
433
+ reviewDTO .setId (idValue );
433
434
}
434
435
435
436
if (bindings .getBinding ("text" ) != null && bindings .getBinding ("text" ).getValue () != null ) {
436
437
String textValue = bindings .getBinding ("text" ).getValue ().stringValue ();
437
- ReviewDTO .setReviewText (textValue );
438
+ reviewDTO .setReviewText (textValue );
438
439
}
439
440
440
441
if (bindings .getBinding ("app_identifier" ) != null && bindings .getBinding ("app_identifier" ).getValue () != null ) {
441
442
String appValue = bindings .getBinding ("app_identifier" ).getValue ().stringValue ();
442
- ReviewDTO .setApplicationId (appValue );
443
-
443
+ reviewDTO .setApplicationId (appValue );
444
444
}
445
445
446
446
if (bindings .getBinding ("date" ) != null && bindings .getBinding ("date" ).getValue () != null ) {
447
447
String dateString = bindings .getBinding ("date" ).getValue ().stringValue ();
448
- try {
449
- SimpleDateFormat dateFormat = new SimpleDateFormat ( "yyyy-MM-dd" );
450
- Date date = dateFormat . parse ( dateString );
451
- ReviewDTO .setDate (date );
452
- } catch ( ParseException e ) {
453
- e . printStackTrace ( );
448
+
449
+ Date date = parseDate ( dateString );
450
+ if ( date != null ) {
451
+ reviewDTO .setDate (date );
452
+ } else {
453
+ System . err . println ( "Failed to parse date: " + dateString );
454
454
}
455
455
}
456
456
}
457
- ReviewDTO .setSentences (new ArrayList <>());
458
- TupleQueryResult sentencesResult =
459
- runSparqlQuery (reviewQueryBuilder .findReviewSentencesEmotions (new ArrayList <>(Collections .singleton (ReviewDTO .getId ()))));
457
+
458
+ reviewDTO .setSentences (new ArrayList <>());
459
+ TupleQueryResult sentencesResult = runSparqlQuery (
460
+ reviewQueryBuilder .findReviewSentencesEmotions (new ArrayList <>(Collections .singleton (reviewDTO .getId ())))
461
+ );
462
+
460
463
if (sentencesResult .hasNext ()) {
461
464
while (sentencesResult .hasNext ()) {
462
- ReviewDTO
463
- .getSentences ()
464
- .add (getSentenceDTO (sentencesResult ));
465
+ reviewDTO .getSentences ().add (getSentenceDTO (sentencesResult ));
465
466
}
466
467
} else {
467
- ReviewDTO .setSentences (new ArrayList <>());
468
+ reviewDTO .setSentences (new ArrayList <>());
468
469
}
469
470
470
- return ReviewDTO ;
471
+ return reviewDTO ;
471
472
}
472
473
474
+ private Date parseDate (String dateString ) {
475
+ List <String > dateFormats = Arrays .asList (
476
+ "yyyy-MM-dd" ,
477
+ "EEE MMM dd HH:mm:ss z yyyy" ,
478
+ "MM/dd/yyyy" ,
479
+ "dd/MM/yyyy" ,
480
+ "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ,
481
+ "yyyy-MM-dd'T'HH:mm:ss'Z'" ,
482
+ "yyyy-MM-dd HH:mm:ss"
483
+ );
484
+
485
+ for (String format : dateFormats ) {
486
+ try {
487
+ SimpleDateFormat dateFormat = new SimpleDateFormat (format , Locale .ENGLISH );
488
+ dateFormat .setLenient (false );
489
+ return dateFormat .parse (dateString );
490
+ } catch (ParseException ignored ) {
491
+ }
492
+ }
493
+
494
+ System .err .println ("Failed to parse date: " + dateString );
495
+ return null ; // If no formats match
496
+ }
473
497
private boolean existsShortReviewBinding (BindingSet bindings ) {
474
498
return bindings .getBinding ("id" ) != null
475
499
&& bindings .getBinding ("id" ).getValue () != null
0 commit comments