use of org.hisp.dhis.user.UserGroup 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.user.UserGroup 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());
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class DhisConvenienceTest method createUserGroup.
public static UserGroup createUserGroup(char uniqueCharacter, Set<User> users) {
UserGroup userGroup = new UserGroup();
userGroup.setAutoFields();
userGroup.setUid(BASE_USER_GROUP_UID + uniqueCharacter);
userGroup.setCode("UserGroupCode" + uniqueCharacter);
userGroup.setName("UserGroup" + uniqueCharacter);
userGroup.setMembers(users);
return userGroup;
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class ConfigurationController method setSystemUpdateNotificationRecipients.
@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@PostMapping("/systemUpdateNotificationRecipients")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setSystemUpdateNotificationRecipients(@RequestBody String uid) throws NotFoundException {
uid = trim(uid);
UserGroup group = identifiableObjectManager.get(UserGroup.class, uid);
if (group == null) {
throw new NotFoundException("User group", uid);
}
Configuration configuration = configurationService.getConfiguration();
configuration.setSystemUpdateNotificationRecipients(group);
configurationService.setConfiguration(configuration);
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class SharingController method getSharingUserGroups.
private List<SharingUserGroupAccess> getSharingUserGroups(@RequestParam String key, int max) {
List<SharingUserGroupAccess> sharingUserGroupAccesses = new ArrayList<>();
List<UserGroup> userGroups = userGroupService.getUserGroupsBetweenByName(key, 0, max);
for (UserGroup userGroup : userGroups) {
SharingUserGroupAccess sharingUserGroupAccess = new SharingUserGroupAccess();
sharingUserGroupAccess.setId(userGroup.getUid());
sharingUserGroupAccess.setName(userGroup.getDisplayName());
sharingUserGroupAccess.setDisplayName(userGroup.getDisplayName());
sharingUserGroupAccesses.add(sharingUserGroupAccess);
}
return sharingUserGroupAccesses;
}
Aggregations