Search in sources :

Example 21 with ActivitiesSummary

use of org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary in project ORCID-Source by ORCID.

the class OrcidSecurityManagerImpl method checkAndFilter.

@Override
public void checkAndFilter(String orcid, ActivitiesSummary activities) {
    if (activities == null) {
        return;
    }
    // Check the token
    isMyToken(orcid);
    // Educations
    if (activities.getEducations() != null) {
        checkAndFilter(orcid, activities.getEducations().getSummaries(), READ_AFFILIATIONS_REQUIRED_SCOPE, true);
    }
    // Employments
    if (activities.getEmployments() != null) {
        checkAndFilter(orcid, activities.getEmployments().getSummaries(), READ_AFFILIATIONS_REQUIRED_SCOPE, true);
    }
    // Funding
    if (activities.getFundings() != null) {
        Iterator<FundingGroup> groupIt = activities.getFundings().getFundingGroup().iterator();
        while (groupIt.hasNext()) {
            FundingGroup group = groupIt.next();
            // Filter the list of elements
            checkAndFilter(orcid, group.getFundingSummary(), READ_FUNDING_REQUIRED_SCOPE, true);
            // Clean external identifiers
            if (group.getFundingSummary().isEmpty()) {
                groupIt.remove();
            } else {
                filterExternalIdentifiers(group);
            }
        }
    }
    // PeerReviews
    if (activities.getPeerReviews() != null) {
        Iterator<PeerReviewGroup> groupIt = activities.getPeerReviews().getPeerReviewGroup().iterator();
        while (groupIt.hasNext()) {
            PeerReviewGroup group = groupIt.next();
            // Filter the list of elements
            checkAndFilter(orcid, group.getPeerReviewSummary(), READ_PEER_REVIEWS_REQUIRED_SCOPE, true);
            if (group.getPeerReviewSummary().isEmpty()) {
                groupIt.remove();
            }
        }
    }
    // Works
    if (activities.getWorks() != null) {
        Iterator<WorkGroup> groupIt = activities.getWorks().getWorkGroup().iterator();
        while (groupIt.hasNext()) {
            WorkGroup group = groupIt.next();
            // Filter the list of elements
            checkAndFilter(orcid, group.getWorkSummary(), READ_WORKS_REQUIRED_SCOPE, true);
            // Clean external identifiers
            if (group.getWorkSummary().isEmpty()) {
                groupIt.remove();
            } else {
                filterExternalIdentifiers(group);
            }
        }
    }
}
Also used : PeerReviewGroup(org.orcid.jaxb.model.record.summary_v2.PeerReviewGroup) WorkGroup(org.orcid.jaxb.model.record.summary_v2.WorkGroup) FundingGroup(org.orcid.jaxb.model.record.summary_v2.FundingGroup)

Example 22 with ActivitiesSummary

use of org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary in project ORCID-Source by ORCID.

the class OrcidSecurityManager_generalTest method testPublicClient_checkAndFilter_ActivitiesSummary.

/**
     * =================== public client tests ===================
     */
@Test(expected = OrcidUnauthorizedException.class)
public void testPublicClient_checkAndFilter_ActivitiesSummary() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, PUBLIC_CLIENT, ScopePathType.READ_PUBLIC);
    orcidSecurityManager.checkAndFilter(ORCID_1, new ActivitiesSummary());
}
Also used : ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) Test(org.junit.Test)

Example 23 with ActivitiesSummary

use of org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary in project ORCID-Source by ORCID.

the class ConvertVrc4ToV2Test method upgradeActivitiesToVrc3Test.

@Test
public void upgradeActivitiesToVrc3Test() throws JAXBException {
    JAXBContext jaxbContext1 = JAXBContext.newInstance(ActivitiesSummary.class);
    JAXBContext jaxbContext2 = JAXBContext.newInstance(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary.class);
    Unmarshaller jaxbUnmarshaller1 = jaxbContext1.createUnmarshaller();
    Unmarshaller jaxbUnmarshaller2 = jaxbContext2.createUnmarshaller();
    InputStream rc3Stream = ConvertVrc4ToV2Test.class.getClassLoader().getResourceAsStream("test-activities-2.0_rc4.xml");
    InputStream rc4Stream = ConvertVrc4ToV2Test.class.getClassLoader().getResourceAsStream("test-activities-2.0.xml");
    ActivitiesSummary rc3Activities = (ActivitiesSummary) jaxbUnmarshaller1.unmarshal(rc3Stream);
    org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary rc4Activities1 = (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) jaxbUnmarshaller2.unmarshal(rc4Stream);
    V2Convertible result = versionConverterV2_0_rc4ToV2_0.upgrade(new V2Convertible(rc3Activities, "v2_rc4"));
    org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary rc4Activities2 = (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) result.getObjectToConvert();
    assertEquals(rc4Activities1, rc4Activities2);
}
Also used : V2Convertible(org.orcid.core.version.V2Convertible) InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) ActivitiesSummary(org.orcid.jaxb.model.record.summary_rc4.ActivitiesSummary) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 24 with ActivitiesSummary

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

Example 25 with ActivitiesSummary

use of org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary in project ORCID-Source by ORCID.

the class MemberV2Test method testWorksWithPartOfRelationshipDontGetGrouped.

