use of org.hisp.dhis.tracker.domain.Attribute in project dhis2-core by dhis2.
the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentInTei.
@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentInTei() {
List<Enrollment> enrollments = Lists.newArrayList(getEnrollmentWithAttributeNOTSet());
List<TrackedEntity> trackedEntities = Lists.newArrayList(getTrackedEntitiesWithAttributeSet());
bundle.setEnrollments(enrollments);
bundle.setTrackedEntities(trackedEntities);
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();
TrackedEntity trackedEntity = bundle.getTrackedEntities().stream().filter(e -> e.getTrackedEntity().equals(TRACKED_ENTITY_ID)).findAny().get();
Optional<Attribute> enrollmentAttribute = enrollment.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
Optional<Attribute> teiAttribute = trackedEntity.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
assertFalse(enrollmentAttribute.isPresent());
assertTrue(teiAttribute.isPresent());
assertEquals(TEI_ATTRIBUTE_OLD_VALUE, teiAttribute.get().getValue());
assertEquals(1, enrollmentIssues.size());
assertEquals(1, enrollmentIssues.get(SECOND_ENROLLMENT_ID).size());
assertEquals(ERROR, enrollmentIssues.get(SECOND_ENROLLMENT_ID).get(0).getIssueType());
}
use of org.hisp.dhis.tracker.domain.Attribute in project dhis2-core by dhis2.
the class AssignValueImplementerTest method getAttributes.
private List<Attribute> getAttributes() {
Attribute attribute = new Attribute();
attribute.setAttribute(ATTRIBUTE_ID);
attribute.setValue(TEI_ATTRIBUTE_OLD_VALUE);
return Lists.newArrayList(attribute);
}
use of org.hisp.dhis.tracker.domain.Attribute 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.domain.Attribute 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.domain.Attribute in project dhis2-core by dhis2.
the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresent.
@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresent() {
List<Enrollment> enrollments = Lists.newArrayList(getEnrollmentWithAttributeSet());
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_OLD_VALUE, attribute.get().getValue());
assertEquals(1, enrollmentIssues.size());
assertEquals(1, enrollmentIssues.get(FIRST_ENROLLMENT_ID).size());
assertEquals(ERROR, enrollmentIssues.get(FIRST_ENROLLMENT_ID).get(0).getIssueType());
}
Aggregations