Search in sources :

Example 6 with TrackerImportStrategy

use of org.hisp.dhis.tracker.TrackerImportStrategy in project dhis2-core by dhis2.

the class PreCheckSecurityOwnershipValidationHook method validateUpdateAndDeleteEvent.

private void validateUpdateAndDeleteEvent(ValidationErrorReporter reporter, Event event, ProgramStageInstance programStageInstance, String teiUid, OrganisationUnit ownerOrgUnit) {
    TrackerImportStrategy strategy = reporter.getValidationContext().getStrategy(event);
    User user = reporter.getValidationContext().getBundle().getUser();
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(programStageInstance, PROGRAM_INSTANCE_CANT_BE_NULL);
    checkNotNull(event, EVENT_CANT_BE_NULL);
    checkEventWriteAccess(reporter, event, programStageInstance.getProgramStage(), programStageInstance.getOrganisationUnit(), ownerOrgUnit, programStageInstance.getAttributeOptionCombo(), teiUid, programStageInstance.isCreatableInSearchScope());
    if (strategy.isUpdate() && EventStatus.COMPLETED == programStageInstance.getStatus() && event.getStatus() != programStageInstance.getStatus() && (!user.isSuper() && !user.isAuthorized("F_UNCOMPLETE_EVENT"))) {
        TrackerErrorReport error = TrackerErrorReport.builder().uid(event.getUid()).trackerType(TrackerType.EVENT).errorCode(E1083).addArg(user).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
    }
}
Also used : User(org.hisp.dhis.user.User) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 7 with TrackerImportStrategy

use of org.hisp.dhis.tracker.TrackerImportStrategy in project dhis2-core by dhis2.

the class RepeatedEventsValidationHook method validateNotMultipleEvents.

private void validateNotMultipleEvents(ValidationErrorReporter reporter, TrackerImportValidationContext context, Event event) {
    ProgramInstance programInstance = context.getProgramInstance(event.getEnrollment());
    ProgramStage programStage = context.getProgramStage(event.getProgramStage());
    TrackerImportStrategy strategy = context.getStrategy(event);
    if (strategy == TrackerImportStrategy.CREATE && programStage != null && programInstance != null && !programStage.getRepeatable() && context.programStageHasEvents(programStage.getUid(), programInstance.getUid())) {
        reporter.addError(event, TrackerErrorCode.E1039, event.getProgramStage());
    }
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 8 with TrackerImportStrategy

use of org.hisp.dhis.tracker.TrackerImportStrategy in project dhis2-core by dhis2.

the class PreCheckExistenceValidationHook method validateTrackedEntity.

@Override
public void validateTrackedEntity(ValidationErrorReporter reporter, TrackedEntity trackedEntity) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy importStrategy = context.getStrategy(trackedEntity);
    TrackedEntityInstance existingTe = context.getTrackedEntityInstance(trackedEntity.getTrackedEntity());
    // If the tracked entity is soft-deleted no operation is allowed
    if (existingTe != null && existingTe.isDeleted()) {
        reporter.addError(trackedEntity, E1114, trackedEntity.getTrackedEntity());
        return;
    }
    if (existingTe != null && importStrategy.isCreate()) {
        reporter.addError(trackedEntity, E1002, trackedEntity.getTrackedEntity());
    } else if (existingTe == null && importStrategy.isUpdateOrDelete()) {
        reporter.addError(trackedEntity, E1063, trackedEntity.getTrackedEntity());
    }
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 9 with TrackerImportStrategy

use of org.hisp.dhis.tracker.TrackerImportStrategy in project dhis2-core by dhis2.

the class PreCheckExistenceValidationHook method validateEnrollment.

@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy importStrategy = context.getStrategy(enrollment);
    ProgramInstance existingPi = context.getProgramInstance(enrollment.getEnrollment());
    // If the tracked entity is soft-deleted no operation is allowed
    if (existingPi != null && existingPi.isDeleted()) {
        reporter.addError(enrollment, E1113, enrollment.getEnrollment());
        return;
    }
    if (existingPi != null && importStrategy.isCreate()) {
        reporter.addError(enrollment, E1080, enrollment.getEnrollment());
    } else if (existingPi == null && importStrategy.isUpdateOrDelete()) {
        reporter.addError(enrollment, E1081, enrollment.getEnrollment());
    }
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) ProgramInstance(org.hisp.dhis.program.ProgramInstance)

Example 10 with TrackerImportStrategy

use of org.hisp.dhis.tracker.TrackerImportStrategy in project dhis2-core by dhis2.

the class PreCheckExistenceValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy importStrategy = context.getStrategy(event);
    ProgramStageInstance existingPsi = context.getProgramStageInstance(event.getEvent());
    // If the event is soft-deleted no operation is allowed
    if (existingPsi != null && existingPsi.isDeleted()) {
        reporter.addError(event, E1082, event.getEvent());
        return;
    }
    if (existingPsi != null && importStrategy.isCreate()) {
        reporter.addError(event, E1030, event.getEvent());
    } else if (existingPsi == null && importStrategy.isUpdateOrDelete()) {
        reporter.addError(event, E1032, event.getEvent());
    }
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Aggregations

TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)12 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)4 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)4 User (org.hisp.dhis.user.User)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Program (org.hisp.dhis.program.Program)3 ProgramStage (org.hisp.dhis.program.ProgramStage)3 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)3 TrackerErrorReport (org.hisp.dhis.tracker.report.TrackerErrorReport)3 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)2 Event (org.hisp.dhis.tracker.domain.Event)2 Relationship (org.hisp.dhis.tracker.domain.Relationship)2 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 NonNull (lombok.NonNull)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1