Skip to content

Commit

Permalink
Updates to generated query
Browse files Browse the repository at this point in the history
- Include field group in custom field references
- Change "in" comparison to use parenthesis instead of square brackets
- Removes parenthesis around AND and OR clauses for presedence for now

Signed-off-by: Sean Sundberg <[email protected]>
  • Loading branch information
seansund committed Jun 6, 2024
1 parent 80a0643 commit c763a11
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/ibm/openpages/support/models/BaseField.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ibm.openpages.support.util.FieldType;

public abstract class BaseField<T> implements FieldMetadata, ResultLabel {
final protected FieldGroup fieldGroup;
final protected String originalValue;
final protected String value;
final protected String label;
Expand All @@ -13,6 +14,7 @@ protected BaseField(FieldGroup fieldGroup, String value, FieldType<?> fieldType)
}

protected BaseField(FieldGroup fieldGroup, String value, String label, FieldType<?> fieldType) {
this.fieldGroup = fieldGroup;
this.originalValue = value;
this.value = fieldGroup != null ? fieldGroup.fieldName(value) : value;
this.label = label;
Expand Down Expand Up @@ -74,6 +76,11 @@ public String value() {
return value;
}

@Override
public String normalizedValue() {
return fieldGroup.isSystemFieldGroup() ? originalValue : value;
}

@Override
public String label() {
return label;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/ibm/openpages/support/models/EnumValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public String value() {
return value;
}

@Override
public String normalizedValue() {
return value;
}

public IEnumGroup enumGroup() {
return enumGroup;
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/ibm/openpages/support/models/FieldGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@
public class FieldGroup {
private final List<? super BaseField<?>> fields;
private final String value;
private final boolean systemFieldGroup;

public FieldGroup(final String value) {
this(value, false);
}
public FieldGroup(final String value, final boolean systemFields) {
this.value = value;
this.systemFieldGroup = systemFields;

fields = new ArrayList<>();
}

public boolean isSystemFieldGroup() {
return systemFieldGroup;
}

public List<? super BaseField<?>> fields() {
return Collections.unmodifiableList(fields);
}
Expand Down Expand Up @@ -56,6 +66,10 @@ public String fieldName(String name) {
return value + ":" + name;
}

public String value() {
return value;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public interface ResultValue {
String baseValue();
String value();
String normalizedValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.ibm.openpages.support.util.FieldType;

public interface SystemFields {
FieldGroup fg_SystemFields = new FieldGroup("System Fields");
FieldGroup fg_SystemFields = new FieldGroup("System Fields", true);

Field Name = fg_SystemFields.addField("Name", FieldType.String);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public void add(QueryClause clause) {
public String toClause() {
final String delimiter = and ? " AND " : " OR ";

return "(" + clauses.stream().map(QueryClause::toClause).collect(Collectors.joining(delimiter)) + ")";
return clauses.stream().map(QueryClause::toClause).collect(Collectors.joining(delimiter));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public static String formatListValue(Object inValue) {
final String valueList = value
.stream()
.map(QueryValueFormatters::formatSimpleValue)
.collect(Collectors.joining(","));
.collect(Collectors.joining(", "));

return "[" + valueList + "]";
return "(" + valueList + ")";
}

public static String formatSimpleValue(Object current) {
Expand Down

0 comments on commit c763a11

Please sign in to comment.