Search in sources :

Example 26 with Group

use of org.orcid.jaxb.model.record_v2.Group in project oxTrust by GluuFederation.

the class BulkWebService method processGroupOperation.

private BulkOperation processGroupOperation(BulkOperation operation, Map<String, String> processedBulkIds) throws Exception {
    log.info(" Operation is for Group ");
    // Intercept bulkId
    Group group = null;
    if (operation.getData() != null) {
        // Required in a request when
        // "method" is "POST", "PUT", or
        // "PATCH".
        String serializedData = serialize(operation.getData());
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            serializedData = serializedData.replaceAll(key, entry.getValue());
        }
        group = deserializeToGroup(serializedData);
    }
    String groupRootEndpoint = appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/";
    if (operation.getMethod().equalsIgnoreCase(HttpMethod.POST)) {
        log.info(" Method is POST ");
        try {
            group = scim2GroupService.createGroup(group);
            GluuGroup gluuGroup = groupService.getGroupByDisplayName(group.getDisplayName());
            String id = gluuGroup.getInum();
            // String location = (new
            // StringBuilder()).append(domain).append("/Groups/").append(id).toString();
            String location = groupRootEndpoint + id;
            operation.setLocation(location);
            operation.setStatus(String.valueOf(Response.Status.CREATED.getStatusCode()));
            operation.setResponse(group);
            // Set aside successfully-processed bulkId
            // bulkId is only required in POST
            processedBulkIds.put(operation.getBulkId(), group.getId());
        } catch (DuplicateEntryException ex) {
            log.error("DuplicateEntryException", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
        } catch (Exception ex) {
            log.error("Failed to create group", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    } else if (operation.getMethod().equalsIgnoreCase(HttpMethod.PUT)) {
        log.info(" Method is PUT ");
        String path = operation.getPath();
        String id = getId(path);
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            if (id.equalsIgnoreCase(key)) {
                id = id.replaceAll(key, entry.getValue());
                break;
            }
        }
        try {
            group = scim2GroupService.updateGroup(id, group);
            // String location = (new
            // StringBuilder()).append(domain).append("/Groups/").append(groupiD).toString();
            String location = groupRootEndpoint + id;
            operation.setLocation(location);
            operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
            operation.setResponse(group);
            // bulkId is only required in POST
            if (operation.getBulkId() != null) {
                processedBulkIds.put(operation.getBulkId(), group.getId());
            }
        } catch (EntryPersistenceException ex) {
            log.error("Failed to update group", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource " + id + " not found"));
        } catch (DuplicateEntryException ex) {
            log.error("DuplicateEntryException", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.CONFLICT.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.CONFLICT, ErrorScimType.UNIQUENESS, ex.getMessage()));
        } catch (Exception ex) {
            log.error("Failed to update group", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    } else if (operation.getMethod().equalsIgnoreCase(HttpMethod.DELETE)) {
        log.info(" Method is DELETE ");
        String path = operation.getPath();
        String id = getId(path);
        for (Map.Entry<String, String> entry : processedBulkIds.entrySet()) {
            String key = "bulkId:" + entry.getKey();
            if (id.equalsIgnoreCase(key)) {
                id = id.replaceAll(key, entry.getValue());
                break;
            }
        }
        try {
            scim2GroupService.deleteGroup(id);
            // Location may be omitted on DELETE
            operation.setStatus(String.valueOf(Response.Status.OK.getStatusCode()));
            operation.setResponse("Group " + id + " deleted");
            // bulkId is only required in POST
            if (operation.getBulkId() != null) {
                processedBulkIds.put(operation.getBulkId(), id);
            }
        } catch (EntryPersistenceException ex) {
            log.error("Failed to delete group", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.NOT_FOUND.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.NOT_FOUND, null, "Resource " + id + " not found"));
        } catch (Exception ex) {
            log.error("Failed to delete group", ex);
            ex.printStackTrace();
            operation.setStatus(String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
            operation.setResponse(createErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, null, INTERNAL_SERVER_ERROR_MESSAGE));
        }
    }
    return operation;
}
Also used : GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) GluuGroup(org.gluu.oxtrust.model.GluuGroup) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException)

Example 27 with Group

use of org.orcid.jaxb.model.record_v2.Group in project oxTrust by GluuFederation.

the class GroupCoreLoadingStrategy method createDummyGroup.

