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