use of org.hisp.dhis.tracker.report.TrackerErrorReport in project dhis2-core by dhis2.
the class AttributeValidationHook method validateAttrValueType.
protected void validateAttrValueType(ValidationErrorReporter errorReporter, TrackerDto dto, Attribute attr, TrackedEntityAttribute teAttr) {
checkNotNull(attr, ATTRIBUTE_CANT_BE_NULL);
checkNotNull(teAttr, TRACKED_ENTITY_ATTRIBUTE_CANT_BE_NULL);
ValueType valueType = teAttr.getValueType();
TrackerImportValidationContext context = errorReporter.getValidationContext();
String error;
if (valueType.equals(ValueType.ORGANISATION_UNIT)) {
error = context.getOrganisationUnit(attr.getValue()) == null ? " Value " + attr.getValue() + " is not a valid org unit value" : null;
} else if (valueType.equals(ValueType.USERNAME)) {
error = context.usernameExists(attr.getValue()) ? null : " Value " + attr.getValue() + " is not a valid username value";
} else {
// org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:945)
try {
error = teAttrService.validateValueType(teAttr, attr.getValue());
} catch (Exception e) {
error = e.getMessage();
}
}
if (error != null) {
TrackerBundle bundle = context.getBundle();
TrackerErrorReport err = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1007).addArg(valueType.toString()).addArg(error).build(bundle);
errorReporter.addError(err);
}
}
use of org.hisp.dhis.tracker.report.TrackerErrorReport in project dhis2-core by dhis2.
the class ReportSummaryDeleteIntegrationTest method testNonExistentEnrollment.
@Test
void testNonExistentEnrollment() throws IOException {
TrackerImportParams params = fromJson("tracker/non_existent_enrollment_basic_data_for_deletion.json");
params.setImportStrategy(TrackerImportStrategy.DELETE);
TrackerImportReport importReport = trackerImportService.importTracker(params);
assertEquals(TrackerStatus.ERROR, importReport.getStatus());
assertTrue(importReport.getValidationReport().hasErrors());
List<TrackerErrorReport> trackerErrorReports = importReport.getValidationReport().getErrors();
assertEquals(TrackerErrorCode.E1081, trackerErrorReports.get(0).getErrorCode());
}
use of org.hisp.dhis.tracker.report.TrackerErrorReport in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHook method checkProgramReadAccess.
private void checkProgramReadAccess(ValidationErrorReporter reporter, TrackerDto dto, User user, Program program) {
checkNotNull(user, USER_CANT_BE_NULL);
checkNotNull(program, PROGRAM_CANT_BE_NULL);
if (!aclService.canDataRead(user, program)) {
TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1096).addArg(user).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 validateEnrollment.
@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
TrackerImportValidationContext context = reporter.getValidationContext();
TrackerImportStrategy strategy = context.getStrategy(enrollment);
TrackerBundle bundle = context.getBundle();
User user = bundle.getUser();
Program program = strategy.isUpdateOrDelete() ? context.getProgramInstance(enrollment.getEnrollment()).getProgram() : context.getProgram(enrollment.getProgram());
OrganisationUnit ownerOrgUnit = context.getOwnerOrganisationUnit(enrollment.getTrackedEntity(), enrollment.getProgram());
checkNotNull(user, USER_CANT_BE_NULL);
checkNotNull(enrollment, ENROLLMENT_CANT_BE_NULL);
checkNotNull(program, PROGRAM_CANT_BE_NULL);
checkEnrollmentOrgUnit(reporter, context, strategy, enrollment, program);
if (strategy.isDelete()) {
boolean hasNonDeletedEvents = context.programInstanceHasEvents(enrollment.getEnrollment());
boolean hasNotCascadeDeleteAuthority = !user.isAuthorized(Authorities.F_ENROLLMENT_CASCADE_DELETE.getAuthority());
if (hasNonDeletedEvents && hasNotCascadeDeleteAuthority) {
TrackerErrorReport error = TrackerErrorReport.builder().uid(enrollment.getUid()).trackerType(TrackerType.ENROLLMENT).errorCode(E1103).addArg(user).addArg(enrollment.getEnrollment()).build(bundle);
reporter.addError(error);
}
}
checkWriteEnrollmentAccess(reporter, enrollment, program, context, ownerOrgUnit);
}
use of org.hisp.dhis.tracker.report.TrackerErrorReport in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHook method checkOrgUnitInSearchScope.
private void checkOrgUnitInSearchScope(ValidationErrorReporter reporter, TrackerDto dto, OrganisationUnit orgUnit) {
TrackerBundle bundle = reporter.getValidationContext().getBundle();
User user = bundle.getUser();
checkNotNull(user, USER_CANT_BE_NULL);
checkNotNull(orgUnit, ORGANISATION_UNIT_CANT_BE_NULL);
if (!organisationUnitService.isInUserSearchHierarchyCached(user, orgUnit)) {
TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(TrackerErrorCode.E1003).addArg(orgUnit).addArg(user).build(reporter.getValidationContext().getBundle());
reporter.addError(error);
}
}
Aggregations