Search in sources :

Example 41 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class EnrollmentAnalyticsManagerTest method verifyWithProgramStageAndNumericDataElementAndFilter2.

@Test
void verifyWithProgramStageAndNumericDataElementAndFilter2() {
    EventQueryParams params = createRequestParamsWithFilter(programStage, ValueType.NUMBER);
    subject.getEnrollments(params, new ListGrid(), 10000);
    verify(jdbcTemplate).queryForRowSet(sql.capture());
    String subSelect = "(select \"fWIAEtYVEGk\" from analytics_event_" + programA.getUid() + " where analytics_event_" + programA.getUid() + ".pi = ax.pi and \"fWIAEtYVEGk\" is not null and ps = '" + programStage.getUid() + "' order by executiondate desc limit 1 )";
    String expected = "ax.\"monthly\",ax.\"ou\"," + "coalesce(" + subSelect + ", null) as fWIAEtYVEGk" + "  from " + getTable(programA.getUid()) + " as ax where ax.\"monthly\" in ('2000Q1') and (uidlevel1 = 'ouabcdefghA' ) " + "and ps = '" + programStage.getUid() + "' and " + subSelect + " > '10' limit 10001";
    assertSql(sql.getValue(), expected);
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ListGrid(org.hisp.dhis.system.grid.ListGrid) Test(org.junit.jupiter.api.Test)

Example 42 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class AnalyticsCacheTest method returnSameObjectAfterModifyCachedObject.

@Test
void returnSameObjectAfterModifyCachedObject() {
    // arrange
    final AnalyticsCacheSettings settings = new AnalyticsCacheSettings(systemSettingManager);
    final CacheBuilder<Grid> cacheBuilder = new SimpleCacheBuilder<>();
    cacheBuilder.expireAfterWrite(1L, TimeUnit.MINUTES);
    final Cache<Grid> cache = new LocalCache<>(cacheBuilder);
    Mockito.<Cache<Grid>>when(cacheProvider.createAnalyticsResponseCache(any(Duration.class))).thenReturn(cache);
    final AnalyticsCache analyticsCache = new AnalyticsCache(cacheProvider, settings);
    final Grid grid = new ListGrid();
    grid.addHeader(new GridHeader("Header1")).addHeader(new GridHeader("Header2")).addRow().addValue("Value11").addValue("Value12").addRow().addValue("Value21").addValue("Value22");
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(Lists.newArrayList(new DataElement("dataElementA"), new DataElement("dataElementB"))).build();
    // act, assert
    analyticsCache.put(params.getKey(), grid, 60);
    Optional<Grid> optCachedGrid = analyticsCache.get(params.getKey());
    assertTrue(optCachedGrid.isPresent());
    assertEquals(2, optCachedGrid.get().getHeaderWidth());
    assertEquals(2, optCachedGrid.get().getRows().size());
    // when the cachedGrid is not the clone of grid, next actions will
    // modify it
    grid.addHeader(new GridHeader("Header3")).addRow().addValue("31").addValue("32");
    optCachedGrid = analyticsCache.get(params.getKey());
    assertTrue(optCachedGrid.isPresent());
    assertEquals(2, optCachedGrid.get().getHeaderWidth());
    assertEquals(2, optCachedGrid.get().getRows().size());
}
Also used : LocalCache(org.hisp.dhis.cache.LocalCache) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) SimpleCacheBuilder(org.hisp.dhis.cache.SimpleCacheBuilder) Duration(java.time.Duration) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) Test(org.junit.jupiter.api.Test)

Example 43 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class EnrollmentAnalyticsManagerTest method verifyWithLastUpdatedTimeField.

@Test
void verifyWithLastUpdatedTimeField() {
    EventQueryParams params = new EventQueryParams.Builder(createRequestParams()).withStartDate(getDate(2017, 1, 1)).withEndDate(getDate(2017, 12, 31)).withTimeField(TimeField.LAST_UPDATED.name()).build();
    subject.getEnrollments(params, new ListGrid(), 10000);
    verify(jdbcTemplate).queryForRowSet(sql.capture());
    String expected = "ax.\"monthly\",ax.\"ou\"  from " + getTable(programA.getUid()) + " as ax where lastupdated >= '2017-01-01' and lastupdated < '2018-01-01' and (uidlevel1 = 'ouabcdefghA' ) limit 10001";
    assertSql(sql.getValue(), expected);
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) PostgreSQLStatementBuilder(org.hisp.dhis.jdbc.statementbuilder.PostgreSQLStatementBuilder) DefaultProgramIndicatorSubqueryBuilder(org.hisp.dhis.analytics.event.data.programindicator.DefaultProgramIndicatorSubqueryBuilder) StatementBuilder(org.hisp.dhis.jdbc.StatementBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ListGrid(org.hisp.dhis.system.grid.ListGrid) Test(org.junit.jupiter.api.Test)

Example 44 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class EnrollmentAnalyticsManagerTest method verifyWithProgramAndStartEndDate.

@Test
void verifyWithProgramAndStartEndDate() {
    EventQueryParams params = new EventQueryParams.Builder(createRequestParams()).withStartDate(getDate(2017, 1, 1)).withEndDate(getDate(2017, 12, 31)).build();
    subject.getEnrollments(params, new ListGrid(), 10000);
    verify(jdbcTemplate).queryForRowSet(sql.capture());
    String expected = "ax.\"monthly\",ax.\"ou\"  from " + getTable(programA.getUid()) + " as ax where enrollmentdate >= '2017-01-01' and enrollmentdate < '2018-01-01' and (uidlevel1 = 'ouabcdefghA' ) limit 10001";
    assertSql(sql.getValue(), expected);
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ListGrid(org.hisp.dhis.system.grid.ListGrid) Test(org.junit.jupiter.api.Test)

Example 45 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testHandleGridForDataValueSetEmpty.

@Test
void testHandleGridForDataValueSetEmpty() {
    Grid grid = new ListGrid();
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList())).build();
    grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
    grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, false, false));
    assertEquals(4, grid.getHeaders().size());
    assertEquals(0, grid.getWidth());
    assertEquals(0, grid.getHeight());
    AnalyticsUtils.handleGridForDataValueSet(params, grid);
    assertEquals(6, grid.getHeaders().size());
    assertEquals(0, grid.getWidth());
    assertEquals(0, grid.getHeight());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

ListGrid (org.hisp.dhis.system.grid.ListGrid)58 Grid (org.hisp.dhis.common.Grid)41 GridHeader (org.hisp.dhis.common.GridHeader)28 Test (org.junit.jupiter.api.Test)21 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)14 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)11 ArrayList (java.util.ArrayList)10 DimensionalObject (org.hisp.dhis.common.DimensionalObject)10 HashMap (java.util.HashMap)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 DataElement (org.hisp.dhis.dataelement.DataElement)8 List (java.util.List)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 Test (org.junit.Test)7 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)6 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)5 DataValueSet (org.hisp.dhis.dxf2.datavalueset.DataValueSet)5 I18nFormat (org.hisp.dhis.i18n.I18nFormat)5