Search in sources :

Example 16 with TrackerErrorReport

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

the class PreCheckSecurityOwnershipValidationHook method checkTeiTypeAndTeiProgramAccess.

private void checkTeiTypeAndTeiProgramAccess(ValidationErrorReporter reporter, TrackerDto dto, User user, String trackedEntityInstance, OrganisationUnit ownerOrganisationUnit, Program program) {
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(program, PROGRAM_CANT_BE_NULL);
    checkNotNull(program.getTrackedEntityType(), TRACKED_ENTITY_TYPE_CANT_BE_NULL);
    checkNotNull(trackedEntityInstance, TRACKED_ENTITY_CANT_BE_NULL);
    if (!aclService.canDataRead(user, program.getTrackedEntityType())) {
        TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1104).addArg(user).addArg(program).addArg(program.getTrackedEntityType()).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
    }
    if (ownerOrganisationUnit != null && !ownershipAccessManager.hasAccess(user, trackedEntityInstance, ownerOrganisationUnit, program)) {
        TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1102).addArg(user).addArg(trackedEntityInstance).addArg(program).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
    }
}
Also used : TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 17 with TrackerErrorReport

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

the class PreCheckSecurityOwnershipValidationHook method checkProgramStageWriteAccess.

private void checkProgramStageWriteAccess(ValidationErrorReporter reporter, TrackerDto dto, User user, ProgramStage programStage) {
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(programStage, PROGRAM_STAGE_CANT_BE_NULL);
    if (!aclService.canDataWrite(user, programStage)) {
        TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1095).addArg(user).addArg(programStage).build(reporter.getValidationContext().getBundle());
        reporter.addError(error);
    }
}
Also used : TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 18 with TrackerErrorReport

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

the class TrackerTest method assertNoImportErrors.

protected void assertNoImportErrors(TrackerImportReport report) {
    List<TrackerErrorReport> errorReports = report.getValidationReport().getErrors();
    boolean empty = errorReports.isEmpty();
    if (!empty) {
        for (TrackerErrorReport errorReport : errorReports) {
            log.error("Import errors: " + errorReport.getErrorMessage());
        }
    }
    assertTrue(empty);
}
Also used : TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 19 with TrackerErrorReport

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

the class RelationshipsValidationHookTest method verifyValidationSuccessWhenSomeObjectsFailButNoParentObject.

@Test
void verifyValidationSuccessWhenSomeObjectsFailButNoParentObject() {
    RelationshipType relType = createRelTypeConstraint(TRACKED_ENTITY_INSTANCE, TRACKED_ENTITY_INSTANCE);
    when(preheat.getAll(RelationshipType.class)).thenReturn(Collections.singletonList(relType));
    reporter = new ValidationErrorReporter(ctx);
    Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity("validTrackedEntity").build()).to(RelationshipItem.builder().trackedEntity("anotherValidTrackedEntity").build()).relationshipType(relType.getUid()).build();
    TrackerErrorReport error = TrackerErrorReport.builder().uid("notValidTrackedEntity").trackerType(TRACKED_ENTITY).errorCode(TrackerErrorCode.E9999).build(bundle);
    reporter.addError(error);
    validationHook.validateRelationship(reporter, relationship);
    assertTrue(reporter.hasErrors());
    assertThat(reporter.getReportList().stream().map(TrackerErrorReport::getErrorCode).collect(Collectors.toList()), not(hasItem(TrackerErrorCode.E4011)));
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) Test(org.junit.jupiter.api.Test)

Example 20 with TrackerErrorReport

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

the class RelationshipsValidationHookTest method verifyValidationFailsWhenParentObjectFailed.

@Test
void verifyValidationFailsWhenParentObjectFailed() {
    RelationshipType relType = createRelTypeConstraint(TRACKED_ENTITY_INSTANCE, TRACKED_ENTITY_INSTANCE);
    when(preheat.getAll(RelationshipType.class)).thenReturn(Collections.singletonList(relType));
    reporter = new ValidationErrorReporter(ctx);
    Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity("validTrackedEntity").build()).to(RelationshipItem.builder().trackedEntity("notValidTrackedEntity").build()).relationshipType(relType.getUid()).build();
    TrackerErrorReport error = TrackerErrorReport.builder().uid(relationship.getTo().getTrackedEntity()).trackerType(TRACKED_ENTITY).errorCode(TrackerErrorCode.E9999).build(bundle);
    reporter.addError(error);
    validationHook.validateRelationship(reporter, relationship);
    hasTrackerError(reporter, TrackerErrorCode.E4011, RELATIONSHIP, relationship.getUid());
    assertThat(reporter.getReportList().stream().map(TrackerErrorReport::getErrorMessage).collect(Collectors.toList()), hasItem("Relationship: `" + relationship.getRelationship() + "` cannot be persisted because trackedEntity notValidTrackedEntity referenced by this relationship is not valid."));
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) Test(org.junit.jupiter.api.Test)

Aggregations

TrackerErrorReport (org.hisp.dhis.tracker.report.TrackerErrorReport)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)9 User (org.hisp.dhis.user.User)7 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)5 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)5 Relationship (org.hisp.dhis.tracker.domain.Relationship)4 CategoryOption (org.hisp.dhis.category.CategoryOption)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Program (org.hisp.dhis.program.Program)3 ProgramStage (org.hisp.dhis.program.ProgramStage)3 TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)3 Event (org.hisp.dhis.tracker.domain.Event)3 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)3 Test (org.junit.jupiter.api.Test)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Collectors (java.util.stream.Collectors)2 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 EventStatus (org.hisp.dhis.event.EventStatus)2 FeatureType (org.hisp.dhis.organisationunit.FeatureType)2 ProgramInstance (org.hisp.dhis.program.ProgramInstance)2