Search in sources :

Example 21 with Group

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

the class ActivityValidatorTest method getPeerReview.

public PeerReview getPeerReview() {
    PeerReview peerReview = new PeerReview();
    peerReview.setCompletionDate(getFuzzyDate());
    peerReview.setExternalIdentifiers(getExternalIDs());
    peerReview.setGroupId("group-id");
    peerReview.setOrganization(getOrganization());
    peerReview.setRole(Role.CHAIR);
    peerReview.setSubjectContainerName(new Title("subject-container-name"));
    peerReview.setSubjectExternalIdentifier(getExternalID());
    peerReview.setSubjectName(getWorkTitle());
    peerReview.setSubjectType(WorkType.ARTISTIC_PERFORMANCE);
    peerReview.setSubjectUrl(new Url("http://test.orcid.org"));
    peerReview.setType(PeerReviewType.EVALUATION);
    peerReview.setUrl(new Url("http://test.orcid.org"));
    peerReview.setVisibility(Visibility.PUBLIC);
    return peerReview;
}
Also used : WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) TranslatedTitle(org.orcid.jaxb.model.common_v2.TranslatedTitle) FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) Title(org.orcid.jaxb.model.common_v2.Title) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Url(org.orcid.jaxb.model.common_v2.Url)

Example 22 with Group

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

the class ActivitiesGroupGeneratorBaseTest method checkActivitiesBelongsToTheSameGroup.

/**
     * Check that the given activitys belongs to the same group in a list of given groups
     * */
public void checkActivitiesBelongsToTheSameGroup(List<ActivitiesGroup> groups, GroupableActivity... activities) {
    GroupableActivity first = activities[0];
    assertNotNull(first);
    ActivitiesGroup theGroup = getGroupThatContainsActivity(groups, first);
    assertNotNull(theGroup);
    for (GroupableActivity activity : activities) {
        assertTrue(theGroup.belongsToGroup(activity));
    }
}
Also used : GroupableActivity(org.orcid.jaxb.model.record_v2.GroupableActivity)

Example 23 with Group

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

the class ActivitiesGroupGeneratorBaseTest method checkActivitiesDontBelongsToTheSameGroup.

/**
     * Check that the given activities belongs to the same group in a list of given groups
     * */
public void checkActivitiesDontBelongsToTheSameGroup(List<ActivitiesGroup> groups, GroupableActivity... activities) {
    for (int i = 0; i < activities.length; i++) {
        GroupableActivity a1 = activities[i];
        ActivitiesGroup theGroup = getGroupThatContainsActivity(groups, a1);
        for (int j = i + 1; j < activities.length; j++) {
            assertFalse("activity[" + i + "] and activity[" + j + "] belongs to the same group", theGroup.belongsToGroup(activities[j]));
        }
    }
}
Also used : GroupableActivity(org.orcid.jaxb.model.record_v2.GroupableActivity)

Example 24 with Group

use of org.orcid.jaxb.model.record_v2.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/samples/read_samples/work-2.0.xml", Work.class);
    work1.setPutCode(null);
    work1.setSource(null);
    work1.setVisibility(Visibility.PUBLIC);
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    org.orcid.jaxb.model.record_v2.WorkTitle title1 = new org.orcid.jaxb.model.record_v2.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/samples/read_samples/work-2.0.xml", Work.class);
    work2.setPutCode(null);
    work2.setSource(null);
    work2.setVisibility(Visibility.PUBLIC);
    org.orcid.jaxb.model.record_v2.WorkTitle title2 = new org.orcid.jaxb.model.record_v2.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/samples/read_samples/work-2.0.xml", Work.class);
    work3.setPutCode(null);
    work3.setSource(null);
    work3.setVisibility(Visibility.PUBLIC);
    org.orcid.jaxb.model.record_v2.WorkTitle title3 = new org.orcid.jaxb.model.record_v2.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) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Title(org.orcid.jaxb.model.common_v2.Title) TranslatedTitle(org.orcid.jaxb.model.common_v2.TranslatedTitle) Url(org.orcid.jaxb.model.common_v2.Url) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) WorkGroup(org.orcid.jaxb.model.record.summary_v2.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 25 with Group

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

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 Url (org.orcid.jaxb.model.common_v2.Url)9 Group (org.gluu.oxtrust.model.scim2.Group)8 Group (org.openstack4j.model.identity.v3.Group)8 ClientResponse (com.sun.jersey.api.client.ClientResponse)7 GluuGroup (org.gluu.oxtrust.model.GluuGroup)7 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)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 Response (javax.ws.rs.core.Response)6 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)6 Group (com.google.monitoring.v3.Group)5 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)5