From c4a0d3d346ab86349505113fcf5b3ac3b63daac2 Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Thu, 12 Sep 2024 08:35:16 -0400 Subject: [PATCH 1/2] fix: Condition with `_To` column. --- .../report_engine/format/QueryDefinition.java | 33 +++++++++++-------- .../report_engine/service/ReportBuilder.java | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/spin/report_engine/format/QueryDefinition.java b/src/main/java/org/spin/report_engine/format/QueryDefinition.java index b78cd1c..6885193 100644 --- a/src/main/java/org/spin/report_engine/format/QueryDefinition.java +++ b/src/main/java/org/spin/report_engine/format/QueryDefinition.java @@ -49,7 +49,7 @@ private QueryDefinition() { conditions = new ArrayList(); columns = new ArrayList(); queryColumns = new ArrayList(); - parameters = new ArrayList(); + this.parameters = new ArrayList(); } public static QueryDefinition newInstance() { @@ -126,7 +126,7 @@ public QueryDefinition withQueryColumns(List queryColumns) { } public List getParameters() { - return parameters; + return this.parameters; } public String getWhereClause() { @@ -168,10 +168,15 @@ public QueryDefinition buildQuery() { .filter(condition -> !Util.isEmpty(condition.getColumnName(), true)) .forEach(condition -> { Optional maybeColumn = getColumns() - .stream() - .filter(column -> column.getColumnName().equals(condition.getColumnName())) - .sorted(Comparator.comparing(PrintFormatColumn::getColumnNameAlias).reversed()) - .findFirst(); + .stream() + .filter(column -> { + final String conditionColumnName = condition.getColumnName(); + return conditionColumnName.equals(column.getColumnName()) + || conditionColumnName.equals(column.getColumnName() + "_To"); + }) + .sorted(Comparator.comparing(PrintFormatColumn::getColumnNameAlias).reversed()) + .findFirst() + ; if(maybeColumn.isPresent()) { if (whereClause.length() > 0) { whereClause.append(" AND "); @@ -286,7 +291,7 @@ private String getRestrictionByOperator(Filter condition, int displayType) { displayType, currentValue ); - parameters.add(valueToFilter); + this.parameters.add(valueToFilter); }); } @@ -312,15 +317,15 @@ private String getRestrictionByOperator(Filter condition, int displayType) { if (valueStartToFilter == null) { sqlValue = " ? "; sqlOperator = OperatorUtil.convertOperator(OperatorUtil.LESS_EQUAL); - parameters.add(valueEndToFilter); + this.parameters.add(valueEndToFilter); } else if (valueEndToFilter == null) { sqlValue = " ? "; sqlOperator = OperatorUtil.convertOperator(OperatorUtil.GREATER_EQUAL); - parameters.add(valueStartToFilter); + this.parameters.add(valueStartToFilter); } else { sqlValue = " ? AND ? "; - parameters.add(valueStartToFilter); - parameters.add(valueEndToFilter); + this.parameters.add(valueStartToFilter); + this.parameters.add(valueEndToFilter); } } else if(operatorValue.equals(OperatorUtil.LIKE) || operatorValue.equals(OperatorUtil.NOT_LIKE)) { columnName = "UPPER(" + columnName + ")"; @@ -337,7 +342,7 @@ private String getRestrictionByOperator(Filter condition, int displayType) { // } // valueToFilter = "UPPPER(" + valueToFilter + ")"; sqlValue = "'%' || UPPER(?) || '%'"; - parameters.add(valueToFilter); + this.parameters.add(valueToFilter); } else if(operatorValue.equals(OperatorUtil.NULL) || operatorValue.equals(OperatorUtil.NOT_NULL)) { ; } else if (operatorValue.equals(OperatorUtil.EQUAL) || operatorValue.equals(OperatorUtil.NOT_EQUAL)) { @@ -365,7 +370,7 @@ private String getRestrictionByOperator(Filter condition, int displayType) { displayType, parameterValue ); - parameters.add(valueToFilter); + this.parameters.add(valueToFilter); } else { // Greater, Greater Equal, Less, Less Equal sqlValue = " ? "; @@ -374,7 +379,7 @@ private String getRestrictionByOperator(Filter condition, int displayType) { displayType, condition.getValue() ); - parameters.add(valueToFilter); + this.parameters.add(valueToFilter); } String rescriction = "(" + columnName + sqlOperator + sqlValue + additionalSQL.toString() + ")"; diff --git a/src/main/java/org/spin/report_engine/service/ReportBuilder.java b/src/main/java/org/spin/report_engine/service/ReportBuilder.java index bb114ba..e236519 100644 --- a/src/main/java/org/spin/report_engine/service/ReportBuilder.java +++ b/src/main/java/org/spin/report_engine/service/ReportBuilder.java @@ -177,7 +177,7 @@ private ReportInfo get(String transactionName) { MPrintFormat printFormat = new MPrintFormat(Env.getCtx(), getPrintFormatId(), null); PrintFormat format = PrintFormat.newInstance(printFormat); QueryDefinition queryDefinition = format.getQuery() - .withConditions(conditions) + .withConditions(this.conditions) .withInstanceId(getInstanceId()) .withLimit(limit, offset) .buildQuery() From 1f15768e8a4e4810d2bbd616024df23f44f53ab5 Mon Sep 17 00:00:00 2001 From: Edwin Betancourt Date: Thu, 12 Sep 2024 11:37:36 -0400 Subject: [PATCH 2/2] change with request changes. --- .../java/org/spin/report_engine/format/QueryDefinition.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/spin/report_engine/format/QueryDefinition.java b/src/main/java/org/spin/report_engine/format/QueryDefinition.java index 6885193..e9ec401 100644 --- a/src/main/java/org/spin/report_engine/format/QueryDefinition.java +++ b/src/main/java/org/spin/report_engine/format/QueryDefinition.java @@ -49,7 +49,7 @@ private QueryDefinition() { conditions = new ArrayList(); columns = new ArrayList(); queryColumns = new ArrayList(); - this.parameters = new ArrayList(); + parameters = new ArrayList(); } public static QueryDefinition newInstance() { @@ -126,7 +126,7 @@ public QueryDefinition withQueryColumns(List queryColumns) { } public List getParameters() { - return this.parameters; + return parameters; } public String getWhereClause() {