Search in sources :

Example 26 with QueryFilter

use of org.hisp.dhis.common.QueryFilter in project dhis2-core by dhis2.

the class TrackedEntityCriteriaMapper method getQueryItem.

/**
 * Creates a QueryItem from the given item string. Item is on format
 * {attribute-id}:{operator}:{filter-value}[:{operator}:{filter-value}].
 * Only the attribute-id is mandatory.
 */
private QueryItem getQueryItem(String item, Map<String, TrackedEntityAttribute> attributes) {
    String[] split = item.split(DimensionalObject.DIMENSION_NAME_SEP);
    if (split.length % 2 != 1) {
        throw new IllegalQueryException("Query item or filter is invalid: " + item);
    }
    QueryItem queryItem = getItem(split[0], attributes);
    if (// Filters specified
    split.length > 1) {
        for (int i = 1; i < split.length; i += 2) {
            QueryOperator operator = QueryOperator.fromString(split[i]);
            queryItem.getFilters().add(new QueryFilter(operator, split[i + 1]));
        }
    }
    return queryItem;
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) QueryFilter(org.hisp.dhis.common.QueryFilter) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) QueryOperator(org.hisp.dhis.common.QueryOperator)

Example 27 with QueryFilter

use of org.hisp.dhis.common.QueryFilter in project dhis2-core by dhis2.

the class TrackedEntityCriteriaMapper method getQueryFilter.

/**
 * Creates a QueryFilter from the given query string. Query is on format
 * {operator}:{filter-value}. Only the filter-value is mandatory. The EQ
 * QueryOperator is used as operator if not specified.
 */
private QueryFilter getQueryFilter(String query) {
    if (query == null || query.isEmpty()) {
        return null;
    }
    if (!query.contains(DimensionalObject.DIMENSION_NAME_SEP)) {
        return new QueryFilter(QueryOperator.EQ, query);
    } else {
        String[] split = query.split(DimensionalObject.DIMENSION_NAME_SEP);
        if (split.length != 2) {
            throw new IllegalQueryException("Query has invalid format: " + query);
        }
        QueryOperator op = QueryOperator.fromString(split[0]);
        return new QueryFilter(op, split[1]);
    }
}
Also used : QueryFilter(org.hisp.dhis.common.QueryFilter) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) QueryOperator(org.hisp.dhis.common.QueryOperator)

Aggregations

QueryFilter (org.hisp.dhis.common.QueryFilter)27 QueryItem (org.hisp.dhis.common.QueryItem)25 QueryOperator (org.hisp.dhis.common.QueryOperator)9 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)8 SqlHelper (org.hisp.dhis.commons.util.SqlHelper)6 Test (org.junit.jupiter.api.Test)6 TextUtils.getQuotedCommaDelimitedString (org.hisp.dhis.commons.util.TextUtils.getQuotedCommaDelimitedString)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)5 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)4 DimensionalObject (org.hisp.dhis.common.DimensionalObject)4 DateUtils.getMediumDateString (org.hisp.dhis.util.DateUtils.getMediumDateString)4 HashSet (java.util.HashSet)3 List (java.util.List)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)3 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)3 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3 Date (java.util.Date)2 Map (java.util.Map)2