use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHook method validateTrackedEntity.
@Override
public void validateTrackedEntity(ValidationErrorReporter reporter, TrackedEntity trackedEntity) {
TrackerImportValidationContext context = reporter.getValidationContext();
TrackerImportStrategy strategy = context.getStrategy(trackedEntity);
TrackerBundle bundle = context.getBundle();
User user = bundle.getUser();
checkNotNull(user, USER_CANT_BE_NULL);
checkNotNull(trackedEntity, TRACKED_ENTITY_CANT_BE_NULL);
checkNotNull(trackedEntity.getOrgUnit(), ORGANISATION_UNIT_CANT_BE_NULL);
// scope has to be checked
if (strategy.isCreate() || strategy.isDelete()) {
checkOrgUnitInCaptureScope(reporter, trackedEntity, context.getOrganisationUnit(trackedEntity.getOrgUnit()));
} else // if its to update trackedEntity, search scope has to be checked
{
checkOrgUnitInSearchScope(reporter, trackedEntity, context.getOrganisationUnit(trackedEntity.getOrgUnit()));
}
if (strategy.isDelete()) {
TrackedEntityInstance tei = context.getTrackedEntityInstance(trackedEntity.getTrackedEntity());
if (tei.getProgramInstances().stream().anyMatch(pi -> !pi.isDeleted()) && !user.isAuthorized(Authorities.F_TEI_CASCADE_DELETE.getAuthority())) {
TrackerErrorReport error = TrackerErrorReport.builder().uid(trackedEntity.getUid()).trackerType(TrackerType.TRACKED_ENTITY).errorCode(E1100).addArg(user).addArg(tei).build(bundle);
reporter.addError(error);
}
}
TrackedEntityType trackedEntityType = context.getTrackedEntityType(trackedEntity.getTrackedEntityType());
checkTeiTypeWriteAccess(reporter, trackedEntity.getUid(), trackedEntityType);
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class PreCheckUpdatableFieldsValidationHook method validateEnrollment.
@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
TrackerImportValidationContext context = reporter.getValidationContext();
ProgramInstance pi = context.getProgramInstance(enrollment.getEnrollment());
Program program = pi.getProgram();
TrackedEntityInstance trackedEntityInstance = pi.getEntityInstance();
reporter.addErrorIf(() -> !program.getUid().equals(enrollment.getProgram()), enrollment, E1127, "program");
reporter.addErrorIf(() -> !trackedEntityInstance.getUid().equals(enrollment.getTrackedEntity()), enrollment, E1127, "trackedEntity");
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class PreCheckUpdatableFieldsValidationHook method validateTrackedEntity.
@Override
public void validateTrackedEntity(ValidationErrorReporter reporter, TrackedEntity trackedEntity) {
TrackerImportValidationContext context = reporter.getValidationContext();
TrackedEntityInstance trackedEntityInstance = context.getTrackedEntityInstance(trackedEntity.getTrackedEntity());
reporter.addErrorIf(() -> !trackedEntityInstance.getTrackedEntityType().getUid().equals(trackedEntity.getTrackedEntityType()), trackedEntity, E1126, "trackedEntityType");
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class RelationshipsValidationHook method validateRelationship.
public void validateRelationship(ValidationErrorReporter reporter, Relationship relationship) {
TrackerImportValidationContext context = reporter.getValidationContext();
TrackerBundle bundle = context.getBundle();
boolean isValid = validateMandatoryData(reporter, relationship, bundle.getPreheat().getAll(RelationshipType.class));
// Relationship
if (isValid) {
validateRelationshipLinkToOneEntity(reporter, relationship);
validateRelationshipConstraint(reporter, relationship, bundle);
validateAutoRelationship(reporter, relationship);
validateReferences(reporter, relationship, relationship.getFrom());
validateReferences(reporter, relationship, relationship.getTo());
}
}
use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.
the class ValidationUtils method validateNotes.
protected static List<Note> validateNotes(ValidationErrorReporter reporter, TrackerDto dto, List<Note> notesToCheck) {
TrackerImportValidationContext context = reporter.getValidationContext();
final List<Note> notes = new ArrayList<>();
for (Note note : notesToCheck) {
if (// Ignore notes with no text
isNotEmpty(note.getValue())) {
// warning, ignore the note and continue
if (isNotEmpty(note.getNote()) && context.getNote(note.getNote()).isPresent()) {
TrackerWarningReport warning = TrackerWarningReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).warningCode(TrackerErrorCode.E1119).addArg(note.getNote()).build(reporter.getValidationContext().getBundle());
reporter.addWarning(warning);
} else {
notes.add(note);
}
}
}
return notes;
}
Aggregations