Search in sources :

Example 61 with BaseDimensionalObject

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

the class EventQueryParamsTest method testReplacePeriodsWithStartEndDates.

@Test
public void testReplacePeriodsWithStartEndDates() {
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 5, 1, 0, 0).toDate()));
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 6, 1, 0, 0).toDate()));
    EventQueryParams params = new EventQueryParams.Builder().addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, periods)).build();
    assertNull(params.getStartDate());
    assertNull(params.getEndDate());
    params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();
    assertEquals(new DateTime(2014, 4, 1, 0, 0).toDate(), params.getStartDate());
    assertEquals(new DateTime(2014, 6, 30, 0, 0).toDate(), params.getEndDate());
}
Also used : DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 62 with BaseDimensionalObject

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

the class QueryPlannerTest method validateFailureOptionCombosWithIndicators.

@Test(expected = IllegalQueryException.class)
public void validateFailureOptionCombosWithIndicators() {
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, inA))).addDimension(new BaseDimensionalObject(CATEGORYOPTIONCOMBO_DIM_ID, DimensionType.DATA_X, getList())).addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).build();
    queryPlanner.validate(params);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 63 with BaseDimensionalObject

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

the class QueryPlannerTest method validateSuccesB.

@Test
public void validateSuccesB() {
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, deB, pdeA, pdeB))).addFilter(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).build();
    queryPlanner.validate(params);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 64 with BaseDimensionalObject

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

the class QueryPlannerTest method validateFailureValueType.

@Test(expected = IllegalQueryException.class)
public void validateFailureValueType() {
    deB.setValueType(ValueType.FILE_RESOURCE);
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, deB))).addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).build();
    queryPlanner.validate(params);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 65 with BaseDimensionalObject

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

the class DefaultAnalyticsService method getOrgUnitTargetMap.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
     * Generates a mapping of permutations keys (organisation unit id or null)
     * and mappings of organisation unit group and counts.
     *
     * @param params the {@link DataQueryParams}.
     * @param indicators the indicators for which formulas to scan for organisation
     *        unit groups.
     * @return a map of maps.
     */
private Map<String, Map<String, Integer>> getOrgUnitTargetMap(DataQueryParams params, Collection<Indicator> indicators) {
    Set<OrganisationUnitGroup> orgUnitGroups = expressionService.getOrganisationUnitGroupsInIndicators(indicators);
    if (orgUnitGroups.isEmpty()) {
        return null;
    }
    DataQueryParams orgUnitTargetParams = DataQueryParams.newBuilder(params).pruneToDimensionType(DimensionType.ORGANISATION_UNIT).addDimension(new BaseDimensionalObject(DimensionalObject.ORGUNIT_GROUP_DIM_ID, null, new ArrayList<DimensionalItemObject>(orgUnitGroups))).withSkipPartitioning(true).build();
    Map<String, Double> orgUnitCountMap = getAggregatedOrganisationUnitTargetMap(orgUnitTargetParams);
    return DataQueryParams.getPermutationOrgUnitGroupCountMap(orgUnitCountMap);
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) PeriodType.getPeriodTypeFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)

Aggregations

BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)108 Test (org.junit.jupiter.api.Test)77 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)69 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)31 DhisSpringTest (org.hisp.dhis.DhisSpringTest)26 DimensionalObject (org.hisp.dhis.common.DimensionalObject)22 ArrayList (java.util.ArrayList)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)18 Grid (org.hisp.dhis.common.Grid)17 HashMap (java.util.HashMap)14 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)14 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)13 CategoryCombo (org.hisp.dhis.category.CategoryCombo)11 DataElement (org.hisp.dhis.dataelement.DataElement)11 Test (org.junit.Test)11 Map (java.util.Map)9 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)9 Period (org.hisp.dhis.period.Period)9 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)8 QueryItem (org.hisp.dhis.common.QueryItem)8