Skip to content

Commit

Permalink
Merge pull request #7 from EdwinBetanc0urt/bugfix/condition-to-column
Browse files Browse the repository at this point in the history
fix: Condition with `_To` column.
  • Loading branch information
yamelsenih authored Sep 12, 2024
2 parents e7640de + 1f15768 commit f71af1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
29 changes: 17 additions & 12 deletions src/main/java/org/spin/report_engine/format/QueryDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,15 @@ public QueryDefinition buildQuery() {
.filter(condition -> !Util.isEmpty(condition.getColumnName(), true))
.forEach(condition -> {
Optional<PrintFormatColumn> 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 ");
Expand Down Expand Up @@ -286,7 +291,7 @@ private String getRestrictionByOperator(Filter condition, int displayType) {
displayType,
currentValue
);
parameters.add(valueToFilter);
this.parameters.add(valueToFilter);
});
}

Expand All @@ -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 + ")";
Expand All @@ -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)) {
Expand Down Expand Up @@ -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 = " ? ";
Expand All @@ -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() + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f71af1d

Please sign in to comment.