Search in sources :

Example 1 with Comparison

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();
}
Also used : Comparison(org.hisp.dhis.gist.GistQuery.Comparison)

Example 2 with Comparison

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++;
    }
}
Also used : Owner(org.hisp.dhis.gist.GistQuery.Owner) GistLogic.isCollectionSizeFilter(org.hisp.dhis.gist.GistLogic.isCollectionSizeFilter) Filter(org.hisp.dhis.gist.GistQuery.Filter) GistLogic.isStringLengthFilter(org.hisp.dhis.gist.GistLogic.isStringLengthFilter) Comparison(org.hisp.dhis.gist.GistQuery.Comparison) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 3 with Comparison

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;
}
Also used : Comparison(org.hisp.dhis.gist.GistQuery.Comparison)

Aggregations

Comparison (org.hisp.dhis.gist.GistQuery.Comparison)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 GistLogic.isCollectionSizeFilter (org.hisp.dhis.gist.GistLogic.isCollectionSizeFilter)1 GistLogic.isStringLengthFilter (org.hisp.dhis.gist.GistLogic.isStringLengthFilter)1 Filter (org.hisp.dhis.gist.GistQuery.Filter)1 Owner (org.hisp.dhis.gist.GistQuery.Owner)1