Search in sources :

Example 41 with WorkContext

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

the class EventGeometryCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    IdScheme scheme = ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme();
    ProgramStage programStage = ctx.getProgramStage(scheme, event.getProgramStage());
    if (Objects.nonNull(event.getGeometry()) && programStageFeatureCompatibleWithEventGeometry(event, programStage)) {
        return new ImportSummary(ImportStatus.ERROR, "Geometry (" + event.getGeometry().getGeometryType() + ") does not conform to the feature type (" + programStage.getFeatureType().value() + ") specified for the program stage: " + programStage.getUid()).setReference(event.getEvent()).incrementIgnored();
    }
    return success();
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) IdScheme(org.hisp.dhis.common.IdScheme) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 42 with WorkContext

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

the class ExpirationDaysCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    final ImportOptions importOptions = ctx.getImportOptions();
    final Program program = ctx.getProgramsMap().get(event.getProgram());
    final ProgramStageInstance programStageInstance = ctx.getProgramStageInstanceMap().get(event.getEvent());
    if (importOptions == null || importOptions.getUser() == null || importOptions.getUser().isAuthorized(Authorities.F_EDIT_EXPIRED.getAuthority())) {
        return success();
    }
    if (program != null) {
        ImportSummary importSummary = checkEventOrPsiCompletedDate(program, event, programStageInstance);
        if (importSummary.isStatus(ImportStatus.ERROR)) {
            return importSummary;
        }
        return checkEventOrPsiExpirationDate(program, event, programStageInstance);
    }
    return success();
}
Also used : Program(org.hisp.dhis.program.Program) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 43 with WorkContext

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

the class TrackedEntityInstanceCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    Program program = ctx.getProgramsMap().get(event.getProgram());
    final Optional<TrackedEntityInstance> trackedEntityInstance = ctx.getTrackedEntityInstance(event.getUid());
    if (program.isRegistration() && !trackedEntityInstance.isPresent()) {
        return new ImportSummary(ImportStatus.ERROR, "Event.trackedEntityInstance does not point to a valid tracked entity instance: " + event.getTrackedEntityInstance()).setReference(event.getEvent()).incrementIgnored();
    }
    return success();
}
Also used : Program(org.hisp.dhis.program.Program) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 44 with WorkContext

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

the class EventStoredByPreProcessor method process.

@Override
public void process(Event event, WorkContext ctx) {
    final String storedBy = EventUtils.getValidUsername(event.getStoredBy(), ctx.getImportOptions());
    event.setStoredBy(storedBy);
    Set<DataValue> dataValues = event.getDataValues();
    for (DataValue dataValue : dataValues) {
        dataValue.setStoredBy(storedBy);
    }
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue)

Example 45 with WorkContext

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

the class EventBaseCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    ImportSummary importSummary = new ImportSummary();
    List<String> errors = validate(event, ctx);
    if (!errors.isEmpty()) {
        importSummary.setStatus(ERROR);
        importSummary.setReference(event.getEvent());
        errors.forEach(error -> importSummary.addConflict("Event", error));
        importSummary.incrementIgnored();
    }
    return importSummary;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary)

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