@Test
public void testWorksWithPartOfRelationshipDontGetGrouped() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    String accessTokenForClient1 = getAccessToken();
    String accessTokenForClient2 = getAccessToken(getUser1OrcidId(), getUser1Password(), getScopes(), getClient2ClientId(), getClient2ClientSecret(), getClient2RedirectUri());
    Work work1 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
    work1.setPutCode(null);
    work1.setVisibility(Visibility.PUBLIC);
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    org.orcid.jaxb.model.record_rc1.WorkTitle title1 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
    title1.setTitle(new Title("Work # 1" + time));
    work1.setWorkTitle(title1);
    WorkExternalIdentifier wExtId1 = new WorkExternalIdentifier();
    wExtId1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
    wExtId1.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
    wExtId1.setRelationship(Relationship.SELF);
    wExtId1.setUrl(new Url("http://orcid.org/work#1"));
    work1.getExternalIdentifiers().getWorkExternalIdentifier().clear();
    work1.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId1);
    Work work2 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
    work2.setPutCode(null);
    work2.setVisibility(Visibility.PUBLIC);
    org.orcid.jaxb.model.record_rc1.WorkTitle title2 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
    title2.setTitle(new Title("Work # 2" + time));
    work2.setWorkTitle(title2);
    work2.getExternalIdentifiers().getExternalIdentifier().clear();
    WorkExternalIdentifier wExtId2 = new WorkExternalIdentifier();
    wExtId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
    wExtId2.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
    wExtId2.setRelationship(Relationship.PART_OF);
    wExtId2.setUrl(new Url("http://orcid.org/work#2"));
    work2.getExternalIdentifiers().getWorkExternalIdentifier().clear();
    work2.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId2);
    Work work3 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
    work3.setPutCode(null);
    work3.setVisibility(Visibility.PUBLIC);
    org.orcid.jaxb.model.record_rc1.WorkTitle title3 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
    title3.setTitle(new Title("Work # 3" + time));
    work3.setWorkTitle(title3);
    work3.getExternalIdentifiers().getExternalIdentifier().clear();
    WorkExternalIdentifier wExtId3 = new WorkExternalIdentifier();
    wExtId3.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
    wExtId3.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
    wExtId3.setRelationship(Relationship.SELF);
    wExtId3.setUrl(new Url("http://orcid.org/work#3"));
    work3.getExternalIdentifiers().getWorkExternalIdentifier().clear();
    work3.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId3);
    //Add the three works
    ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessTokenForClient1);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work2, accessTokenForClient1);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work3, accessTokenForClient2);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    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;
    List<Long> putCodes = new ArrayList<Long>();
    for (WorkGroup group : activities.getWorks().getWorkGroup()) {
        if (group.getIdentifiers().getIdentifier() == null || group.getIdentifiers().getIdentifier().isEmpty()) {
            for (WorkSummary summary : group.getWorkSummary()) {
                String title = summary.getTitle().getTitle().getContent();
                if (("Work # 2" + time).equals(title)) {
                    work2found = true;
                    work2Group = group;
                    putCodes.add(summary.getPutCode());
                }
            }
        } else {
            for (Identifier id : group.getIdentifiers().getIdentifier()) {
                //If it is the ID is the one we are looking for
                if (id.getExternalIdentifierId().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;
                            putCodes.add(summary.getPutCode());
                        } else if (("Work # 3" + time).equals(title)) {
                            work3found = true;
                            work3Group = group;
                            putCodes.add(summary.getPutCode());
                        }
                    }
                }
            }
        }
    }
    assertTrue("Work1: " + work1found + " work2 " + work2found + " work3 " + work3found, work1found && work2found && 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));
    //Delete all elements created
    for (Long putCode : putCodes) {
        ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode, accessTokenForClient1);
        if (Response.Status.NO_CONTENT.getStatusCode() != deleteResponse.getStatus()) {
            deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode, accessTokenForClient2);
            assertEquals("Cant delete work " + putCode, Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WorkExternalIdentifierId(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId) ArrayList(java.util.ArrayList) Title(org.orcid.jaxb.model.common_rc1.Title) Url(org.orcid.jaxb.model.common_rc1.Url) ActivitiesSummary(org.orcid.jaxb.model.record.summary_rc1.ActivitiesSummary) WorkGroup(org.orcid.jaxb.model.record.summary_rc1.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_rc1.WorkSummary) WorkExternalIdentifier(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier) FundingExternalIdentifier(org.orcid.jaxb.model.record_rc1.FundingExternalIdentifier) Identifier(org.orcid.jaxb.model.record.summary_rc1.Identifier) Work(org.orcid.jaxb.model.record_rc1.Work) WorkExternalIdentifier(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)101 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)81 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)47 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)43 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)43 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)42 PeerReviewSummary (org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary)40 DBUnitTest (org.orcid.test.DBUnitTest)23 Record (org.orcid.jaxb.model.record_v2.Record)21 Person (org.orcid.jaxb.model.record_v2.Person)19 ClientResponse (com.sun.jersey.api.client.ClientResponse)18 Response (javax.ws.rs.core.Response)18 Address (org.orcid.jaxb.model.record_v2.Address)16 Email (org.orcid.jaxb.model.record_v2.Email)16 Keyword (org.orcid.jaxb.model.record_v2.Keyword)16 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)16 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)16 WorkGroup (org.orcid.jaxb.model.record.summary_v2.WorkGroup)15 OtherName (org.orcid.jaxb.model.record_v2.OtherName)14 Biography (org.orcid.jaxb.model.record_v2.Biography)13