Search in sources :

Example 36 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class MembershipServiceTest method deleteAdminTest.

@Test
public void deleteAdminTest() {
    GroupingsServiceResult gsr;
    // usernameToDelete is not a superuser
    String usernameToDelete = users.get(9).getUsername();
    try {
        // user is not super user
        gsr = membershipService.deleteAdmin(usernameToDelete, ADMIN_USER);
    } catch (GroupingsServiceResultException gsre) {
        gsr = gsre.getGsr();
    }
    assertTrue(gsr.getResultCode().startsWith(FAILURE));
    // user is super user usernameToDelete is not superuser
    gsr = membershipService.deleteAdmin(ADMIN_USER, usernameToDelete);
    assertEquals(SUCCESS, gsr.getResultCode());
    // make usernameToDelete a superuser
    membershipService.addAdmin(ADMIN_USER, usernameToDelete);
    assertTrue(memberAttributeService.isAdmin(usernameToDelete));
    // user is super user usernameToDelete is not superuser
    gsr = membershipService.deleteAdmin(ADMIN_USER, usernameToDelete);
    assertEquals(SUCCESS, gsr.getResultCode());
}
Also used : GroupingsServiceResultException(edu.hawaii.its.api.type.GroupingsServiceResultException) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 37 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class TestGroupAttributeService method changeListServeStatusTest.

@Test
public void changeListServeStatusTest() {
    GroupingsServiceResult groupingsServiceResult;
    assertTrue(memberAttributeService.isOwner(GROUPING, username[0]));
    assertTrue(groupAttributeService.hasListserv(GROUPING));
    groupAttributeService.changeListservStatus(GROUPING, username[0], true);
    assertTrue(groupAttributeService.hasListserv(GROUPING));
    groupAttributeService.changeListservStatus(GROUPING, username[0], false);
    assertFalse(groupAttributeService.hasListserv(GROUPING));
    groupAttributeService.changeListservStatus(GROUPING, username[0], false);
    assertFalse(groupAttributeService.hasListserv(GROUPING));
    assertFalse(memberAttributeService.isOwner(GROUPING, username[1]));
    try {
        groupingsServiceResult = groupAttributeService.changeListservStatus(GROUPING, username[1], true);
    } catch (GroupingsServiceResultException gsre) {
        groupingsServiceResult = gsre.getGsr();
    }
    assertTrue(groupingsServiceResult.getResultCode().startsWith(FAILURE));
    assertFalse(groupAttributeService.hasListserv(GROUPING));
    groupAttributeService.changeListservStatus(GROUPING, username[0], true);
    assertTrue(groupAttributeService.hasListserv(GROUPING));
    try {
        groupingsServiceResult = groupAttributeService.changeListservStatus(GROUPING, username[1], false);
    } catch (GroupingsServiceResultException gsre) {
        groupingsServiceResult = gsre.getGsr();
    }
    assertTrue(groupingsServiceResult.getResultCode().startsWith(FAILURE));
    assertTrue(groupAttributeService.hasListserv(GROUPING));
}
Also used : GroupingsServiceResultException(edu.hawaii.its.api.type.GroupingsServiceResultException) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 38 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class TestMembershipService method addRemoveSelfOptedTest.

@Test
public void addRemoveSelfOptedTest() {
    // username[2] is not in the include, but not self opted
    assertTrue(memberAttributeService.isMember(GROUPING_INCLUDE, username[2]));
    assertFalse(memberAttributeService.isSelfOpted(GROUPING_INCLUDE, username[2]));
    // add the self opted attribute for username[2]'s membership for the include group
    membershipService.addSelfOpted(GROUPING_INCLUDE, username[2]);
    // username[2] should now be self opted
    assertTrue(memberAttributeService.isSelfOpted(GROUPING_INCLUDE, username[2]));
    // remove the self opted attribute for username[2]'s membership from the include group
    membershipService.removeSelfOpted(GROUPING_INCLUDE, username[2]);
    // username[2] should no longer be self opted into the include
    assertFalse(memberAttributeService.isSelfOpted(GROUPING_INCLUDE, username[2]));
    // try to add self opted attribute when not in the group
    GroupingsServiceResult groupingsServiceResult;
    try {
        groupingsServiceResult = membershipService.addSelfOpted(GROUPING_EXCLUDE, username[2]);
    } catch (GroupingsServiceResultException gsre) {
        groupingsServiceResult = gsre.getGsr();
    }
    assertTrue(groupingsServiceResult.getResultCode().startsWith(FAILURE));
    assertFalse(memberAttributeService.isSelfOpted(GROUPING_EXCLUDE, username[2]));
}
Also used : GroupingsServiceResultException(edu.hawaii.its.api.type.GroupingsServiceResultException) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 39 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class GroupingFactoryServiceImpl method addGrouping.

