Search in sources :

Example 81 with DimensionalItemObject

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

the class QueryPlannerTest method assertQueryMods.

private void assertQueryMods(List<DataQueryParams> group, QueryModifiers mods, DataElement... elements) {
    List<DataElement> modElements = Arrays.asList(elements);
    for (DataQueryParams params : group) {
        List<DimensionalItemObject> groupElements = params.getDataElements();
        assertNotEquals(0, groupElements.size());
        QueryModifiers groupMods = groupElements.get(0).getQueryMods();
        if (Objects.equals(mods, groupMods)) {
            assertTrue(Objects.equals(params.getStartDate(), mods == null ? null : mods.getMinDate()));
            assertTrue(Objects.equals(params.getEndDate(), mods == null ? null : mods.getMaxDate()));
            assertEquals(modElements.size(), groupElements.size());
            assertTrue(groupElements.containsAll(modElements));
            groupElements.forEach(e -> {
                assertEquals(mods, e.getQueryMods());
            });
            return;
        }
    }
    throw new RuntimeException("No group found for queryMods " + mods);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) QueryModifiers(org.hisp.dhis.common.QueryModifiers) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject)

Example 82 with DimensionalItemObject

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

the class QueryPlannerTest method samePeriodType.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private static boolean samePeriodType(List<DimensionalItemObject> isoPeriods) {
    Iterator<DimensionalItemObject> periods = new ArrayList<>(isoPeriods).iterator();
    PeriodType first = ((Period) periods.next()).getPeriodType();
    while (periods.hasNext()) {
        PeriodType next = ((Period) periods.next()).getPeriodType();
        if (!first.equals(next)) {
            return false;
        }
    }
    return true;
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Period(org.hisp.dhis.period.Period)

Example 83 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject 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 84 with DimensionalItemObject

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

the class AbstractJdbcEventAnalyticsManagerTest method verifyGetAggregateClauseWithValueFails.

@Test
void verifyGetAggregateClauseWithValueFails() {
    DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
    EventQueryParams params = new EventQueryParams.Builder(createRequestParams()).withValue(dio).withAggregationType(fromAggregationType(AggregationType.CUSTOM)).build();
    assertThrows(IllegalArgumentException.class, () -> subject.getAggregateClause(params));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject) Test(org.junit.jupiter.api.Test)

Example 85 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject 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)

Aggregations

DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)178 Test (org.junit.jupiter.api.Test)63 ArrayList (java.util.ArrayList)51 DimensionalObject (org.hisp.dhis.common.DimensionalObject)48 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)42 Period (org.hisp.dhis.period.Period)41 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)40 HashMap (java.util.HashMap)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)28 DhisSpringTest (org.hisp.dhis.DhisSpringTest)26 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)22 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)20 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)20 DataElement (org.hisp.dhis.dataelement.DataElement)20 List (java.util.List)17 Indicator (org.hisp.dhis.indicator.Indicator)17 Grid (org.hisp.dhis.common.Grid)16 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)16 ListMap (org.hisp.dhis.common.ListMap)15 QueryItem (org.hisp.dhis.common.QueryItem)15