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