Search in sources :

Example 6 with Group

use of org.orcid.jaxb.model.record_rc4.Group in project ORCID-Source by ORCID.

the class WorksTest method testWorksWithPartOfRelationshipDontGetGrouped.

@Test
public void testWorksWithPartOfRelationshipDontGetGrouped() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    String accessTokenForClient1 = getAccessToken();
    String accessTokenForClient2 = getAccessToken(getUser1OrcidId(), getUser1Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE, ScopePathType.ACTIVITIES_READ_LIMITED), getClient2ClientId(), getClient2ClientSecret(), getClient2RedirectUri());
    Work work1 = (Work) unmarshallFromPath("/record_2.0_rc4/samples/work-2.0_rc4.xml", Work.class);
    work1.setPutCode(null);
    work1.setVisibility(Visibility.PUBLIC);
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    org.orcid.jaxb.model.record_rc4.WorkTitle title1 = new org.orcid.jaxb.model.record_rc4.WorkTitle();
    title1.setTitle(new Title("Work # 1" + time));
    work1.setWorkTitle(title1);
    ExternalID wExtId1 = new ExternalID();
    wExtId1.setValue("Work Id " + time);
    wExtId1.setType(WorkExternalIdentifierType.AGR.value());
    wExtId1.setRelationship(Relationship.SELF);
    wExtId1.setUrl(new Url("http://orcid.org/work#1"));
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    work1.getExternalIdentifiers().getExternalIdentifier().add(wExtId1);
    Work work2 = (Work) unmarshallFromPath("/record_2.0_rc4/samples/work-2.0_rc4.xml", Work.class);
    work2.setPutCode(null);
    work2.setVisibility(Visibility.PUBLIC);
    org.orcid.jaxb.model.record_rc4.WorkTitle title2 = new org.orcid.jaxb.model.record_rc4.WorkTitle();
    title2.setTitle(new Title("Work # 2" + time));
    work2.setWorkTitle(title2);
    work2.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId2 = new ExternalID();
    wExtId2.setValue("Work Id " + time);
    wExtId2.setType(WorkExternalIdentifierType.AGR.value());
    wExtId2.setRelationship(Relationship.PART_OF);
    wExtId2.setUrl(new Url("http://orcid.org/work#2"));
    work2.getExternalIdentifiers().getExternalIdentifier().clear();
    work2.getExternalIdentifiers().getExternalIdentifier().add(wExtId2);
    Work work3 = (Work) unmarshallFromPath("/record_2.0_rc4/samples/work-2.0_rc4.xml", Work.class);
    work3.setPutCode(null);
    work3.setVisibility(Visibility.PUBLIC);
    org.orcid.jaxb.model.record_rc4.WorkTitle title3 = new org.orcid.jaxb.model.record_rc4.WorkTitle();
    title3.setTitle(new Title("Work # 3" + time));
    work3.setWorkTitle(title3);
    work3.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId3 = new ExternalID();
    wExtId3.setValue("Work Id " + time);
    wExtId3.setType(WorkExternalIdentifierType.AGR.value());
    wExtId3.setRelationship(Relationship.SELF);
    wExtId3.setUrl(new Url("http://orcid.org/work#3"));
    work3.getExternalIdentifiers().getExternalIdentifier().clear();
    work3.getExternalIdentifiers().getExternalIdentifier().add(wExtId3);
    //Add the three works
    ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessTokenForClient1);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    Long putCode1 = getPutCodeFromResponse(postResponse);
    postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work2, accessTokenForClient1);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    Long putCode2 = getPutCodeFromResponse(postResponse);
    postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work3, accessTokenForClient2);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    Long putCode3 = getPutCodeFromResponse(postResponse);
    ClientResponse activitiesResponse = memberV2ApiClient.viewActivities(this.getUser1OrcidId(), accessTokenForClient1);
    assertEquals(Response.Status.OK.getStatusCode(), activitiesResponse.getStatus());
    ActivitiesSummary activities = activitiesResponse.getEntity(ActivitiesSummary.class);
    assertNotNull(activities);
    assertFalse(activities.getWorks().getWorkGroup().isEmpty());
    WorkGroup work1Group = null;
    WorkGroup work2Group = null;
    WorkGroup work3Group = null;
    boolean work1found = false;
    boolean work2found = false;
    boolean work3found = false;
    for (WorkGroup group : activities.getWorks().getWorkGroup()) {
        if (group.getIdentifiers().getExternalIdentifier() == null || group.getIdentifiers().getExternalIdentifier().isEmpty()) {
            for (WorkSummary summary : group.getWorkSummary()) {
                String title = summary.getTitle().getTitle().getContent();
                if (("Work # 2" + time).equals(title)) {
                    work2found = true;
                    work2Group = group;
                }
            }
        } else {
            for (ExternalID id : group.getIdentifiers().getExternalIdentifier()) {
                //If it is the ID is the one we are looking for
                if (id.getValue().equals("Work Id " + time)) {
                    for (WorkSummary summary : group.getWorkSummary()) {
                        String title = summary.getTitle().getTitle().getContent();
                        if (("Work # 1" + time).equals(title)) {
                            work1found = true;
                            work1Group = group;
                        } else if (("Work # 3" + time).equals(title)) {
                            work3found = true;
                            work3Group = group;
                        }
                    }
                }
            }
        }
    }
    assertTrue(work1found);
    assertTrue(work2found);
    assertTrue(work3found);
    //Check that work # 1 and Work # 3 are in the same work
    assertEquals(work1Group, work3Group);
    //Check that work # 2 is not in the same group than group # 1
    assertThat(work2Group, not(work1Group));
    //Remove all created works
    ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode1, accessTokenForClient1);
    assertNotNull(deleteResponse);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
    deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode2, accessTokenForClient1);
    assertNotNull(deleteResponse);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
    deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode3, accessTokenForClient2);
    assertNotNull(deleteResponse);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ExternalID(org.orcid.jaxb.model.record_rc4.ExternalID) TranslatedTitle(org.orcid.jaxb.model.common_rc4.TranslatedTitle) Title(org.orcid.jaxb.model.common_rc4.Title) WorkTitle(org.orcid.jaxb.model.record_rc4.WorkTitle) Url(org.orcid.jaxb.model.common_rc4.Url) ActivitiesSummary(org.orcid.jaxb.model.record.summary_rc4.ActivitiesSummary) WorkGroup(org.orcid.jaxb.model.record.summary_rc4.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_rc4.WorkSummary) WorkTitle(org.orcid.jaxb.model.record_rc4.WorkTitle) Work(org.orcid.jaxb.model.record_rc4.Work) WorkTitle(org.orcid.jaxb.model.record_rc4.WorkTitle) Test(org.junit.Test)

