Skip to content

Commit

Permalink
Update logic to build query clause (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Sundberg <[email protected]>
  • Loading branch information
seansund authored Jun 3, 2024
1 parent f3dca70 commit 2289af2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
package com.ibm.openpages.support.util.query;

import com.ibm.openpages.support.models.IObjectType;
import com.ibm.openpages.support.models.ResultValue;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;

public enum Operation {
EQUAL("=");
EQUALS("="),
IN("IN", inValue -> (inValue instanceof List<?>) ? inValue : Collections.singletonList(inValue));

private final String value;
private final Function<Object, Object> valueFormatter;

Operation(String value) {
this(value, in -> in);
}

Operation(String value, Function<Object, Object> valueFormatter) {
this.value = value;
this.valueFormatter = valueFormatter;
}

public String value() {
return value;
}

public String toClause(IObjectType type, ResultValue field, Object inValue) {
final Object value = valueFormatter.apply(inValue);

return "[" + type.name() + "].[" + field.baseValue() + "] " + this.value() + " " + value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ protected SimpleQueryClause(IObjectType type, ResultValue field, Operation opera

@Override
public String toClause() {
return "[" + type.name() + "].[" + field.baseValue() + "] " + operation.value() + " " + value;
return operation.toClause(type, field, value);
}
}

0 comments on commit 2289af2

Please sign in to comment.