Search in sources :

Example 26 with WorkContext

use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.

the class EventBaseCheckTest method verifyErrorOnInvalidEventDate.

@Test
void verifyErrorOnInvalidEventDate() {
    event.setEvent(event.getUid());
    event.setEventDate("111-12-122");
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(importSummary, event, null);
    assertHasConflict(importSummary, event, "Invalid event date: " + event.getEventDate());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Example 27 with WorkContext

use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.

the class FilteredDataValueCheckTest method testNotLinkedDataElementsAreReported.

@Test
void testNotLinkedDataElementsAreReported() {
    Event event = new Event();
    event.setProgramStage(PROGRAMSTAGE);
    HashSet<DataValue> dataValues = Sets.newHashSet(new DataValue(DATA_ELEMENT_1, "whatever"), new DataValue(DATA_ELEMENT_2, "another value"));
    event.setDataValues(dataValues);
    WorkContext ctx = WorkContext.builder().importOptions(ImportOptions.getDefaultImportOptions()).programsMap(getProgramMap()).eventDataValueMap(new EventDataValueAggregator().aggregateDataValues(ImmutableList.of(event), Collections.emptyMap(), ImportOptions.getDefaultImportOptions())).build();
    ImportSummary importSummary = dataValueCheck.check(new ImmutableEvent(event), ctx);
    assertEquals(ImportStatus.WARNING, importSummary.getStatus());
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EventDataValueAggregator(org.hisp.dhis.dxf2.events.importer.context.EventDataValueAggregator) Event(org.hisp.dhis.dxf2.events.event.Event) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test)

Example 28 with WorkContext

use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.

the class ProgramInstanceCheckTest method failOnMultipleProgramInstance.

@Test
void failOnMultipleProgramInstance() {
    // Data preparation
    Program programNoReg = createProgram('P');
    programNoReg.setProgramType(ProgramType.WITHOUT_REGISTRATION);
    Map<String, Program> programMap = new HashMap<>();
    programMap.put(programNoReg.getUid(), programNoReg);
    when(workContext.getProgramsMap()).thenReturn(programMap);
    // 
    // Program Instance
    // 
    when(workContext.getProgramInstanceMap()).thenReturn(new HashMap<>());
    // 
    // Tracked Entity Instance
    // 
    TrackedEntityInstance tei = createTrackedEntityInstance(createOrganisationUnit('A'));
    Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = new HashMap<>();
    teiMap.put(event.getUid(), Pair.of(tei, true));
    when(workContext.getTrackedEntityInstanceMap()).thenReturn(teiMap);
    ProgramInstance programInstance1 = new ProgramInstance();
    ProgramInstance programInstance2 = new ProgramInstance();
    when(this.programInstanceStore.get(programNoReg, ProgramStatus.ACTIVE)).thenReturn(Lists.newArrayList(programInstance1, programInstance2));
    event.setProgram(programNoReg.getUid());
    // 
    // Method under test
    // 
    ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(summary, event, "Multiple active program instances exists for program: " + programNoReg.getUid());
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisConvenienceTest.createTrackedEntityInstance(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance) Pair(org.apache.commons.lang3.tuple.Pair) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Example 29 with WorkContext

use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.

the class ExpirationDaysCheckTest method failWhenEventHasNoDateAndProgramExpiryDaysBasedOnPeriod.

@Test
void failWhenEventHasNoDateAndProgramExpiryDaysBasedOnPeriod() {
    // Given
    final String monthlyPeriodType = new SimpleDateFormat("yyyyMM").format(new Date());
    // Prepare program
    Program program = createProgram('P');
    program.setExpiryPeriodType(PeriodType.getPeriodTypeFromIsoString(monthlyPeriodType));
    program.setExpiryDays(3);
    Map<String, Program> programMap = new HashMap<>();
    programMap.put(program.getUid(), program);
    when(workContext.getProgramsMap()).thenReturn(programMap);
    // Prepare event
    event.setProgram(program.getUid());
    // When
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    // Then
    assertHasError(importSummary, event, "Event needs to have at least one (event or schedule) date");
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Example 30 with WorkContext

use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.

the class ExpirationDaysCheckTest method failWhenEventHasDateBeforeCurrentDateAndProgramExpiryDaysBasedOnPeriod.

@Test
void failWhenEventHasDateBeforeCurrentDateAndProgramExpiryDaysBasedOnPeriod() {
    // Given
    final String monthlyPeriodType = new SimpleDateFormat("yyyyMM").format(new Date());
    // Prepare program
    Program program = createProgram('P');
    program.setExpiryPeriodType(PeriodType.getPeriodTypeFromIsoString(monthlyPeriodType));
    program.setExpiryDays(3);
    Map<String, Program> programMap = new HashMap<>();
    programMap.put(program.getUid(), program);
    when(workContext.getProgramsMap()).thenReturn(programMap);
    // Prepare event
    event.setProgram(program.getUid());
    event.setEventDate(new SimpleDateFormat("yyyy-MM-dd").format(getTodayMinusDays(100)));
    // When
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    // Then
    assertHasError(importSummary, event, "The event's date belongs to an expired period. It is not possible to create such event");
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)47 ImmutableEvent (org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)35 Test (org.junit.jupiter.api.Test)35 BaseValidationTest (org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)26 Program (org.hisp.dhis.program.Program)23 HashMap (java.util.HashMap)20 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)16 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)14 ProgramInstance (org.hisp.dhis.program.ProgramInstance)14 WorkContext (org.hisp.dhis.dxf2.events.importer.context.WorkContext)13 Event (org.hisp.dhis.dxf2.events.event.Event)12 ProgramStage (org.hisp.dhis.program.ProgramStage)11 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)9 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)9 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)9 Set (java.util.Set)7 DhisConvenienceTest.createTrackedEntityInstance (org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance)7 IdScheme (org.hisp.dhis.common.IdScheme)6 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)6 User (org.hisp.dhis.user.User)5