use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class EnrollmentGeoValidationHookTest method testProgramWithFeatureTypeDifferentFromGeometryFails.
@Test
void testProgramWithFeatureTypeDifferentFromGeometryFails() {
// given
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(CodeGenerator.generateUid());
enrollment.setProgram(PROGRAM);
enrollment.setGeometry(new GeometryFactory().createPoint());
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
// when
Program program = new Program();
program.setFeatureType(FeatureType.MULTI_POLYGON);
when(validationContext.getProgram(PROGRAM)).thenReturn(program);
this.hookToTest.validateEnrollment(reporter, enrollment);
// then
hasTrackerError(reporter, E1012, ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter 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.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class ValidationUtils method addIssuesToReporter.
public static void addIssuesToReporter(ValidationErrorReporter reporter, TrackerDto dto, List<ProgramRuleIssue> programRuleIssues) {
programRuleIssues.stream().filter(issue -> issue.getIssueType().equals(ERROR)).forEach(issue -> {
List<String> args = Lists.newArrayList(issue.getRuleUid());
args.addAll(issue.getArgs());
TrackerErrorReport error = TrackerErrorReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).errorCode(issue.getIssueCode()).addArgs(args.toArray()).build(reporter.getValidationContext().getBundle());
reporter.addError(error);
});
programRuleIssues.stream().filter(issue -> issue.getIssueType().equals(WARNING)).forEach(issue -> {
List<String> args = Lists.newArrayList(issue.getRuleUid());
args.addAll(issue.getArgs());
TrackerWarningReport warning = TrackerWarningReport.builder().uid(dto.getUid()).trackerType(dto.getTrackerType()).warningCode(issue.getIssueCode()).addArgs(args.toArray()).build(reporter.getValidationContext().getBundle());
reporter.addWarning(warning);
});
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class RepeatedEventsValidationHook method validate.
@Override
public void validate(ValidationErrorReporter reporter, TrackerImportValidationContext context) {
TrackerBundle bundle = context.getBundle();
Map<Pair<String, String>, List<Event>> eventsByEnrollmentAndNotRepeatableProgramStage = bundle.getEvents().stream().filter(e -> !reporter.isInvalid(e)).filter(e -> !context.getStrategy(e).isDelete()).filter(e -> {
ProgramStage programStage = context.getProgramStage(e.getProgramStage());
return programStage.getProgram().isRegistration() && !programStage.getRepeatable();
}).collect(Collectors.groupingBy(e -> Pair.of(e.getProgramStage(), e.getEnrollment())));
for (Map.Entry<Pair<String, String>, List<Event>> mapEntry : eventsByEnrollmentAndNotRepeatableProgramStage.entrySet()) {
if (mapEntry.getValue().size() > 1) {
for (Event event : mapEntry.getValue()) {
reporter.addError(event, TrackerErrorCode.E1039, mapEntry.getKey().getLeft());
}
}
}
bundle.getEvents().forEach(e -> validateNotMultipleEvents(reporter, context, e));
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class EventDataValuesValidationHook method validateMandatoryDataValues.
private void validateMandatoryDataValues(Event event, TrackerImportValidationContext context, ValidationErrorReporter reporter) {
if (StringUtils.isNotEmpty(event.getProgramStage())) {
ProgramStage programStage = context.getProgramStage(event.getProgramStage());
final List<String> mandatoryDataElements = programStage.getProgramStageDataElements().stream().filter(ProgramStageDataElement::isCompulsory).map(de -> context.getIdentifiers().getDataElementIdScheme().getIdentifier(de.getDataElement())).collect(Collectors.toList());
List<String> missingDataValue = validateMandatoryDataValue(programStage, event, mandatoryDataElements);
missingDataValue.forEach(de -> reporter.addError(event, E1303, de));
}
}
Aggregations