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;
}
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());
}
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))));
}
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);
}
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);
}
Aggregations