use of org.hisp.dhis.tracker.programrule.ProgramRuleIssue in project dhis2-core by dhis2.
the class AssignValueImplementer method applyToEnrollments.
@Override
public List<ProgramRuleIssue> applyToEnrollments(Map.Entry<String, List<EnrollmentActionRule>> enrollmentActionRules, TrackerBundle bundle) {
List<ProgramRuleIssue> issues = Lists.newArrayList();
Boolean canOverwrite = systemSettingManager.getBooleanSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE);
for (EnrollmentActionRule actionRule : enrollmentActionRules.getValue()) {
if (!actionRule.getAttribute().isPresent() || Boolean.TRUE.equals(canOverwrite) || isTheSameValue(actionRule, bundle.getPreheat())) {
addOrOverwriteAttribute(actionRule, bundle);
issues.add(new ProgramRuleIssue(actionRule.getRuleUid(), TrackerErrorCode.E1310, Lists.newArrayList(actionRule.getField(), actionRule.getValue()), IssueType.WARNING));
} else {
issues.add(new ProgramRuleIssue(actionRule.getRuleUid(), TrackerErrorCode.E1309, Lists.newArrayList(actionRule.getField(), actionRule.getEnrollment()), IssueType.ERROR));
}
}
return issues;
}
use of org.hisp.dhis.tracker.programrule.ProgramRuleIssue 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.programrule.ProgramRuleIssue in project dhis2-core by dhis2.
the class EventRuleValidationHook method validateEvent.
@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
TrackerImportValidationContext context = reporter.getValidationContext();
List<ProgramRuleIssue> programRuleIssues = validators.stream().flatMap(v -> v.validateEvents(context.getBundle()).getOrDefault(event.getEvent(), Lists.newArrayList()).stream()).collect(Collectors.toList());
addIssuesToReporter(reporter, event, programRuleIssues);
}
use of org.hisp.dhis.tracker.programrule.ProgramRuleIssue in project dhis2-core by dhis2.
the class EnrollmentRuleValidationHook method validateEnrollment.
@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
TrackerImportValidationContext context = reporter.getValidationContext();
List<ProgramRuleIssue> programRuleIssues = validators.stream().flatMap(v -> v.validateEnrollments(context.getBundle()).getOrDefault(enrollment.getEnrollment(), Lists.newArrayList()).stream()).collect(Collectors.toList());
addIssuesToReporter(reporter, enrollment, programRuleIssues);
}
use of org.hisp.dhis.tracker.programrule.ProgramRuleIssue in project dhis2-core by dhis2.
the class AssignValueImplementer method applyToEvents.
@Override
public List<ProgramRuleIssue> applyToEvents(Map.Entry<String, List<EventActionRule>> eventClasses, TrackerBundle bundle) {
List<ProgramRuleIssue> issues = Lists.newArrayList();
Boolean canOverwrite = systemSettingManager.getBooleanSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE);
for (EventActionRule actionRule : eventClasses.getValue()) {
if (!actionRule.getDataValue().isPresent() || Boolean.TRUE.equals(canOverwrite) || isTheSameValue(actionRule, bundle.getPreheat())) {
addOrOverwriteDataValue(actionRule, bundle);
issues.add(new ProgramRuleIssue(actionRule.getRuleUid(), TrackerErrorCode.E1308, Lists.newArrayList(actionRule.getField(), actionRule.getEvent()), IssueType.WARNING));
} else {
issues.add(new ProgramRuleIssue(actionRule.getRuleUid(), TrackerErrorCode.E1307, Lists.newArrayList(actionRule.getField(), actionRule.getValue()), IssueType.ERROR));
}
}
return issues;
}
Aggregations