Search in sources :

Example 11 with TrackerImportStrategy

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

the class StrategyPreProcessor method preProcessRelationships.

public void preProcessRelationships(TrackerBundle bundle) {
    for (Relationship relationship : bundle.getRelationships()) {
        TrackerImportStrategy importStrategy = bundle.getImportStrategy();
        org.hisp.dhis.relationship.Relationship existingRelationship = bundle.getPreheat().getRelationship(TrackerIdScheme.UID, relationship);
        if (importStrategy.isCreateAndUpdate()) {
            if (existingRelationship == null) {
                bundle.setStrategy(relationship, TrackerImportStrategy.CREATE);
            } else {
                bundle.setStrategy(relationship, TrackerImportStrategy.UPDATE);
            }
        } else {
            bundle.setStrategy(relationship, importStrategy);
        }
    }
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy)

Example 12 with TrackerImportStrategy

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

the class PreCheckSecurityOwnershipValidationHook method validateEnrollment.

@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy strategy = context.getStrategy(enrollment);
    TrackerBundle bundle = context.getBundle();
    User user = bundle.getUser();
    Program program = strategy.isUpdateOrDelete() ? context.getProgramInstance(enrollment.getEnrollment()).getProgram() : context.getProgram(enrollment.getProgram());
    OrganisationUnit ownerOrgUnit = context.getOwnerOrganisationUnit(enrollment.getTrackedEntity(), enrollment.getProgram());
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(enrollment, ENROLLMENT_CANT_BE_NULL);
    checkNotNull(program, PROGRAM_CANT_BE_NULL);
    checkEnrollmentOrgUnit(reporter, context, strategy, enrollment, program);
    if (strategy.isDelete()) {
        boolean hasNonDeletedEvents = context.programInstanceHasEvents(enrollment.getEnrollment());
        boolean hasNotCascadeDeleteAuthority = !user.isAuthorized(Authorities.F_ENROLLMENT_CASCADE_DELETE.getAuthority());
        if (hasNonDeletedEvents && hasNotCascadeDeleteAuthority) {
            TrackerErrorReport error = TrackerErrorReport.builder().uid(enrollment.getUid()).trackerType(TrackerType.ENROLLMENT).errorCode(E1103).addArg(user).addArg(enrollment.getEnrollment()).build(bundle);
            reporter.addError(error);
        }
    }
    checkWriteEnrollmentAccess(reporter, enrollment, program, context, ownerOrgUnit);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

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