use of edu.hawaii.its.api.type.Person in project uhgroupings by uhawaii-system-its-ti-iam.
the class MemberAttributeServiceTest method isMemberTest.
@Test
public void isMemberTest() {
// test with username
Person person2 = users.get(2);
Person person5 = users.get(5);
assertFalse(memberAttributeService.isMember(GROUPING_0_PATH, person2));
assertTrue(memberAttributeService.isMember(GROUPING_0_PATH, person5));
// test with uuid
person2.setUsername(null);
person5.setUsername(null);
assertFalse(memberAttributeService.isMember(GROUPING_0_PATH, person2));
assertTrue(memberAttributeService.isMember(GROUPING_0_PATH, person5));
}
use of edu.hawaii.its.api.type.Person in project uhgroupings by uhawaii-system-its-ti-iam.
the class MemberAttributeServiceTest method checkSelfOptedTest.
@Test
public void checkSelfOptedTest() {
// user is not in group
boolean selfOpted = memberAttributeService.isSelfOpted(GROUPING_0_INCLUDE_PATH, users.get(2).getUsername());
assertFalse(selfOpted);
// user has not self opted
selfOpted = memberAttributeService.isSelfOpted(GROUPING_0_INCLUDE_PATH, users.get(5).getUsername());
assertFalse(selfOpted);
// user has self opted
Person person = personRepository.findByUsername(users.get(5).getUsername());
Group group = groupRepository.findByPath(GROUPING_0_INCLUDE_PATH);
Membership membership = membershipRepository.findByPersonAndGroup(person, group);
membership.setSelfOpted(true);
membershipRepository.save(membership);
selfOpted = memberAttributeService.isSelfOpted(GROUPING_0_INCLUDE_PATH, users.get(5).getUsername());
assertTrue(selfOpted);
}
use of edu.hawaii.its.api.type.Person in project uhgroupings by uhawaii-system-its-ti-iam.
the class MemberAttributeServiceTest method assignOwnershipTest.
@Test
public void assignOwnershipTest() {
// expect this to fail
GroupingsServiceResult randomUserAdds;
Person randomUser = personRepository.findByUsername(users.get(1).getUsername());
Grouping grouping = groupingRepository.findByPath(GROUPING_0_PATH);
assertFalse(grouping.getOwners().getMembers().contains(randomUser));
assertFalse(grouping.getOwners().isMember(randomUser));
try {
randomUserAdds = memberAttributeService.assignOwnership(GROUPING_0_PATH, randomUser.getUsername(), randomUser.getUsername());
} catch (GroupingsServiceResultException gsre) {
randomUserAdds = gsre.getGsr();
}
grouping = groupingRepository.findByPath(GROUPING_0_PATH);
assertFalse(grouping.getOwners().getMembers().contains(randomUser));
assertFalse(grouping.getOwners().isMember(randomUser));
assertNotEquals(randomUserAdds.getResultCode(), SUCCESS);
GroupingsServiceResult ownerAdds = memberAttributeService.assignOwnership(GROUPING_0_PATH, users.get(0).getUsername(), randomUser.getUsername());
grouping = groupingRepository.findByPath(GROUPING_0_PATH);
assertTrue(grouping.getOwners().getMembers().contains(randomUser));
assertTrue(grouping.getOwners().isMember(randomUser));
assertEquals(ownerAdds.getResultCode(), SUCCESS);
GroupingsServiceResult adminAdds = memberAttributeService.assignOwnership(GROUPING_0_PATH, ADMIN_USER, randomUser.getUsername());
grouping = groupingRepository.findByPath(GROUPING_0_PATH);
assertTrue(grouping.getOwners().getMembers().contains(randomUser));
assertTrue(grouping.getOwners().isMember(randomUser));
assertEquals(SUCCESS, adminAdds.getResultCode());
}
use of edu.hawaii.its.api.type.Person in project uhgroupings by uhawaii-system-its-ti-iam.
the class MembershipServiceTest method addMembersByUsername.
@Test
public void addMembersByUsername() {
// add all usernames
List<String> usernames = new ArrayList<>();
for (Person user : users) {
usernames.add(user.getUsername());
}
Grouping grouping = groupingRepository.findByPath(GROUPING_3_PATH);
// check how many members are in the basis
int numberOfBasisMembers = grouping.getBasis().getMembers().size();
// try to put all users into exclude group
membershipService.addGroupMembersByUsername(users.get(0).getUsername(), GROUPING_3_EXCLUDE_PATH, usernames);
grouping = groupingRepository.findByPath(GROUPING_3_PATH);
// there should be no real members in composite, but it should still have the 'grouperAll' member
assertEquals(1, grouping.getComposite().getMembers().size());
// only the users in the basis should have been added to the exclude group
assertEquals(numberOfBasisMembers, grouping.getExclude().getMembers().size());
// try to put all users into the include group
membershipService.addGroupMembersByUsername(users.get(0).getUsername(), GROUPING_3_INCLUDE_PATH, usernames);
grouping = groupingRepository.findByPath(GROUPING_3_PATH);
// all members should be in the group ( - 1 for 'grouperAll' in composite);
assertEquals(usernames.size(), grouping.getComposite().getMembers().size() - 1);
// members in basis should not have been added to the include group ( + 2 for 'grouperAll' in both groups)
assertEquals(usernames.size() - numberOfBasisMembers + 2, grouping.getInclude().getMembers().size());
}
use of edu.hawaii.its.api.type.Person in project uhgroupings by uhawaii-system-its-ti-iam.
the class GrouperFactoryServiceImplLocal method makeWsAddMemberResults.
@Override
public WsAddMemberResults makeWsAddMemberResults(String group, WsSubjectLookup lookup, Person personToAdd) {
Person newGroupMember;
WsAddMemberResults wsAddMemberResults = new WsAddMemberResults();
WsResultMeta wsResultMeta = new WsResultMeta();
wsResultMeta.setResultCode(SUCCESS);
wsAddMemberResults.setResultMetadata(wsResultMeta);
Grouping grouping = groupingRepository.findByIncludePathOrExcludePathOrCompositePathOrOwnersPath(group, group, group, group);
if (personToAdd.getUsername() != null) {
newGroupMember = personRepository.findByUsername(personToAdd.getUsername());
} else {
newGroupMember = personRepository.findByUuid(personToAdd.getUuid());
}
if (grouping == null) {
Group groupToAddTo = groupRepository.findByPath(group);
addMember(groupToAddTo, newGroupMember);
} else {
boolean inBasis = grouping.getBasis().isMember(newGroupMember);
boolean inExclude = grouping.getExclude().isMember(newGroupMember);
boolean inInclude = grouping.getInclude().isMember(newGroupMember);
if (group.endsWith(OWNERS)) {
addMember(grouping.getOwners(), newGroupMember);
} else if (group.endsWith(EXCLUDE)) {
if (inBasis) {
addMember(grouping.getExclude(), newGroupMember);
} else if (inInclude) {
deleteMember(grouping.getInclude(), newGroupMember);
}
} else if (group.endsWith(INCLUDE)) {
if (inExclude) {
deleteMember(grouping.getExclude(), newGroupMember);
} else if (!inBasis) {
addMember(grouping.getInclude(), newGroupMember);
}
}
grouping = groupingRepository.findByPath(grouping.getPath());
Group composite = buildComposite(grouping.getInclude(), grouping.getExclude(), grouping.getBasis(), grouping.getPath());
groupRepository.save(composite);
}
return wsAddMemberResults;
}
Aggregations