@Override
public // todo change basis to a String
List<GroupingsServiceResult> addGrouping(String adminUsername, String groupingPath, List<String> basis, List<String> include, List<String> exclude, List<String> owners) {
    List<GroupingsServiceResult> addGroupingResults = new ArrayList<>();
    String action = adminUsername + " is adding a Grouping: " + groupingPath;
    // make sure that adminUsername is actually an admin
    if (!memberAttributeService.isAdmin(adminUsername)) {
        GroupingsServiceResult gsr = helperService.makeGroupingsServiceResult(FAILURE + ": " + adminUsername + " does not have permission to add this grouping", action);
        addGroupingResults.add(gsr);
        return addGroupingResults;
    }
    // make sure that there is not already a group there
    if (!pathIsEmpty(adminUsername, groupingPath)) {
        GroupingsServiceResult gsr = helperService.makeGroupingsServiceResult(FAILURE + ": a group already exists at " + groupingPath, action);
        addGroupingResults.add(gsr);
        return addGroupingResults;
    }
    Map<String, List<String>> memberLists = new HashMap<>();
    memberLists.put("", new ArrayList<>());
    memberLists.put(BASIS_PLUS_INCLUDE, new ArrayList<>());
    memberLists.put(BASIS, new ArrayList<>());
    memberLists.put(INCLUDE, include);
    memberLists.put(EXCLUDE, exclude);
    memberLists.put(OWNERS, owners);
    // a stem the same as a folder
    // create main stem
    grouperFactoryService.makeWsStemSaveResults(adminUsername, groupingPath);
    // create basis stem
    grouperFactoryService.makeWsStemSaveResults(adminUsername, groupingPath + BASIS);
    for (Map.Entry<String, List<String>> entry : memberLists.entrySet()) {
        String groupPath = groupingPath + entry.getKey();
        // make the groups in grouper
        addGroupingResults.add(helperService.makeGroupingsServiceResult(grouperFactoryService.addEmptyGroup(adminUsername, groupPath), action));
        // add members to the groups
        addGroupingResults.addAll(membershipService.addGroupMembersByUsername(adminUsername, groupPath, entry.getValue()));
        if (groupingPath.equals(groupPath)) {
        // todo create is-trio attribute
        }
        // todo this needs to be created not updated
        // update the last modified values of those groups
        addGroupingResults.add(membershipService.updateLastModified(groupPath));
    }
    WsSubjectLookup lookup = grouperFactoryService.makeWsSubjectLookup(adminUsername);
    WsStemLookup stemLookup = grouperFactoryService.makeWsStemLookup(STEM);
    String basisUid = getGroupId(groupingPath + BASIS);
    String includeUid = getGroupId(groupingPath + INCLUDE);
    String excludeUid = getGroupId(groupingPath + EXCLUDE);
    String basisPlusIncludeUid = getGroupId(groupingPath + BASIS_PLUS_INCLUDE);
    // add memberships for BASIS_PLUS_INCLUDE (basis group and include group)
    addGroupingResults.add(helperService.makeGroupingsServiceResult(grouperFactoryService.makeWsAddMemberResultsGroup(groupingPath + BASIS_PLUS_INCLUDE, lookup, basisUid), "add " + groupingPath + BASIS + " to " + groupingPath + BASIS_PLUS_INCLUDE));
    addGroupingResults.add(helperService.makeGroupingsServiceResult(grouperFactoryService.makeWsAddMemberResultsGroup(groupingPath + BASIS_PLUS_INCLUDE, lookup, includeUid), "add " + groupingPath + INCLUDE + " to " + groupingPath + BASIS_PLUS_INCLUDE));
    // add members for the composite (basisPlusInclude group complement exclude group)
    addGroupingResults.add(helperService.makeGroupingsServiceResult(grouperFactoryService.makeWsAddMemberResultsGroup(groupingPath, lookup, basisPlusIncludeUid), "add " + groupingPath + BASIS_PLUS_INCLUDE + " to " + groupingPath));
    // todo do a complement
    // add the isTrio attribute to the grouping
    grouperFactoryService.makeWsAssignAttributesResultsForGroup(lookup, ASSIGN_TYPE_GROUP, OPERATION_ASSIGN_ATTRIBUTE, TRIO, groupingPath);
    return addGroupingResults;
}
Also used : WsSubjectLookup(edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup) WsStemLookup(edu.internet2.middleware.grouperClient.ws.beans.WsStemLookup) HashMap(java.util.HashMap) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 40 with GroupingsServiceResult

use of edu.hawaii.its.api.type.GroupingsServiceResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class HelperServiceImpl method makeGroupingsServiceResult.

// makes a groupingsServiceResult with the result code from the metadataHolder and the action string
@Override
public GroupingsServiceResult makeGroupingsServiceResult(ResultMetadataHolder resultMetadataHolder, String action) {
    GroupingsServiceResult groupingsServiceResult = new GroupingsServiceResult();
    groupingsServiceResult.setAction(action);
    groupingsServiceResult.setResultCode(resultMetadataHolder.getResultMetadata().getResultCode());
    if (groupingsServiceResult.getResultCode().startsWith(FAILURE)) {
        throw new GroupingsServiceResultException(groupingsServiceResult);
    }
    return groupingsServiceResult;
}
Also used : GroupingsServiceResultException(edu.hawaii.its.api.type.GroupingsServiceResultException) GroupingsServiceResult(edu.hawaii.its.api.type.GroupingsServiceResult)

Aggregations

GroupingsServiceResult (edu.hawaii.its.api.type.GroupingsServiceResult)43 Test (org.junit.Test)32 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)32 GroupingsServiceResultException (edu.hawaii.its.api.type.GroupingsServiceResultException)15 WithMockUhUser (edu.hawaii.its.groupings.controller.WithMockUhUser)15 ArrayList (java.util.ArrayList)15 Grouping (edu.hawaii.its.api.type.Grouping)6 WsSubjectLookup (edu.internet2.middleware.grouperClient.ws.beans.WsSubjectLookup)4 Person (edu.hawaii.its.api.type.Person)3 WsAddMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsAddMemberResults)3 WsDeleteMemberResults (edu.internet2.middleware.grouperClient.ws.beans.WsDeleteMemberResults)2 WsGetAttributeAssignmentsResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetAttributeAssignmentsResults)2 Group (edu.hawaii.its.api.type.Group)1 GroupingsHTTPException (edu.hawaii.its.api.type.GroupingsHTTPException)1 Membership (edu.hawaii.its.api.type.Membership)1 WsResultMeta (edu.internet2.middleware.grouperClient.ws.beans.WsResultMeta)1 WsStemLookup (edu.internet2.middleware.grouperClient.ws.beans.WsStemLookup)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1