use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class DataQueryParams method setDataDimensionOptions.
/**
* Sets the given list of data dimension options. Replaces existing options
* of the given data dimension type.
*
* @param itemType the data dimension type, or all types if null.
* @param options the data dimension options.
*/
private void setDataDimensionOptions(@Nullable DataDimensionItemType itemType, List<? extends DimensionalItemObject> options) {
List<DimensionalItemObject> existing = getDimensionOptions(DATA_X_DIM_ID);
if (itemType != null) {
existing = AnalyticsUtils.getByDataDimensionItemType(itemType, existing);
}
DimensionalObject dimension = getDimension(DATA_X_DIM_ID);
if (dimension == null) {
dimension = new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, null, DISPLAY_NAME_DATA_X, options);
addDimension(dimension);
} else {
dimension.getItems().removeAll(existing);
dimension.getItems().addAll(options);
}
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class EventAnalyticsServiceMetadataTest method testGetQueryItemDimensionMetadata.
// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
@SuppressWarnings("unchecked")
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).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());
assertFalse(itemsOptionSet.isEmpty());
assertEquals(2, itemsOptionSetFilter.size());
assertTrue(itemsOptionSetFilter.containsAll(IdentifiableObjectUtils.getUids(Sets.newHashSet(opA, opB))));
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class AbstractJdbcEventAnalyticsManagerTest method verifyGetWhereClauseWithAttributeOrgUnitTypeAndCoordinatesReturnsFetchesCoordinatesFromOrgUnite.
@Test
void verifyGetWhereClauseWithAttributeOrgUnitTypeAndCoordinatesReturnsFetchesCoordinatesFromOrgUnite() {
// Given
DataElement deA = createDataElement('A', ValueType.ORGANISATION_UNIT, AggregationType.NONE);
DimensionalObject periods = new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, newArrayList(MonthlyPeriodType.getPeriodFromIsoString("201701")));
DimensionalObject orgUnits = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, "ouA", newArrayList(createOrganisationUnit('A')));
QueryItem qiA = new QueryItem(deA, null, deA.getValueType(), deA.getAggregationType(), null);
// When
EventQueryParams params = new EventQueryParams.Builder().addDimension(periods).addDimension(orgUnits).addItem(qiA).withCoordinateField(deA.getUid()).withSkipData(true).withSkipMeta(false).withStartDate(new Date()).withEndDate(new Date()).withCoordinatesOnly(true).build();
final String whereClause = this.subject.getWhereClause(params);
// Then
assertThat(whereClause, containsString("and ax.\"" + deA.getUid() + "_geom" + "\" is not null"));
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class AbstractJdbcEventAnalyticsManagerTest method testGetWhereClauseWithMultipleOrgUnitDescendantsAtSameLevel.
@Test
void testGetWhereClauseWithMultipleOrgUnitDescendantsAtSameLevel() {
// Given
final DimensionalObject periods = new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, newArrayList(MonthlyPeriodType.getPeriodFromIsoString("201801")));
final DimensionalObject multipleOrgUnitsSameLevel = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, "uidlevel1", "Level 1", newArrayList(createOrganisationUnit('A'), createOrganisationUnit('B'), createOrganisationUnit('C')));
final EventQueryParams params = new EventQueryParams.Builder().addDimension(periods).addDimension(multipleOrgUnitsSameLevel).withSkipData(true).withSkipMeta(false).withStartDate(new Date()).withEndDate(new Date()).build();
// When
final String whereClause = this.subject.getWhereClause(params);
// Then
assertThat(whereClause, containsString("and ax.\"uidlevel0\" in ('ouabcdefghA','ouabcdefghB','ouabcdefghC')"));
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class QueryValidatorTest method validateSuccessSingleProgramIndicatorFilter.
@Test
void validateSuccessSingleProgramIndicatorFilter() {
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).addFilter(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.PROGRAM_INDICATOR, getList(inA))).build();
queryValidator.validate(params);
}
Aggregations