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);
}
}
}
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);
}
Aggregations