Search in sources :

Example 6 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class DataValueAclCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    final TrackerAccessManager trackerAccessManager = ctx.getServiceDelegator().getTrackerAccessManager();
    final ProgramStageInstance programStageInstance = ctx.getProgramStageInstanceMap().get(event.getUid());
    Map<String, Set<EventDataValue>> eventDataValueMap = ctx.getEventDataValueMap();
    final User user = ctx.getImportOptions().getUser();
    final ImportSummary importSummary = new ImportSummary();
    // Note that here we are passing a ProgramStageInstance, which during a
    // INSERT
    // operation
    // is going to be null, so the ACL method will not be able to check that
    final Set<EventDataValue> dataValues = eventDataValueMap.get(event.getUid());
    for (EventDataValue dataValue : dataValues) {
        DataElement dataElement = ctx.getDataElementMap().get(dataValue.getDataElement());
        List<String> errors = trackerAccessManager.canWrite(user, programStageInstance, dataElement, true);
        if (!errors.isEmpty()) {
            errors.forEach(error -> importSummary.addConflict(dataElement.getUid(), error));
        }
    }
    return importSummary;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Set(java.util.Set) User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 7 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class EventDateCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    if (EventStatus.ACTIVE == event.getStatus() && event.getEventDate() == null) {
        return new ImportSummary(ImportStatus.ERROR, "Event date is required. ").setReference(event.getEvent()).incrementIgnored();
    }
    try {
        DateUtils.parseDate(event.getDueDate());
        DateUtils.parseDate(event.getEventDate());
        DateUtils.parseDate(event.getCompletedDate());
    } catch (Exception e) {
        return new ImportSummary(ImportStatus.ERROR, "Event date or Execution date format is not correct. ").setReference(event.getEvent()).incrementIgnored();
    }
    return success();
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary)

Example 8 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class ProgramInstanceRepeatableStageCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    IdScheme scheme = ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme();
    ProgramStage programStage = ctx.getProgramStage(scheme, event.getProgramStage());
    ProgramInstance programInstance = ctx.getProgramInstanceMap().get(event.getUid());
    Program program = ctx.getProgramsMap().get(event.getProgram());
    TrackedEntityInstance tei = null;
    if (program.isRegistration()) {
        tei = ctx.getTrackedEntityInstanceMap().get(event.getUid()).getLeft();
    }
    // @formatter:off
    if (programInstance != null && tei != null && program.isRegistration() && !programStage.getRepeatable() && hasProgramStageInstance(ctx.getServiceDelegator().getJdbcTemplate(), programInstance.getId(), programStage.getId(), tei.getId())) {
        return new ImportSummary(ImportStatus.ERROR, "Program stage is not repeatable and an event already exists").setReference(event.getEvent()).incrementIgnored();
    }
    return success();
}
Also used : Program(org.hisp.dhis.program.Program) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance) IdScheme(org.hisp.dhis.common.IdScheme) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 9 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class AttributeOptionComboAclCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    ImportSummary importSummary = new ImportSummary();
    TrackerAccessManager trackerAccessManager = ctx.getServiceDelegator().getTrackerAccessManager();
    ImportOptions importOptions = ctx.getImportOptions();
    CategoryOptionCombo categoryOptionCombo = ctx.getCategoryOptionComboMap().get(event.getUid());
    List<String> errors = trackerAccessManager.canWrite(importOptions.getUser(), categoryOptionCombo);
    if (!errors.isEmpty()) {
        importSummary.setStatus(ImportStatus.ERROR);
        errors.forEach(error -> importSummary.addConflict("CategoryOptionCombo", error));
        importSummary.incrementIgnored();
    }
    return importSummary;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 10 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class ProgramInstanceRepeatableStageCheckTest method successOnNonRepeatableStageAndExistingEventsOnNewEnrollment.

@Test
void successOnNonRepeatableStageAndExistingEventsOnNewEnrollment() {
    // Data preparation
    Program program = createProgram('P');
    TrackedEntityInstance tei = createTrackedEntityInstance('A', createOrganisationUnit('A'));
    event.setProgramStage(CodeGenerator.generateUid());
    event.setProgram(program.getUid());
    event.setTrackedEntityInstance(tei.getUid());
    ProgramStage programStage = createProgramStage('A', program);
    programStage.setRepeatable(false);
    when(workContext.getProgramStage(programStageIdScheme, event.getProgramStage())).thenReturn(programStage);
    Map<String, Program> programMap = new HashMap<>();
    programMap.put(program.getUid(), program);
    Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
    ProgramInstance programInstance = new ProgramInstance();
    programInstanceMap.put(event.getUid(), programInstance);
    Pair<TrackedEntityInstance, Boolean> teiPair = Pair.of(tei, true);
    Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = new HashMap<>();
    teiMap.put(event.getUid(), teiPair);
    when(workContext.getTrackedEntityInstanceMap()).thenReturn(teiMap);
    when(workContext.getProgramsMap()).thenReturn(programMap);
    when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
    when(workContext.getServiceDelegator()).thenReturn(serviceDelegator);
    when(serviceDelegator.getJdbcTemplate()).thenReturn(jdbcTemplate);
    when(jdbcTemplate.queryForObject(anyString(), eq(Boolean.class), eq(programInstance.getId()), eq(programStage.getId()), eq(tei.getId()))).thenReturn(false);
    // Method under test
    ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
    assertNoError(summary);
}
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisConvenienceTest.createTrackedEntityInstance(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) DhisConvenienceTest.createProgramStage(org.hisp.dhis.DhisConvenienceTest.createProgramStage) ProgramStage(org.hisp.dhis.program.ProgramStage) Pair(org.apache.commons.lang3.tuple.Pair) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)49 ImmutableEvent (org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)38 Test (org.junit.jupiter.api.Test)35 BaseValidationTest (org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)34 Program (org.hisp.dhis.program.Program)18 HashMap (java.util.HashMap)17 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)13 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)11 ProgramInstance (org.hisp.dhis.program.ProgramInstance)10 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)9 ProgramStage (org.hisp.dhis.program.ProgramStage)8 DataElement (org.hisp.dhis.dataelement.DataElement)7 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)7 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)7 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)5 DhisConvenienceTest.createProgramStageDataElement (org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement)5 DhisConvenienceTest.createTrackedEntityInstance (org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance)5 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)5 EventTestUtils.createDataValue (org.hisp.dhis.dxf2.events.importer.EventTestUtils.createDataValue)5 EventTestUtils.createEventDataValue (org.hisp.dhis.dxf2.events.importer.EventTestUtils.createEventDataValue)5