Search in sources :

Example 1 with ImmutableEvent

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

the class DataValueCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    final Set<DataValue> dataValues = event.getDataValues();
    final ImportSummary importSummary = new ImportSummary();
    final User user = ctx.getImportOptions().getUser();
    for (DataValue dataValue : dataValues) {
        if (!checkHasValidDataElement(importSummary, ctx, dataValue) || !checkSerializeToJson(importSummary, ctx, dataValue)) {
            importSummary.setStatus(ImportStatus.ERROR);
            importSummary.setReference(event.getUid());
            importSummary.incrementIgnored();
            return importSummary;
        }
    }
    if (!importSummary.hasConflicts()) {
        if (doValidationOfMandatoryAttributes(user) && isValidationRequired(event, ctx)) {
            validateMandatoryAttributes(importSummary, ctx, event);
        }
    }
    if (importSummary.hasConflicts()) {
        importSummary.setStatus(ImportStatus.ERROR);
        importSummary.setReference(event.getUid());
        importSummary.incrementIgnored();
    }
    return importSummary;
}
Also used : User(org.hisp.dhis.user.User) DataValue(org.hisp.dhis.dxf2.events.event.DataValue) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary)

Example 2 with ImmutableEvent

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

the class AttributeOptionComboCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    Program program = ctx.getProgramsMap().get(event.getProgram());
    CategoryOptionCombo coc = ctx.getCategoryOptionComboMap().get(event.getUid());
    if (coc != null && coc.isDefault() && program.getCategoryCombo() != null && !program.getCategoryCombo().isDefault()) {
        ImportSummary importSummary = new ImportSummary(event.getEvent());
        importSummary.addConflict("attributeOptionCombo", "Valid attribute option combo must be specified since program does not have the default category combo");
        importSummary.setStatus(ImportStatus.ERROR);
        return importSummary.incrementIgnored();
    }
    return success();
}
Also used : Program(org.hisp.dhis.program.Program) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 3 with ImmutableEvent

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

the class BaseEventAclCheck method check.

public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    ImportOptions importOptions = ctx.getImportOptions();
    ProgramStageInstance programStageInstance = prepareForAclValidation(ctx, event);
    List<String> errors = checkAcl(ctx.getServiceDelegator().getTrackerAccessManager(), importOptions.getUser(), programStageInstance);
    final ImportSummary importSummary = new ImportSummary();
    if (!errors.isEmpty()) {
        errors.forEach(error -> importSummary.addConflict(event.getUid(), error));
        importSummary.incrementIgnored();
        importSummary.setStatus(ImportStatus.ERROR);
        importSummary.setReference(event.getEvent());
    }
    return importSummary;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 4 with ImmutableEvent

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

the class EventBaseCheck method validateProgramInstance.

private void validateProgramInstance(ImmutableEvent event, WorkContext ctx, List<String> errors) {
    ProgramInstance programInstance = ctx.getProgramInstanceMap().get(event.getUid());
    ImportOptions importOptions = ctx.getImportOptions();
    if (programInstance == null) {
        errors.add("No program instance found for event: " + event.getEvent());
    } else if (COMPLETED.equals(programInstance.getStatus())) {
        if (importOptions == null || importOptions.getUser() == null || importOptions.getUser().isAuthorized(F_EDIT_EXPIRED.getAuthority())) {
            return;
        }
        Date referenceDate = parseDate(event.getCreated());
        if (referenceDate == null) {
            referenceDate = new Date();
        }
        referenceDate = removeTimeStamp(referenceDate);
        if (referenceDate.after(removeTimeStamp(programInstance.getEndDate()))) {
            errors.add("Not possible to add event to a completed enrollment. Event created date ( " + referenceDate + " ) is after enrollment completed date ( " + removeTimeStamp(programInstance.getEndDate()) + " ).");
        }
    }
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Date(java.util.Date) DateUtils.parseDate(org.hisp.dhis.util.DateUtils.parseDate)

Example 5 with ImmutableEvent

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

the class ProgramStageInstanceBasicCheck method check.

@Override
public ImportSummary check(final ImmutableEvent event, final WorkContext ctx) {
    final ProgramStageInstance programStageInstance = ctx.getProgramStageInstanceMap().get(event.getEvent());
    if (programStageInstance == null) {
        final ImportSummary error = error("Event ID " + event.getEvent() + " doesn't point to valid event", event.getEvent());
        error.addConflict("Invalid Event ID", event.getEvent());
        return error;
    } else if (programStageInstance.isDeleted() || ctx.getImportOptions().getImportStrategy().isCreate()) {
        return error("Event ID " + event.getEvent() + " was already used and/or deleted. This event can not be modified.").setReference(event.getEvent());
    }
    return success();
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

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