Search in sources :

Example 6 with TrackerImportValidationContext

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);
}
Also used : EVENT_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.EVENT_CANT_BE_NULL) Authorities(org.hisp.dhis.security.Authorities) CategoryOption(org.hisp.dhis.category.CategoryOption) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) E1100(org.hisp.dhis.tracker.report.TrackerErrorCode.E1100) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Relationship(org.hisp.dhis.tracker.domain.Relationship) E1083(org.hisp.dhis.tracker.report.TrackerErrorCode.E1083) Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) PROGRAM_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL) TRACKED_ENTITY_TYPE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.TRACKED_ENTITY_TYPE_CANT_BE_NULL) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TRACKED_ENTITY_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.TRACKED_ENTITY_CANT_BE_NULL) USER_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.USER_CANT_BE_NULL) ProgramInstance(org.hisp.dhis.program.ProgramInstance) PROGRAM_STAGE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.PROGRAM_STAGE_CANT_BE_NULL) User(org.hisp.dhis.user.User) ORGANISATION_UNIT_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.ORGANISATION_UNIT_CANT_BE_NULL) PROGRAM_INSTANCE_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.PROGRAM_INSTANCE_CANT_BE_NULL) Event(org.hisp.dhis.tracker.domain.Event) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) NonNull(lombok.NonNull) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) ENROLLMENT_CANT_BE_NULL(org.hisp.dhis.tracker.validation.hooks.TrackerImporterAssertErrors.ENROLLMENT_CANT_BE_NULL) EventStatus(org.hisp.dhis.event.EventStatus) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackerOwnershipManager(org.hisp.dhis.trackedentity.TrackerOwnershipManager) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) E1103(org.hisp.dhis.tracker.report.TrackerErrorCode.E1103) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) AclService(org.hisp.dhis.security.acl.AclService) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackerDto(org.hisp.dhis.tracker.domain.TrackerDto) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) User(org.hisp.dhis.user.User) 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) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 7 with TrackerImportValidationContext

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");
}
Also used : Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 8 with TrackerImportValidationContext

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");
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 9 with TrackerImportValidationContext

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());
    }
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) RelationshipType(org.hisp.dhis.relationship.RelationshipType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle)

Example 10 with TrackerImportValidationContext

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;
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Note(org.hisp.dhis.tracker.domain.Note) ArrayList(java.util.ArrayList) TrackerWarningReport(org.hisp.dhis.tracker.report.TrackerWarningReport)

Aggregations

TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)46 Program (org.hisp.dhis.program.Program)14 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)14 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)13 ProgramStage (org.hisp.dhis.program.ProgramStage)11 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)8 Test (org.junit.jupiter.api.Test)8 List (java.util.List)7 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)7 Event (org.hisp.dhis.tracker.domain.Event)7 Note (org.hisp.dhis.tracker.domain.Note)7 Collectors (java.util.stream.Collectors)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)5 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 TrackedEntityComment (org.hisp.dhis.trackedentitycomment.TrackedEntityComment)4 TrackerType (org.hisp.dhis.tracker.TrackerType)4 User (org.hisp.dhis.user.User)4