Search in sources :

Example 6 with AnalyticsTableUpdateParams

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));
}
Also used : AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 7 with AnalyticsTableUpdateParams

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);
}
Also used : AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) AnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.AnalyticsJobParameters) Date(java.util.Date)

Example 8 with AnalyticsTableUpdateParams

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);
    }
}
Also used : ContinuousAnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.ContinuousAnalyticsJobParameters) AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) Date(java.util.Date)

Example 9 with AnalyticsTableUpdateParams

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();
}
Also used : DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgramTrackedEntityAttribute(org.hisp.dhis.DhisConvenienceTest.createProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) DhisConvenienceTest.createTrackedEntityAttribute(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) AnalyticsTableAsserter(org.hisp.dhis.analytics.util.AnalyticsTableAsserter) DhisConvenienceTest.createProgramTrackedEntityAttribute(org.hisp.dhis.DhisConvenienceTest.createProgramTrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) Matchers.containsString(org.hamcrest.Matchers.containsString) DhisConvenienceTest.createProgramStage(org.hisp.dhis.DhisConvenienceTest.createProgramStage) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 10 with AnalyticsTableUpdateParams

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();
}
Also used : AnalyticsTableAsserter(org.hisp.dhis.analytics.util.AnalyticsTableAsserter) BeforeEach(org.junit.jupiter.api.BeforeEach) CategoryService(org.hisp.dhis.category.CategoryService) BeanRandomizer(org.hisp.dhis.random.BeanRandomizer) CHARACTER_11(org.hisp.dhis.analytics.ColumnDataType.CHARACTER_11) ResourceTableService(org.hisp.dhis.resourcetable.ResourceTableService) Date(java.util.Date) ValueType(org.hisp.dhis.common.ValueType) AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) GEOMETRY(org.hisp.dhis.analytics.ColumnDataType.GEOMETRY) GEOMETRY_POINT(org.hisp.dhis.analytics.ColumnDataType.GEOMETRY_POINT) DhisConvenienceTest.createProgramStage(org.hisp.dhis.DhisConvenienceTest.createProgramStage) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) INTEGER(org.hisp.dhis.analytics.ColumnDataType.INTEGER) Map(java.util.Map) AnalyticsTableType(org.hisp.dhis.analytics.AnalyticsTableType) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) IndexType(org.hisp.dhis.analytics.IndexType) Category(org.hisp.dhis.category.Category) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) DhisConvenienceTest.createCategory(org.hisp.dhis.DhisConvenienceTest.createCategory) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) Matchers.equalTo(org.hamcrest.Matchers.equalTo) LocalDate(java.time.LocalDate) Matchers.is(org.hamcrest.Matchers.is) DhisConvenienceTest.createProgramTrackedEntityAttribute(org.hisp.dhis.DhisConvenienceTest.createProgramTrackedEntityAttribute) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Matchers.containsString(org.hamcrest.Matchers.containsString) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Mockito.mock(org.mockito.Mockito.mock) TIMESTAMP(org.hisp.dhis.analytics.ColumnDataType.TIMESTAMP) DhisConvenienceTest.createTrackedEntityAttribute(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityAttribute) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) DOUBLE(org.hisp.dhis.analytics.ColumnDataType.DOUBLE) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) Mock(org.mockito.Mock) PostgreSQLStatementBuilder(org.hisp.dhis.jdbc.statementbuilder.PostgreSQLStatementBuilder) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) AnalyticsTableHookService(org.hisp.dhis.analytics.AnalyticsTableHookService) PartitionManager(org.hisp.dhis.analytics.partition.PartitionManager) Program(org.hisp.dhis.program.Program) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) HashSet(java.util.HashSet) DataElement(org.hisp.dhis.dataelement.DataElement) DatabaseInfo(org.hisp.dhis.system.database.DatabaseInfo) ArgumentCaptor(org.mockito.ArgumentCaptor) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) BIGINT(org.hisp.dhis.analytics.ColumnDataType.BIGINT) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) ColumnNotNullConstraint(org.hisp.dhis.analytics.ColumnNotNullConstraint) DhisConvenienceTest.createCategoryCombo(org.hisp.dhis.DhisConvenienceTest.createCategoryCombo) DataApprovalLevelService(org.hisp.dhis.dataapproval.DataApprovalLevelService) AnalyticsTablePartition(org.hisp.dhis.analytics.AnalyticsTablePartition) DateTime(org.joda.time.DateTime) TEXT(org.hisp.dhis.analytics.ColumnDataType.TEXT) AggregationType(org.hisp.dhis.analytics.AggregationType) Mockito.when(org.mockito.Mockito.when) StatementBuilder(org.hisp.dhis.jdbc.StatementBuilder) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) ProgramStage(org.hisp.dhis.program.ProgramStage) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) PeriodType(org.hisp.dhis.period.PeriodType) DhisConvenienceTest.getDate(org.hisp.dhis.DhisConvenienceTest.getDate) SettingKey(org.hisp.dhis.setting.SettingKey) Collections(java.util.Collections) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) Program(org.hisp.dhis.program.Program) AnalyticsTableAsserter(org.hisp.dhis.analytics.util.AnalyticsTableAsserter) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) Test(org.junit.jupiter.api.Test)

Aggregations

AnalyticsTableUpdateParams (org.hisp.dhis.analytics.AnalyticsTableUpdateParams)16 Test (org.junit.jupiter.api.Test)14 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)11 Program (org.hisp.dhis.program.Program)11 Date (java.util.Date)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 AnalyticsTable (org.hisp.dhis.analytics.AnalyticsTable)9 DhisConvenienceTest.createProgramTrackedEntityAttribute (org.hisp.dhis.DhisConvenienceTest.createProgramTrackedEntityAttribute)7 DhisConvenienceTest.createTrackedEntityAttribute (org.hisp.dhis.DhisConvenienceTest.createTrackedEntityAttribute)7 ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)7 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)7 DateTime (org.joda.time.DateTime)7 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)6 DhisConvenienceTest.createProgramStage (org.hisp.dhis.DhisConvenienceTest.createProgramStage)6 AnalyticsTablePartition (org.hisp.dhis.analytics.AnalyticsTablePartition)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Map (java.util.Map)5 LocalDate (java.time.LocalDate)4 HashSet (java.util.HashSet)4 DhisConvenienceTest.createCategory (org.hisp.dhis.DhisConvenienceTest.createCategory)4