use of org.hisp.dhis.analytics.AnalyticsTableUpdateParams in project dhis2-core by dhis2.
the class JdbcAnalyticsTableManagerTest method testGetLatestAnalyticsTableNoFullTableUpdate.
@Test
void testGetLatestAnalyticsTableNoFullTableUpdate() {
Date lastLatestPartitionUpdate = new DateTime(2019, 3, 1, 9, 0).toDate();
Date startTime = new DateTime(2019, 3, 1, 10, 0).toDate();
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime(startTime).withLatestPartition().build();
when(systemSettingManager.getDateSetting(SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE)).thenReturn(null);
when(systemSettingManager.getDateSetting(SettingKey.LAST_SUCCESSFUL_LATEST_ANALYTICS_PARTITION_UPDATE)).thenReturn(lastLatestPartitionUpdate);
assertThrows(IllegalArgumentException.class, () -> subject.getAnalyticsTables(params));
}
use of org.hisp.dhis.analytics.AnalyticsTableUpdateParams in project dhis2-core by dhis2.
the class AnalyticsTableJob method execute.
@Override
public void execute(JobConfiguration jobConfiguration, JobProgress progress) {
AnalyticsJobParameters parameters = (AnalyticsJobParameters) jobConfiguration.getJobParameters();
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withLastYears(parameters.getLastYears()).withSkipResourceTables(parameters.isSkipResourceTables()).withSkipTableTypes(parameters.getSkipTableTypes()).withSkipPrograms(parameters.getSkipPrograms()).withJobId(jobConfiguration).withStartTime(new Date()).build();
analyticsTableGenerator.generateTables(params, progress);
}
use of org.hisp.dhis.analytics.AnalyticsTableUpdateParams in project dhis2-core by dhis2.
the class ContinuousAnalyticsTableJob method execute.
@Override
public void execute(JobConfiguration jobConfiguration, JobProgress progress) {
ContinuousAnalyticsJobParameters parameters = (ContinuousAnalyticsJobParameters) jobConfiguration.getJobParameters();
Integer fullUpdateHourOfDay = ObjectUtils.firstNonNull(parameters.getFullUpdateHourOfDay(), DEFAULT_HOUR_OF_DAY);
Date now = new Date();
Date defaultNextFullUpdate = DateUtils.getNextDate(fullUpdateHourOfDay, now);
Date nextFullUpdate = systemSettingManager.getSystemSetting(SettingKey.NEXT_ANALYTICS_TABLE_UPDATE, defaultNextFullUpdate);
log.info("Starting continuous analytics table update, current time: '{}', default next full update: '{}', next full update: '{}'", getLongDateString(now), getLongDateString(defaultNextFullUpdate), getLongDateString(nextFullUpdate));
Preconditions.checkNotNull(nextFullUpdate);
if (now.after(nextFullUpdate)) {
log.info("Performing full analytics table update");
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withLastYears(parameters.getLastYears()).withSkipResourceTables(false).withSkipTableTypes(parameters.getSkipTableTypes()).withJobId(jobConfiguration).withStartTime(now).build();
try {
analyticsTableGenerator.generateTables(params, progress);
} finally {
Date nextUpdate = DateUtils.getNextDate(fullUpdateHourOfDay, now);
systemSettingManager.saveSystemSetting(SettingKey.NEXT_ANALYTICS_TABLE_UPDATE, nextUpdate);
log.info("Next full analytics table update: '{}'", getLongDateString(nextUpdate));
}
} else {
log.info("Performing latest analytics table partition update");
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withLatestPartition().withSkipResourceTables(true).withSkipTableTypes(parameters.getSkipTableTypes()).withJobId(jobConfiguration).withStartTime(now).build();
analyticsTableGenerator.generateTables(params, progress);
}
}
use of org.hisp.dhis.analytics.AnalyticsTableUpdateParams in project dhis2-core by dhis2.
the class JdbcEventAnalyticsTableManagerTest method verifyGetTableWithTrackedEntityAttribute.
@Test
void verifyGetTableWithTrackedEntityAttribute() {
when(databaseInfo.isSpatialSupport()).thenReturn(true);
Program program = createProgram('A');
TrackedEntityAttribute tea1 = rnd.nextObject(TrackedEntityAttribute.class);
tea1.setValueType(ValueType.ORGANISATION_UNIT);
ProgramTrackedEntityAttribute tea = new ProgramTrackedEntityAttribute(program, tea1);
program.setProgramAttributes(Collections.singletonList(tea));
DataElement d1 = createDataElement('Z', ValueType.TEXT, AggregationType.SUM);
ProgramStage ps1 = createProgramStage('A', Sets.newHashSet(d1));
program.setProgramStages(Sets.newHashSet(ps1));
when(idObjectManager.getAllNoAcl(Program.class)).thenReturn(Lists.newArrayList(program));
String aliasD1 = "(select eventdatavalues #>> '{%s, value}' " + FROM_CLAUSE + " ) as \"%s\"";
String aliasTea1 = "(select %s from organisationunit ou where ou.uid = (select value from " + "trackedentityattributevalue where trackedentityinstanceid=pi.trackedentityinstanceid and " + "trackedentityattributeid=%d)) as \"%s\"";
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withLastYears(2).withStartTime(START_TIME).withToday(today).build();
when(jdbcTemplate.queryForList(getYearQueryForCurrentYear(program, true), Integer.class)).thenReturn(Lists.newArrayList(2018, 2019));
List<AnalyticsTable> tables = subject.getAnalyticsTables(params);
assertThat(tables, hasSize(1));
new AnalyticsTableAsserter.Builder(tables.get(0)).withTableName(TABLE_PREFIX + program.getUid().toLowerCase()).withTableType(AnalyticsTableType.EVENT).withColumnSize(54).addColumns(periodColumns).addColumn(d1.getUid(), TEXT, // ValueType.TEXT
toAlias(aliasD1, d1.getUid())).addColumn(tea1.getUid(), TEXT, String.format(aliasTea1, "ou.uid", tea1.getId(), tea1.getUid())).addColumn(tea1.getUid() + "_geom", GEOMETRY, String.format(aliasTea1, "ou.geometry", tea1.getId(), tea1.getUid()), IndexType.GIST).addColumn(tea1.getUid() + "_name", TEXT, String.format(aliasTea1, "ou.name", tea1.getId(), tea1.getUid())).withDefaultColumns(subject.getFixedColumns()).build().verify();
}
use of org.hisp.dhis.analytics.AnalyticsTableUpdateParams in project dhis2-core by dhis2.
the class JdbcEventAnalyticsTableManagerTest method verifyGetAnalyticsTableWithOptionGroupSets.
@Test
void verifyGetAnalyticsTableWithOptionGroupSets() {
List<CategoryOptionGroupSet> cogs = rnd.objects(CategoryOptionGroupSet.class, 2).collect(Collectors.toList());
Program programA = rnd.nextObject(Program.class);
programA.setId(0);
when(idObjectManager.getAllNoAcl(Program.class)).thenReturn(Collections.singletonList(programA));
when(categoryService.getAttributeCategoryOptionGroupSetsNoAcl()).thenReturn(cogs);
when(jdbcTemplate.queryForList(getYearQueryForCurrentYear(programA, false), Integer.class)).thenReturn(Lists.newArrayList(2018, 2019));
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime(START_TIME).build();
List<AnalyticsTable> tables = subject.getAnalyticsTables(params);
assertThat(tables, hasSize(1));
new AnalyticsTableAsserter.Builder(tables.get(0)).withTableName(TABLE_PREFIX + programA.getUid().toLowerCase()).withTableType(AnalyticsTableType.EVENT).withColumnSize(subject.getFixedColumns().size() + PeriodType.getAvailablePeriodTypes().size() + cogs.size() + (programA.isRegistration() ? 1 : 0)).addColumns(periodColumns).withDefaultColumns(subject.getFixedColumns()).addColumn(quote(cogs.get(0).getUid()), col -> match(cogs.get(0), col)).addColumn(quote(cogs.get(1).getUid()), col -> match(cogs.get(1), col)).build().verify();
}
Aggregations