Search in sources :

Example 16 with BaseDimensionalObject

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

the class DefaultDimensionService method getDimensionalObjectCopy.

@Override
public DimensionalObject getDimensionalObjectCopy(String uid, boolean filterCanRead) {
    DimensionalObject dimension = idObjectManager.get(DimensionalObject.DYNAMIC_DIMENSION_CLASSES, uid);
    BaseDimensionalObject copy = new BaseDimensionalObject();
    mergeService.merge(new MergeParams<>(dimension, copy).setMergeMode(MergeMode.MERGE));
    if (filterCanRead) {
        User user = currentUserService.getCurrentUser();
        List<DimensionalItemObject> items = getCanReadObjects(user, dimension.getItems());
        copy.setItems(items);
    }
    return copy;
}
Also used : User(org.hisp.dhis.user.User) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MergeParams(org.hisp.dhis.schema.MergeParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject)

Example 17 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 18 with BaseDimensionalObject

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

the class EventAnalyticsServiceMetadataTest method testGetQueryItemDimensionMetadata.

// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
@SuppressWarnings("unchecked")
public void testGetQueryItemDimensionMetadata() {
    DimensionalObject periods = new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA));
    DimensionalObject orgUnits = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA));
    QueryItem itemLegendSet = new QueryItem(deA, lsA, deA.getValueType(), deA.getAggregationType(), null);
    QueryItem itemLegendSetFilter = new QueryItem(deB, lsA, deB.getValueType(), deB.getAggregationType(), null);
    itemLegendSetFilter.addFilter(new QueryFilter(QueryOperator.IN, leA.getUid() + OPTION_SEP + leB.getUid() + OPTION_SEP + leC.getUid()));
    QueryItem item = new QueryItem(deC, null, deC.getValueType(), deC.getAggregationType(), null);
    QueryItem itemFilter = new QueryItem(deD, null, deD.getValueType(), deD.getAggregationType(), null);
    itemFilter.addFilter(new QueryFilter(QueryOperator.GT, "10"));
    QueryItem itemOptionSet = new QueryItem(deE, null, deE.getValueType(), deE.getAggregationType(), osA);
    QueryItem itemOptionSetFilter = new QueryItem(deF, null, deE.getValueType(), deE.getAggregationType(), osA);
    itemOptionSetFilter.addFilter(new QueryFilter(QueryOperator.IN, opA.getCode() + OPTION_SEP + opB.getCode()));
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).addDimension(periods).addDimension(orgUnits).addItem(itemLegendSet).addItem(itemLegendSetFilter).addItem(item).addItem(itemFilter).addItem(itemOptionSet).addItem(itemOptionSetFilter).withSkipData(true).withSkipMeta(false).withDisplayProperty(DisplayProperty.NAME).withApiVersion(DhisApiVersion.V26).build();
    Grid grid = eventAnalyticsService.getAggregatedEventData(params);
    Map<String, Object> metadata = grid.getMetaData();
    assertNotNull(metadata);
    Map<String, Object> dimensionItems = (Map<String, Object>) metadata.get(AnalyticsMetaDataKey.DIMENSIONS.getKey());
    assertNotNull(dimensionItems);
    List<String> itemsLegendSet = (List<String>) dimensionItems.get(itemLegendSet.getItemId());
    List<String> itemsLegendSetFilter = (List<String>) dimensionItems.get(itemLegendSetFilter.getItemId());
    List<String> items = (List<String>) dimensionItems.get(item.getItemId());
    List<String> itemsFilter = (List<String>) dimensionItems.get(itemFilter.getItemId());
    List<String> itemsOptionSet = (List<String>) dimensionItems.get(itemOptionSet.getItemId());
    List<String> itemsOptionSetFilter = (List<String>) dimensionItems.get(itemOptionSetFilter.getItemId());
    assertNotNull(itemsLegendSet);
    assertNotNull(itemsLegendSetFilter);
    assertNotNull(items);
    assertNotNull(itemsFilter);
    assertNotNull(itemsOptionSet);
    assertNotNull(itemsOptionSetFilter);
    assertEquals(4, itemsLegendSet.size());
    assertEquals(itemsLegendSet, Lists.newArrayList(leA.getUid(), leB.getUid(), leC.getUid(), leD.getUid()));
    assertEquals(3, itemsLegendSetFilter.size());
    assertTrue(itemsLegendSetFilter.containsAll(IdentifiableObjectUtils.getUids(Sets.newHashSet(leA, leB, leC))));
    assertTrue(items.isEmpty());
    assertTrue(itemsFilter.isEmpty());
    assertTrue(itemsOptionSet.isEmpty());
    assertEquals(2, itemsOptionSetFilter.size());
    assertTrue(itemsOptionSetFilter.containsAll(IdentifiableObjectUtils.getCodes(Sets.newHashSet(opA, opB))));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Grid(org.hisp.dhis.common.Grid) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) QueryFilter(org.hisp.dhis.common.QueryFilter) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) List(java.util.List) Map(java.util.Map) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 19 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 20 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)

Aggregations

BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)21 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)16 Test (org.junit.Test)13 DhisSpringTest (org.hisp.dhis.DhisSpringTest)11 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)8 DimensionalObject (org.hisp.dhis.common.DimensionalObject)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)2 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)2 Grid (org.hisp.dhis.common.Grid)2 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)2 ListMap (org.hisp.dhis.common.ListMap)2 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)1 AnalyticalObject (org.hisp.dhis.common.AnalyticalObject)1 QueryFilter (org.hisp.dhis.common.QueryFilter)1 QueryItem (org.hisp.dhis.common.QueryItem)1