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