private Group createDummyGroup() {
    Group group = new Group();
    group.setId("");
    group.setExternalId("");
    group.setDisplayName("");
    Set<MemberRef> members = new HashSet<MemberRef>();
    MemberRef memberRef = new MemberRef();
    memberRef.setOperation("");
    memberRef.setPrimary(false);
    memberRef.setValue("test");
    memberRef.setDisplay("");
    memberRef.setType(MemberRef.Type.USER);
    memberRef.setReference("");
    members.add(memberRef);
    group.setMembers(members);
    return group;
}
Also used : Group(org.gluu.oxtrust.model.scim2.Group) MemberRef(org.gluu.oxtrust.model.scim2.MemberRef) HashSet(java.util.HashSet)

Example 28 with Group

use of org.orcid.jaxb.model.record_v2.Group in project google-cloud-java by GoogleCloudPlatform.

the class GroupServiceClientTest method createGroupTest.

@Test
@SuppressWarnings("all")
public void createGroupTest() {
    GroupName name2 = GroupName.create("[PROJECT]", "[GROUP]");
    String displayName = "displayName1615086568";
    GroupName parentName = GroupName.create("[PROJECT]", "[GROUP]");
    String filter = "filter-1274492040";
    boolean isCluster = false;
    Group expectedResponse = Group.newBuilder().setNameWithGroupName(name2).setDisplayName(displayName).setParentNameWithGroupName(parentName).setFilter(filter).setIsCluster(isCluster).build();
    mockGroupService.addResponse(expectedResponse);
    ProjectName name = ProjectName.create("[PROJECT]");
    Group group = Group.newBuilder().build();
    Group actualResponse = client.createGroup(name, group);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockGroupService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateGroupRequest actualRequest = (CreateGroupRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsProjectName());
    Assert.assertEquals(group, actualRequest.getGroup());
}
Also used : GroupName(com.google.monitoring.v3.GroupName) Group(com.google.monitoring.v3.Group) ProjectName(com.google.monitoring.v3.ProjectName) CreateGroupRequest(com.google.monitoring.v3.CreateGroupRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 29 with Group

use of org.orcid.jaxb.model.record_v2.Group in project google-cloud-java by GoogleCloudPlatform.

the class GroupServiceClientTest method updateGroupTest.

@Test
@SuppressWarnings("all")
public void updateGroupTest() {
    GroupName name = GroupName.create("[PROJECT]", "[GROUP]");
    String displayName = "displayName1615086568";
    GroupName parentName = GroupName.create("[PROJECT]", "[GROUP]");
    String filter = "filter-1274492040";
    boolean isCluster = false;
    Group expectedResponse = Group.newBuilder().setNameWithGroupName(name).setDisplayName(displayName).setParentNameWithGroupName(parentName).setFilter(filter).setIsCluster(isCluster).build();
    mockGroupService.addResponse(expectedResponse);
    Group group = Group.newBuilder().build();
    Group actualResponse = client.updateGroup(group);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockGroupService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateGroupRequest actualRequest = (UpdateGroupRequest) actualRequests.get(0);
    Assert.assertEquals(group, actualRequest.getGroup());
}
Also used : GroupName(com.google.monitoring.v3.GroupName) Group(com.google.monitoring.v3.Group) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) UpdateGroupRequest(com.google.monitoring.v3.UpdateGroupRequest) Test(org.junit.Test)

Example 30 with Group

use of org.orcid.jaxb.model.record_v2.Group in project google-cloud-java by GoogleCloudPlatform.

the class GroupServiceClientTest method createGroupExceptionTest.

@Test
@SuppressWarnings("all")
public void createGroupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockGroupService.addException(exception);
    try {
        ProjectName name = ProjectName.create("[PROJECT]");
        Group group = Group.newBuilder().build();
        client.createGroup(name, group);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : Group(com.google.monitoring.v3.Group) ProjectName(com.google.monitoring.v3.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)24 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)19 ArrayList (java.util.ArrayList)14 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)14 WorkGroup (org.orcid.jaxb.model.record.summary_v2.WorkGroup)13 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)11 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)10 Group (org.gluu.oxtrust.model.scim2.Group)9 Url (org.orcid.jaxb.model.common_v2.Url)9 GluuGroup (org.gluu.oxtrust.model.GluuGroup)8 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)8 Group (org.openstack4j.model.identity.v3.Group)8 ClientResponse (com.sun.jersey.api.client.ClientResponse)7 Response (javax.ws.rs.core.Response)7 FundingGroup (org.orcid.jaxb.model.record.summary_v2.FundingGroup)7 GroupAble (org.orcid.jaxb.model.record_v2.GroupAble)7 GroupableActivity (org.orcid.jaxb.model.record_v2.GroupableActivity)7 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)6 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)6 Group (com.google.monitoring.v3.Group)5