Skip to content

Commit

Permalink
Merge pull request #494 from folio-org/MODFQMMGR-536-broken-dates
Browse files Browse the repository at this point in the history
  • Loading branch information
mweaver-ebsco authored Oct 22, 2024
2 parents 94187da + ada3a3a commit 7e9c0b9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 29 deletions.
26 changes: 13 additions & 13 deletions src/main/java/org/folio/fqm/service/FqlToSqlConverterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static Condition getSqlCondition(FqlCondition<?> fqlCondition, EntityType

private static Condition handleEquals(EqualsCondition equalsCondition, EntityType entityType, org.jooq.Field<Object> field) {
if (isDateCondition(equalsCondition, entityType)) {
return handleDate(equalsCondition, field);
return handleDate(equalsCondition, field, entityType);
}
String dataType = getFieldDataType(entityType, equalsCondition);
String filterFieldDataType = getFieldForFiltering(equalsCondition, entityType).getDataType().getDataType();
Expand All @@ -157,7 +157,7 @@ private static Condition handleEquals(EqualsCondition equalsCondition, EntityTyp

private static Condition handleNotEquals(NotEqualsCondition notEqualsCondition, EntityType entityType, org.jooq.Field<Object> field) {
if (isDateCondition(notEqualsCondition, entityType)) {
return handleDate(notEqualsCondition, field);
return handleDate(notEqualsCondition, field, entityType);
}
String dataType = getFieldDataType(entityType, notEqualsCondition);
String filterFieldDataType = getFieldForFiltering(notEqualsCondition, entityType).getDataType().getDataType();
Expand All @@ -175,7 +175,7 @@ private static Condition handleNotEquals(NotEqualsCondition notEqualsCondition,
return field.ne(valueField(notEqualsCondition.value(), notEqualsCondition, entityType));
}

private static Condition handleDate(FieldCondition<?> fieldCondition, org.jooq.Field<Object> field) {
private static Condition handleDate(FieldCondition<?> fieldCondition, org.jooq.Field<Object> field, EntityType entityType) {
String dateString = (String) fieldCondition.value();
Condition condition = falseCondition();
LocalDateTime dateTime;
Expand All @@ -190,22 +190,22 @@ private static Condition handleDate(FieldCondition<?> fieldCondition, org.jooq.F

LocalDateTime nextDayDateTime = dateTime.plusDays(1);
if (fieldCondition instanceof EqualsCondition) {
condition = field.greaterOrEqual(dateTime.format(DATE_TIME_FORMATTER))
.and(field.lessThan(nextDayDateTime.format(DATE_TIME_FORMATTER)));
condition = field.greaterOrEqual(valueField(dateTime.format(DATE_TIME_FORMATTER), fieldCondition, entityType))
.and(field.lessThan(valueField(nextDayDateTime.format(DATE_TIME_FORMATTER), fieldCondition, entityType)));
} else if (fieldCondition instanceof NotEqualsCondition) {
condition = field.greaterOrEqual(nextDayDateTime.format(DATE_TIME_FORMATTER))
.or(field.lessThan(dateTime.format(DATE_TIME_FORMATTER)));
condition = field.greaterOrEqual(valueField(nextDayDateTime.format(DATE_TIME_FORMATTER), fieldCondition, entityType))
.or(field.lessThan(valueField(dateTime.format(DATE_TIME_FORMATTER), fieldCondition, entityType)));
} else if (fieldCondition instanceof GreaterThanCondition greaterThanCondition) {
if (greaterThanCondition.orEqualTo()) {
condition = field.greaterOrEqual(dateTime.format(DATE_TIME_FORMATTER));
condition = field.greaterOrEqual(valueField(dateTime.format(DATE_TIME_FORMATTER), fieldCondition, entityType));
} else {
condition = field.greaterOrEqual(nextDayDateTime.format(DATE_TIME_FORMATTER));
condition = field.greaterOrEqual(valueField(nextDayDateTime.format(DATE_TIME_FORMATTER), fieldCondition, entityType));
}
} else if (fieldCondition instanceof LessThanCondition lessThanCondition) {
if (lessThanCondition.orEqualTo()) {
condition = field.lessThan(nextDayDateTime.format(DATE_TIME_FORMATTER));
condition = field.lessThan(valueField(nextDayDateTime.format(DATE_TIME_FORMATTER), fieldCondition, entityType));
} else {
condition = field.lessThan(dateTime.format(DATE_TIME_FORMATTER));
condition = field.lessThan(valueField(dateTime.format(DATE_TIME_FORMATTER), fieldCondition, entityType));
}
}
return condition;
Expand Down Expand Up @@ -274,7 +274,7 @@ private static Condition handleNotIn(NotInCondition notInCondition, EntityType e

private static Condition handleGreaterThan(GreaterThanCondition greaterThanCondition, EntityType entityType, org.jooq.Field<Object> field) {
if (isDateCondition(greaterThanCondition, entityType)) {
return handleDate(greaterThanCondition, field);
return handleDate(greaterThanCondition, field, entityType);
}
if (greaterThanCondition.orEqualTo()) {
return field.greaterOrEqual(valueField(greaterThanCondition.value(), greaterThanCondition, entityType));
Expand All @@ -284,7 +284,7 @@ private static Condition handleGreaterThan(GreaterThanCondition greaterThanCondi

private static Condition handleLessThan(LessThanCondition lessThanCondition, EntityType entityType, org.jooq.Field<Object> field) {
if (isDateCondition(lessThanCondition, entityType)) {
return handleDate(lessThanCondition, field);
return handleDate(lessThanCondition, field, entityType);
}
if (lessThanCondition.orEqualTo()) {
return field.lessOrEqual(valueField(lessThanCondition.value(), lessThanCondition, entityType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
join: {
type: 'left join',
joinTo: 'holdings.hrd',
condition: "(:that.jsonb ->> 'instanceid')::uuid = :this.id",
condition: "(:that.jsonb ->> 'instanceId')::uuid = :this.id",
},
},
],
Expand Down
13 changes: 1 addition & 12 deletions src/main/resources/entity-types/circulation/simple_loan.json5
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
hidden: false,
essential: true,
valueGetter: ':sourceAlias.creation_date',
valueFunction: '(:value)::timestamp',
},
{
name: 'created_by',
Expand Down Expand Up @@ -398,18 +399,6 @@
visibleByDefault: false,
valueGetter: ":sourceAlias.jsonb->'reminders'->'lastFeeBilled'->>'number'",
},
{
name: 'reminders_last_date',
sourceAlias: 'loan',
dataType: {
dataType: 'dateType',
},
isIdColumn: false,
queryable: true,
visibleByDefault: false,
essential: true,
valueGetter: ":sourceAlias.jsonb->'reminders'->'lastFeeBilled'->>'date'",
},
{
name: 'jsonb',
sourceAlias: 'loan',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
queryable: true,
visibleByDefault: true,
valueGetter: ':sourceAlias.creation_date',
valueFunction: '(:value)::timestamp',
essential: true
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@
queryable: true,
visibleByDefault: true,
essential: true,
valueGetter: ":sourceAlias.jsonb->'metadata'->>'createdDate'",
filterValueGetter: "\"left\"(lower((:sourceAlias.jsonb -> 'metadata'::text) ->> 'createdDate'::text), 600)",
valueFunction: '"left"(lower(:value), 600)'
valueGetter: ":sourceAlias.creation_date",
valueFunction: '(:value)::timestamp',
},
{
name: 'updated_by',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
queryable: true,
visibleByDefault: false,
valueGetter: ':sourceAlias.creation_date',
valueFunction: '(:value)::timestamp',
},
{
name: 'created_by',
Expand Down

0 comments on commit 7e9c0b9

Please sign in to comment.