use of org.hisp.dhis.tracker.programrule.IssueType.WARNING in project dhis2-core by dhis2.
the class AssignValueImplementerTest method testAssignDataElementValueForEventsWhenDataElementIsEmpty.
@Test
void testAssignDataElementValueForEventsWhenDataElementIsEmpty() {
List<Event> events = Lists.newArrayList(getEventWithDataValueNOTSet());
bundle.setEvents(events);
bundle.setRuleEffects(getRuleEventEffects(events));
Map<String, List<ProgramRuleIssue>> eventIssues = implementerToTest.validateEvents(bundle);
Event event = bundle.getEvents().stream().filter(e -> e.getEvent().equals(SECOND_EVENT_ID)).findAny().get();
Optional<DataValue> newDataValue = event.getDataValues().stream().filter(dv -> dv.getDataElement().equals(dataElementA.getUid())).findAny();
assertTrue(newDataValue.isPresent());
assertEquals(DATA_ELEMENT_NEW_VALUE, newDataValue.get().getValue());
assertEquals(1, eventIssues.size());
assertEquals(1, eventIssues.get(SECOND_EVENT_ID).size());
assertEquals(WARNING, eventIssues.get(SECOND_EVENT_ID).get(0).getIssueType());
}
use of org.hisp.dhis.tracker.programrule.IssueType.WARNING in project dhis2-core by dhis2.
the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsEmpty.
@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsEmpty() {
List<TrackedEntity> trackedEntities = Lists.newArrayList(getTrackedEntitiesWithAttributeNOTSet());
List<Enrollment> enrollments = Lists.newArrayList(getEnrollmentWithAttributeNOTSet());
bundle.setTrackedEntities(trackedEntities);
bundle.setEnrollments(enrollments);
bundle.setRuleEffects(getRuleEnrollmentEffects(enrollments));
Map<String, List<ProgramRuleIssue>> enrollmentIssues = implementerToTest.validateEnrollments(bundle);
Enrollment enrollment = bundle.getEnrollments().stream().filter(e -> e.getEnrollment().equals(SECOND_ENROLLMENT_ID)).findAny().get();
Optional<Attribute> attribute = enrollment.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
assertTrue(attribute.isPresent());
assertEquals(TEI_ATTRIBUTE_NEW_VALUE, attribute.get().getValue());
assertEquals(1, enrollmentIssues.size());
assertEquals(1, enrollmentIssues.get(SECOND_ENROLLMENT_ID).size());
assertEquals(WARNING, enrollmentIssues.get(SECOND_ENROLLMENT_ID).get(0).getIssueType());
}
use of org.hisp.dhis.tracker.programrule.IssueType.WARNING in project dhis2-core by dhis2.
the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentAndSystemSettingToOverwriteIsTrue.
@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentAndSystemSettingToOverwriteIsTrue() {
List<Enrollment> enrollments = Lists.newArrayList(getEnrollmentWithAttributeSet());
bundle.setEnrollments(enrollments);
bundle.setRuleEffects(getRuleEnrollmentEffects(enrollments));
when(systemSettingManager.getBooleanSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE)).thenReturn(Boolean.TRUE);
Map<String, List<ProgramRuleIssue>> enrollmentIssues = implementerToTest.validateEnrollments(bundle);
Enrollment enrollment = bundle.getEnrollments().stream().filter(e -> e.getEnrollment().equals(FIRST_ENROLLMENT_ID)).findAny().get();
Optional<Attribute> attribute = enrollment.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
assertTrue(attribute.isPresent());
assertEquals(TEI_ATTRIBUTE_NEW_VALUE, attribute.get().getValue());
assertEquals(1, enrollmentIssues.size());
assertEquals(1, enrollmentIssues.get(FIRST_ENROLLMENT_ID).size());
assertEquals(WARNING, enrollmentIssues.get(FIRST_ENROLLMENT_ID).get(0).getIssueType());
}
use of org.hisp.dhis.tracker.programrule.IssueType.WARNING 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.IssueType.WARNING in project dhis2-core by dhis2.
the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentAndHasTheSameValue.
@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentAndHasTheSameValue() {
List<Enrollment> enrollments = Lists.newArrayList(getEnrollmentWithAttributeSetSameValue());
bundle.setEnrollments(enrollments);
bundle.setRuleEffects(getRuleEnrollmentEffects(enrollments));
Map<String, List<ProgramRuleIssue>> enrollmentIssues = implementerToTest.validateEnrollments(bundle);
Enrollment enrollment = bundle.getEnrollments().stream().filter(e -> e.getEnrollment().equals(FIRST_ENROLLMENT_ID)).findAny().get();
Optional<Attribute> attribute = enrollment.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
assertTrue(attribute.isPresent());
assertEquals(TEI_ATTRIBUTE_NEW_VALUE, attribute.get().getValue());
assertEquals(1, enrollmentIssues.size());
assertEquals(1, enrollmentIssues.get(FIRST_ENROLLMENT_ID).size());
assertEquals(WARNING, enrollmentIssues.get(FIRST_ENROLLMENT_ID).get(0).getIssueType());
}
Aggregations