From 5bd6d23958ec790a545f052837350a7cdc9305e1 Mon Sep 17 00:00:00 2001 From: Rob Stine Date: Sun, 21 Mar 2021 20:07:38 -0400 Subject: [PATCH] #2014 update. DOB was incorrectly overriding query field/type on all operator types instead of greater than less than and equality checks. --- .../gov/gtas/querybuilder/JPQLGenerator.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gtas-parent/gtas-commons/src/main/java/gov/gtas/querybuilder/JPQLGenerator.java b/gtas-parent/gtas-commons/src/main/java/gov/gtas/querybuilder/JPQLGenerator.java index 9a611b0780..782a85b92e 100644 --- a/gtas-parent/gtas-commons/src/main/java/gov/gtas/querybuilder/JPQLGenerator.java +++ b/gtas-parent/gtas-commons/src/main/java/gov/gtas/querybuilder/JPQLGenerator.java @@ -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, @@ -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, @@ -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, @@ -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, @@ -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]); @@ -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]); @@ -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();