use of org.hisp.dhis.validation.notification.ValidationNotificationTemplate in project dhis2-core by dhis2.
the class ValidationRuleStoreTest method testGetValidationRulesWithNotificationTemplates.
@Test
public void testGetValidationRulesWithNotificationTemplates() {
// Setup
ValidationRule validationRuleA = createValidationRule('A', equal_to, expressionA, expressionB, periodType);
ValidationRule validationRuleB = createValidationRule('B', equal_to, expressionA, expressionB, periodType);
validationRuleStore.save(validationRuleA);
validationRuleStore.save(validationRuleB);
// Test empty
List<ValidationRule> rules = validationRuleStore.getValidationRulesWithNotificationTemplates();
assertEquals(0, rules.size());
// Add template
ValidationNotificationTemplate template = createValidationNotificationTemplate("Template A");
template.addValidationRule(validationRuleA);
idObjectManager.save(template);
rules = validationRuleStore.getValidationRulesWithNotificationTemplates();
assertEquals(1, rules.size());
// Add one more
template.addValidationRule(validationRuleB);
idObjectManager.update(template);
rules = validationRuleStore.getValidationRulesWithNotificationTemplates();
assertEquals(2, rules.size());
assertTrue(rules.containsAll(Sets.newHashSet(validationRuleA, validationRuleB)));
}
use of org.hisp.dhis.validation.notification.ValidationNotificationTemplate in project dhis2-core by dhis2.
the class DhisConvenienceTest method createValidationNotificationTemplate.
public static ValidationNotificationTemplate createValidationNotificationTemplate(String name) {
ValidationNotificationTemplate template = new ValidationNotificationTemplate();
template.setAutoFields();
template.setName(name);
template.setSubjectTemplate("Subject");
template.setMessageTemplate("Message");
template.setNotifyUsersInHierarchyOnly(false);
return template;
}
use of org.hisp.dhis.validation.notification.ValidationNotificationTemplate in project dhis2-core by dhis2.
the class ValidationNotificationServiceTest method setUpEntitiesA.
private void setUpEntitiesA() {
User userA = createUser('A');
orgUnitA = createOrganisationUnit('A');
orgUnitA.addUser(userA);
userGroupA = createUserGroup('A', Sets.newHashSet(userA));
userA.setGroups(Sets.newHashSet(userGroupA));
valRuleA = createValidationRule('A', Operator.equal_to, createExpression2('A', "X"), createExpression2('B', "Y"), PeriodType.getPeriodTypeByName(QuarterlyPeriodType.NAME));
ValidationNotificationTemplate templateA = createValidationNotificationTemplate("Template A");
templateA.addValidationRule(valRuleA);
templateA.setRecipientUserGroups(Sets.newHashSet(userGroupA));
}
use of org.hisp.dhis.validation.notification.ValidationNotificationTemplate in project dhis2-core by dhis2.
the class ValidationNotificationServiceTest method testNotifyUsersInHierarchyLimitsRecipients.
@Test
void testNotifyUsersInHierarchyLimitsRecipients() {
// Complicated fixtures. Sorry to whomever has to read this...
// Org units
OrganisationUnit root = createOrganisationUnit('R'), lvlOneLeft = createOrganisationUnit('1'), lvlOneRight = createOrganisationUnit('2'), lvlTwoLeftLeft = createOrganisationUnit('3'), lvlTwoLeftRight = createOrganisationUnit('4');
configureHierarchy(root, lvlOneLeft, lvlOneRight, lvlTwoLeftLeft, lvlTwoLeftRight);
// Users
User uA = createUser('A'), uB = createUser('B'), uC = createUser('C'), uD = createUser('D'), uE = createUser('E'), uF = createUser('F'), uG = createUser('G');
root.addUser(uA);
lvlOneLeft.addUser(uB);
lvlOneLeft.addUser(uC);
lvlOneRight.addUser(uD);
lvlOneRight.addUser(uE);
lvlTwoLeftLeft.addUser(uF);
lvlTwoLeftRight.addUser(uG);
// User groups
UserGroup ugA = createUserGroup('A', Sets.newHashSet());
ugA.addUser(uB);
ugA.addUser(uC);
ugA.addUser(uD);
ugA.addUser(uE);
ugA.addUser(uF);
ugA.addUser(uG);
UserGroup ugB = createUserGroup('B', Sets.newHashSet());
ugB.addUser(uA);
// Validation rule and template
ValidationRule rule = createValidationRule('V', Operator.equal_to, createExpression2('A', "X"), createExpression2('B', "Y"), PeriodType.getPeriodTypeByName(QuarterlyPeriodType.NAME));
ValidationNotificationTemplate template = createValidationNotificationTemplate("My fancy template");
template.setNotifyUsersInHierarchyOnly(true);
template.addValidationRule(rule);
template.setRecipientUserGroups(Sets.newHashSet(ugA));
// Create a validationResult that emanates from the middle of the left
// branch
final ValidationResult resultFromMiddleLeft = createValidationResult(lvlOneLeft, rule);
// Perform tests
// One
subject.sendNotifications(Sets.newHashSet(resultFromMiddleLeft));
assertEquals(1, sentMessages.size());
Collection<User> rcpt = sentMessages.iterator().next().recipients;
assertEquals(2, rcpt.size());
assertTrue(rcpt.containsAll(Sets.newHashSet(uB, uC)));
// Two
sentMessages = new ArrayList<>();
// Add the second group (with user F) to the recipients
template.getRecipientUserGroups().add(ugB);
subject.sendNotifications(Sets.newHashSet(resultFromMiddleLeft));
assertEquals(1, sentMessages.size());
rcpt = sentMessages.iterator().next().recipients;
// We now expect user A, which is on the root org unit and in group B to
// also be among the recipients
assertEquals(3, rcpt.size());
assertTrue(rcpt.containsAll(Sets.newHashSet(uA, uB, uC)));
// Three
sentMessages = new ArrayList<>();
// Keep the hierarchy as is, but spread out the validation result from
// the bottom left of the tree
final ValidationResult resultFromBottomLeft = createValidationResult(lvlTwoLeftLeft, rule);
subject.sendNotifications(Sets.newHashSet(resultFromBottomLeft));
assertEquals(1, sentMessages.size());
rcpt = sentMessages.iterator().next().recipients;
assertEquals(4, rcpt.size());
assertTrue(rcpt.containsAll(Sets.newHashSet(uA, uB, uC, uF)));
}
use of org.hisp.dhis.validation.notification.ValidationNotificationTemplate in project dhis2-core by dhis2.
the class ValidationNotificationServiceTest method testNotifyParentOfUserInGroup.
@Test
void testNotifyParentOfUserInGroup() {
OrganisationUnit root = createOrganisationUnit('R'), lvlOneLeft = createOrganisationUnit('1'), lvlOneRight = createOrganisationUnit('2'), lvlTwoLeftLeft = createOrganisationUnit('3'), lvlTwoLeftRight = createOrganisationUnit('4');
configureHierarchy(root, lvlOneLeft, lvlOneRight, lvlTwoLeftLeft, lvlTwoLeftRight);
// Users
User uB = createUser('B'), uC = createUser('C'), uD = createUser('D'), uE = createUser('E');
UserGroup groupA = createUserGroup('A', Sets.newHashSet());
groupA.addUser(uD);
groupA.addUser(uE);
lvlOneLeft.addUser(uB);
lvlOneRight.addUser(uC);
lvlTwoLeftLeft.addUser(uD);
lvlTwoLeftRight.addUser(uE);
ValidationRule rule = createValidationRule('V', Operator.equal_to, createExpression2('A', "X"), createExpression2('B', "Y"), PeriodType.getPeriodTypeByName(QuarterlyPeriodType.NAME));
ValidationNotificationTemplate template = createValidationNotificationTemplate("My fancy template");
template.setNotifyParentOrganisationUnitOnly(true);
template.addValidationRule(rule);
template.setRecipientUserGroups(Sets.newHashSet(groupA));
final ValidationResult validationResult = createValidationResult(lvlOneLeft, rule);
subject.sendNotifications(Sets.newHashSet(validationResult));
assertEquals(1, sentMessages.size());
Collection<User> rcpt = sentMessages.iterator().next().recipients;
assertEquals(1, rcpt.size());
}
Aggregations