use of org.hisp.dhis.gist.GistQuery.Comparison in project dhis2-core by dhis2.
the class GistBuilder method createFilterHQL.
private String createFilterHQL(int index, Filter filter, String field) {
Comparison operator = filter.getOperator();
if (operator.isAccessCompare()) {
return createAccessFilterHQL(index, filter, field);
}
StringBuilder str = new StringBuilder();
String fieldTemplate = "%s";
if (filter.isAttribute()) {
fieldTemplate = "jsonb_extract_path_text(%s, '" + filter.getPropertyPath() + "', 'value')";
} else if (isStringLengthFilter(filter, context.resolveMandatory(filter.getPropertyPath()))) {
fieldTemplate = "length(%s)";
} else if (isCollectionSizeFilter(filter, context.resolveMandatory(filter.getPropertyPath()))) {
fieldTemplate = "size(%s)";
} else if (operator.isCaseInsensitive()) {
fieldTemplate = "lower(%s)";
}
str.append(String.format(fieldTemplate, field));
str.append(" ").append(createOperatorLeftSideHQL(operator));
if (!operator.isUnary()) {
str.append(" :f_" + index).append(createOperatorRightSideHQL(operator));
}
return str.toString();
}
use of org.hisp.dhis.gist.GistQuery.Comparison in project dhis2-core by dhis2.
the class GistBuilder method addCountParameters.
public void addCountParameters(BiConsumer<String, Object> dest, BiFunction<String, Class<?>, Object> argumentParser) {
Owner owner = query.getOwner();
if (owner != null) {
dest.accept("OwnerId", owner.getId());
}
int i = 0;
for (Filter filter : query.getFilters()) {
Comparison operator = filter.getOperator();
if (!operator.isUnary() && !operator.isAccessCompare()) {
Object value = filter.isAttribute() ? filter.getValue()[0] : getParameterValue(context.resolveMandatory(filter.getPropertyPath()), filter, argumentParser);
dest.accept("f_" + i, operator.isStringCompare() ? completeLikeExpression(operator, stringParameterValue(operator, value)) : value);
}
i++;
}
}
use of org.hisp.dhis.gist.GistQuery.Comparison in project dhis2-core by dhis2.
the class GistPlanner method isAccessFilterWithoutUserID.
private static boolean isAccessFilterWithoutUserID(Filter f) {
Comparison op = f.getOperator();
if (!op.isAccessCompare()) {
return false;
}
String[] args = f.getValue();
return op == Comparison.CAN_ACCESS && args.length <= 1 || op != Comparison.CAN_ACCESS && args.length == 0;
}
Aggregations