Example 7 with Group

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

the class CopyUtils2 method copy.

/**
	 * Copy data from GluuGroup object to ScimGroup object
	 * 
	 * @param source
	 * @param destination
	 * @return
	 * @throws Exception
	 */
public Group copy(GluuGroup source, Group destination) throws Exception {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        destination = new Group();
    }
    destination.setDisplayName(source.getDisplayName());
    destination.setId(source.getInum());
    if (source.getMembers() != null) {
        if (source.getMembers().size() > 0) {
            Set<MemberRef> memberRefSet = new HashSet<MemberRef>();
            List<String> membersList = source.getMembers();
            for (String oneMember : membersList) {
                if (oneMember != null && !oneMember.isEmpty()) {
                    GluuCustomPerson gluuCustomPerson = personService.getPersonByDn(oneMember);
                    MemberRef memberRef = new MemberRef();
                    memberRef.setValue(gluuCustomPerson.getInum());
                    memberRef.setDisplay(gluuCustomPerson.getDisplayName());
                    String reference = appConfiguration.getBaseEndpoint() + "/scim/v2/Users/" + gluuCustomPerson.getInum();
                    memberRef.setReference(reference);
                    memberRefSet.add(memberRef);
                }
            }
            destination.setMembers(memberRefSet);
        }
    }
    log.trace(" getting meta ");
    Meta meta = (destination.getMeta() != null) ? destination.getMeta() : new Meta();
    if (source.getAttribute("oxTrustMetaVersion") != null) {
        meta.setVersion(source.getAttribute("oxTrustMetaVersion"));
    }
    String location = source.getAttribute("oxTrustMetaLocation");
    if (location != null && !location.isEmpty()) {
        if (!location.startsWith("https://") && !location.startsWith("http://")) {
            location = appConfiguration.getBaseEndpoint() + location;
        }
    } else {
        location = appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/" + source.getInum();
    }
    meta.setLocation(location);
    if (source.getAttribute("oxTrustMetaCreated") != null && !source.getAttribute("oxTrustMetaCreated").isEmpty()) {
        try {
            DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaCreated"), DateTimeZone.UTC);
            meta.setCreated(dateTimeUtc.toDate());
        } catch (Exception e) {
            log.error(" Date parse exception (NEW format), continuing...", e);
            // For backward compatibility
            try {
                meta.setCreated(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaCreated")));
            } catch (Exception ex) {
                log.error(" Date parse exception (OLD format)", ex);
            }
        }
    }
    if (source.getAttribute("oxTrustMetaLastModified") != null && !source.getAttribute("oxTrustMetaLastModified").isEmpty()) {
        try {
            DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaLastModified"), DateTimeZone.UTC);
            meta.setLastModified(dateTimeUtc.toDate());
        } catch (Exception e) {
            log.error(" Date parse exception (NEW format), continuing...", e);
            // For backward compatibility
            try {
                meta.setLastModified(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaLastModified")));
            } catch (Exception ex) {
                log.error(" Date parse exception (OLD format)", ex);
            }
        }
    }
    destination.setMeta(meta);
    return destination;
}
Also used : ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Meta(org.gluu.oxtrust.model.scim2.Meta) MemberRef(org.gluu.oxtrust.model.scim2.MemberRef) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) HashSet(java.util.HashSet)

Example 8 with Group

use of org.orcid.jaxb.model.record_rc4.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 9 with Group

use of org.orcid.jaxb.model.record_rc4.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 10 with Group

use of org.orcid.jaxb.model.record_rc4.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)

Aggregations

Test (org.junit.Test)9 Group (org.gluu.oxtrust.model.scim2.Group)8 Group (org.openstack4j.model.identity.v3.Group)8 ArrayList (java.util.ArrayList)7 GluuGroup (org.gluu.oxtrust.model.GluuGroup)7 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)7 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)6 Group (com.google.monitoring.v3.Group)5 GroupName (com.google.monitoring.v3.GroupName)3 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 URI (java.net.URI)3 Date (java.util.Date)3 DefaultValue (javax.ws.rs.DefaultValue)3 HeaderParam (javax.ws.rs.HeaderParam)3 Produces (javax.ws.rs.Produces)3 Response (javax.ws.rs.core.Response)3 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)3 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)3