Skip to content

Commit

Permalink
#2014 update. DOB was incorrectly overriding query field/type on all
Browse files Browse the repository at this point in the history
operator types instead of greater than less than and equality checks.
  • Loading branch information
originalname51 committed Mar 22, 2021
1 parent 9222ea5 commit 5bd6d23
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,15 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
QueryTerm qt = (QueryTerm) qe;
if (qt.getEntity().equalsIgnoreCase(EntityEnum.PASSENGER.getEntityName()) &&
qt.getField().equalsIgnoreCase("passengerDetails.age")) {

String replacementField = "passengerDetails.dob";
String replacementType = "date";
qt.setField(replacementField);
qt.setType(replacementType);


//Handle UTC offsets.
LocalDateTime localDatetime = LocalDateTime.now();
localDatetime = localDatetime.minusMinutes(utcMinuteOffset);

LocalDate localDate = localDatetime.toLocalDate();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String replacementField = "passengerDetails.dob";
String replacementType = "date";
switch (qt.getOperator()) {
case LESS:
// Because dates are stored as the "greatest date" being the date in the future,
Expand All @@ -188,6 +185,8 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
LocalDate lessTime = localDate.minusYears(lessAge + 1);
String[] lessReplacementValue = new String[] {lessTime.format(formatter)};
qt.setValue(lessReplacementValue);
qt.setField(replacementField);
qt.setType(replacementType);
break;
case LESS_OR_EQUAL:
// Because dates are stored as the "greatest date" being the date in the future,
Expand All @@ -196,7 +195,9 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
int lessEqualAge = Integer.parseInt(qt.getValue()[0]);
LocalDate lessEqualTime = localDate.minusYears(lessEqualAge + 1);
String[] lessEqualReplacementValue = new String[] {lessEqualTime.format(formatter)};
qt.setValue(lessEqualReplacementValue);
qt.setValue(lessEqualReplacementValue);
qt.setField(replacementField);
qt.setType(replacementType);
break;
case GREATER_OR_EQUAL:
// Because dates are stored as the "greatest date" being the date in the future,
Expand All @@ -206,6 +207,8 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
LocalDate greaterOrEqualTime = localDate.minusYears(greaterOrEqualAge);
String[] greaterOrEqualVal = new String[] {greaterOrEqualTime.format(formatter)};
qt.setValue(greaterOrEqualVal);
qt.setField(replacementField);
qt.setType(replacementType);
break;
case GREATER:
// Because dates are stored as the "greatest date" being the date in the future,
Expand All @@ -214,7 +217,9 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
int greaterAge = Integer.parseInt(qt.getValue()[0]);
LocalDate greaterTime = localDate.minusYears(greaterAge);
String[] greaterValue = new String[] {greaterTime.format(formatter)};
qt.setValue(greaterValue);
qt.setValue(greaterValue);
qt.setField(replacementField);
qt.setType(replacementType);
break;
case EQUAL:
int equalAge = Integer.parseInt(qt.getValue()[0]);
Expand All @@ -225,6 +230,8 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
qt.setOperator(BETWEEN);
String[] replacementValueEqual = new String[] {equalAgeStart.format(formatter), equalAgeFinish.format(formatter)};
qt.setValue(replacementValueEqual);
qt.setField(replacementField);
qt.setType(replacementType);
break;
case NOT_EQUAL:
int notEqualAge = Integer.parseInt(qt.getValue()[0]);
Expand All @@ -235,6 +242,8 @@ private static void convertAgeToDob(QueryObject queryObject, int utcMinuteOffset
qt.setOperator(NOT_BETWEEN);
String[] replacementValueNotEqual = new String[] {notEqualAgeStart.format(formatter), notEqualAgeFinish.format(formatter)};
qt.setValue(replacementValueNotEqual);
qt.setField(replacementField);
qt.setType(replacementType);
break;
default:
String message = "No conversion from age to date for query operator of " + qt.getOperator();
Expand Down

0 comments on commit 5bd6d23

Please sign in to comment.