diff --git a/src/main/java/com/ibm/openpages/support/util/query/Operation.java b/src/main/java/com/ibm/openpages/support/util/query/Operation.java index ca11873..7bff96e 100644 --- a/src/main/java/com/ibm/openpages/support/util/query/Operation.java +++ b/src/main/java/com/ibm/openpages/support/util/query/Operation.java @@ -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 valueFormatter; Operation(String value) { + this(value, in -> in); + } + + Operation(String value, Function 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; + } } diff --git a/src/main/java/com/ibm/openpages/support/util/query/SimpleQueryClause.java b/src/main/java/com/ibm/openpages/support/util/query/SimpleQueryClause.java index fa41c74..6214228 100644 --- a/src/main/java/com/ibm/openpages/support/util/query/SimpleQueryClause.java +++ b/src/main/java/com/ibm/openpages/support/util/query/SimpleQueryClause.java @@ -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); } }