Search in sources :

Example 11 with QueryFilter

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

the class EventAnalyticsTest method createRequestParamsWithFilter.

protected EventQueryParams createRequestParamsWithFilter(ProgramStage withProgramStage, ValueType withQueryItemValueType, QueryOperator withOperator, String withQueryFilter) {
    EventQueryParams.Builder params = new EventQueryParams.Builder(createRequestParams(withProgramStage, withQueryItemValueType));
    QueryItem queryItem = params.build().getItems().get(0);
    queryItem.addFilter(new QueryFilter(withOperator, withQueryFilter));
    return params.build();
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) QueryFilter(org.hisp.dhis.common.QueryFilter)

Example 12 with QueryFilter

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

the class AbstractJdbcEventAnalyticsManagerTest method verifyGetSelectSqlWithNonTextDataElement.

@Test
void verifyGetSelectSqlWithNonTextDataElement() {
    DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
    QueryItem item = new QueryItem(dio);
    item.setValueType(ValueType.NUMBER);
    String column = subject.getSelectSql(new QueryFilter(), item, from, to);
    assertThat(column, is("ax.\"" + dataElementA.getUid() + "\""));
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) QueryFilter(org.hisp.dhis.common.QueryFilter) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) Test(org.junit.jupiter.api.Test)

Example 13 with QueryFilter

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

the class AbstractJdbcEventAnalyticsManagerTest method verifyGetSelectSqlWithTextDataElement.

@Test
void verifyGetSelectSqlWithTextDataElement() {
    DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
    QueryItem item = new QueryItem(dio);
    item.setValueType(ValueType.TEXT);
    QueryFilter queryFilter = new QueryFilter(QueryOperator.EQ, "EQ");
    String column = subject.getSelectSql(queryFilter, item, from, to);
    assertThat(column, is("ax.\"" + dataElementA.getUid() + "\""));
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) QueryFilter(org.hisp.dhis.common.QueryFilter) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) Test(org.junit.jupiter.api.Test)

Example 14 with QueryFilter

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

the class RequestToSearchParamsMapper method getQueryItem.

private QueryItem getQueryItem(String item) {
    String[] split = item.split(DimensionalObject.DIMENSION_NAME_SEP);
    if (split == null || split.length % 2 != 1) {
        throw new IllegalQueryException("Query item or filter is invalid: " + item);
    }
    QueryItem queryItem = getItem(split[0]);
    if (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 15 with QueryFilter

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

the class AbstractEventService method getQueryItem.

private QueryItem getQueryItem(String item) {
    String[] split = item.split(DimensionalObject.DIMENSION_NAME_SEP);
    if (split == null || split.length % 2 != 1) {
        throw new IllegalQueryException("Query item or filter is invalid: " + item);
    }
    QueryItem queryItem = getItem(split[0]);
    if (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)

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