use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class SimpleDimensionHandlerTest method testAssociateDimensions.
@Test
void testAssociateDimensions() {
// Given
final String eventDateDimension = EVENT_DATE.getDimension();
final EventVisualization aEventVisualization = stubEventVisualization();
aEventVisualization.getSimpleDimensions().clear();
aEventVisualization.getColumns().addAll(of(new BaseDimensionalObject(eventDateDimension)));
final SimpleDimensionHandler handler = new SimpleDimensionHandler(aEventVisualization);
// When
handler.associateDimensions();
// Then
assertThat(aEventVisualization.getSimpleDimensions(), hasSize(1));
assertThat(aEventVisualization.getSimpleDimensions().get(0).getParent(), is(equalTo(COLUMN)));
assertThat(aEventVisualization.getSimpleDimensions().get(0).getDimension(), is(equalTo(eventDateDimension)));
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class EventAnalyticsServiceMetadataTest method testGetQueryItemMetadata.
@Test
@SuppressWarnings("unchecked")
void testGetQueryItemMetadata() {
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 qiA = new QueryItem(deA, deA.getLegendSet(), deA.getValueType(), deA.getAggregationType(), null);
QueryItem qiB = new QueryItem(deE, null, deE.getValueType(), deE.getAggregationType(), deE.getOptionSet());
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).addDimension(periods).addDimension(orgUnits).addItem(qiA).addItemFilter(qiB).withSkipData(true).withSkipMeta(false).withApiVersion(DhisApiVersion.V29).build();
Grid grid = eventAnalyticsService.getAggregatedEventData(params);
Map<String, Object> metadata = grid.getMetaData();
Map<String, MetadataItem> itemMap = (Map<String, MetadataItem>) metadata.get(AnalyticsMetaDataKey.ITEMS.getKey());
assertNotNull(itemMap.get(DimensionalObject.PERIOD_DIM_ID));
assertNotNull(itemMap.get(DimensionalObject.ORGUNIT_DIM_ID));
for (Legend legend : deA.getLegendSet().getLegends()) {
assertNotNull(itemMap.get(legend.getUid()));
}
for (Option option : deE.getOptionSet().getOptions()) {
assertNotNull(itemMap.get(option.getUid()));
}
assertNotNull(itemMap.get(deA.getUid()));
assertNotNull(itemMap.get(deE.getUid()));
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class DummyAnalyticsService method verifyHeaderCreationBasedOnQueryItemsAndDimensions.
@Test
void verifyHeaderCreationBasedOnQueryItemsAndDimensions() {
// Given
DimensionalObject periods = new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA));
DimensionalObject orgUnits = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, "ouA", Lists.newArrayList(ouA));
QueryItem qiA = new QueryItem(deA, null, deA.getValueType(), deA.getAggregationType(), null);
QueryItem qiB = new QueryItem(deB, null, deB.getValueType(), deB.getAggregationType(), null);
QueryItem qiC = new QueryItem(deC, null, deC.getValueType(), deC.getAggregationType(), null);
EventQueryParams params = new EventQueryParams.Builder().addDimension(periods).addDimension(orgUnits).addItem(qiA).addItem(qiB).addItem(qiC).withCoordinateField(deB.getUid()).withSkipData(true).withSkipMeta(false).withApiVersion(DhisApiVersion.V33).build();
when(securityManager.withUserConstraints(any(EventQueryParams.class))).thenReturn(params);
// When
Grid grid = dummyAnalyticsService.getGrid(params);
// Then
final List<GridHeader> headers = grid.getHeaders();
assertThat(headers, is(notNullValue()));
assertThat(headers, hasSize(4));
assertHeader(headers.get(0), "ou", "ouA", ValueType.TEXT, String.class.getName());
assertHeader(headers.get(1), deA.getUid(), deA.getName(), ValueType.TEXT, String.class.getName());
assertHeader(headers.get(2), deB.getUid(), deB.getName(), ValueType.COORDINATE, Point.class.getName());
assertHeader(headers.get(3), deC.getUid(), deC.getName(), ValueType.NUMBER, Double.class.getName());
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class EventsAnalyticsManagerTest method verifySortClauseHandlesProgramIndicators.
@Test
void verifySortClauseHandlesProgramIndicators() {
Program program = createProgram('P');
ProgramIndicator piA = createProgramIndicator('A', program, ".", ".");
piA.setUid("TLKx7vllb1I");
ProgramIndicator piB = createProgramIndicator('B', program, ".", ".");
piA.setUid("CCKx3gllb2P");
OrganisationUnit ouA = createOrganisationUnit('A');
Period peA = PeriodType.getPeriodFromIsoString("201501");
DataElement deA = createDataElement('A');
deA.setUid("ZE4cgllb2P");
DataQueryParams params = DataQueryParams.newBuilder().withDataType(DataType.NUMERIC).withTableName("analytics").withPeriodType(QuarterlyPeriodType.NAME).withAggregationType(AnalyticsAggregationType.fromAggregationType(AggregationType.DEFAULT)).addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.PROGRAM_INDICATOR, getList(piA, piB))).addFilter(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.DATA_X, getList(peA))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA))).build();
final EventQueryParams.Builder eventQueryParamsBuilder = new EventQueryParams.Builder(params).withProgram(program).addAscSortItem(new QueryItem(piA)).addDescSortItem(new QueryItem(piB)).addAscSortItem(new QueryItem(deA));
final String sql = subject.getEventsOrEnrollmentsSql(eventQueryParamsBuilder.build(), 100);
assertThat(sql, containsString("order by \"" + piA.getUid() + "\" asc,\"" + deA.getUid() + "\" asc,\"" + piB.getUid() + "\""));
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class QueryValidatorTest method validateErrorReportingRatesAndDataElementGroupSetAsDimensions.
@Test
void validateErrorReportingRatesAndDataElementGroupSetAsDimensions() {
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(rrA, inA))).addDimension(new BaseDimensionalObject(dgsA.getDimension(), DimensionType.DATA_ELEMENT_GROUP_SET, getList(deA))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).build();
ErrorMessage error = queryValidator.validateForErrorMessage(params);
assertEquals(ErrorCode.E7112, error.getErrorCode());
}
Aggregations