Search in sources :

Example 41 with BaseDimensionalObject

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)));
}
Also used : BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.jupiter.api.Test)

Example 42 with BaseDimensionalObject

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()));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) Legend(org.hisp.dhis.legend.Legend) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Grid(org.hisp.dhis.common.Grid) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Option(org.hisp.dhis.option.Option) Map(java.util.Map) MetadataItem(org.hisp.dhis.common.MetadataItem) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 43 with BaseDimensionalObject

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());
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) Point(org.opengis.geometry.primitive.Point) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test)

Example 44 with BaseDimensionalObject

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() + "\""));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) DhisConvenienceTest.createOrganisationUnit(org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) QueryItem(org.hisp.dhis.common.QueryItem) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) Program(org.hisp.dhis.program.Program) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) PostgreSQLStatementBuilder(org.hisp.dhis.jdbc.statementbuilder.PostgreSQLStatementBuilder) DefaultProgramIndicatorSubqueryBuilder(org.hisp.dhis.analytics.event.data.programindicator.DefaultProgramIndicatorSubqueryBuilder) StatementBuilder(org.hisp.dhis.jdbc.StatementBuilder) Period(org.hisp.dhis.period.Period) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DhisConvenienceTest.createProgramIndicator(org.hisp.dhis.DhisConvenienceTest.createProgramIndicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.jupiter.api.Test)

Example 45 with BaseDimensionalObject

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());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) Test(org.junit.jupiter.api.Test)

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