Search in sources :

Example 11 with Title

use of org.orcid.jaxb.model.common_rc2.Title in project ORCID-Source by ORCID.

the class WorksTest method getWork.

private Work getWork(String title, boolean randomExtId, String extIdValue) {
    Long time = System.currentTimeMillis();
    Work work = new Work();
    WorkTitle workTitle = new WorkTitle();
    Title wTitle = new Title(title);
    workTitle.setTranslatedTitle(new TranslatedTitle(title, "en"));
    workTitle.setTitle(wTitle);
    work.setWorkTitle(workTitle);
    work.setWorkType(WorkType.BOOK);
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.SELF);
    if (randomExtId) {
        extId.setValue("work-ext-id-" + (Math.random() * 1000) + "-" + time);
    } else {
        extId.setValue("work-ext-id-" + extIdValue);
    }
    extId.setType("doi");
    ExternalIDs extIds = new ExternalIDs();
    extIds.getExternalIdentifier().add(extId);
    work.setWorkExternalIdentifiers(extIds);
    return work;
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_rc3.ExternalIDs) TranslatedTitle(org.orcid.jaxb.model.common_rc3.TranslatedTitle) WorkTitle(org.orcid.jaxb.model.record_rc3.WorkTitle) ExternalID(org.orcid.jaxb.model.record_rc3.ExternalID) Work(org.orcid.jaxb.model.record_rc3.Work) WorkTitle(org.orcid.jaxb.model.record_rc3.WorkTitle) Title(org.orcid.jaxb.model.common_rc3.Title) TranslatedTitle(org.orcid.jaxb.model.common_rc3.TranslatedTitle)

Example 12 with Title

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

Example 13 with Title

use of org.orcid.jaxb.model.common_rc2.Title in project ORCID-Source by ORCID.

the class MemberV2Test method testTokenWorksOnlyForTheScopeItWasIssued.

@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testTokenWorksOnlyForTheScopeItWasIssued() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    List<String> scopes = getScopes(ScopePathType.FUNDING_CREATE, ScopePathType.FUNDING_UPDATE);
    String accessToken = getAccessToken(scopes);
    Work work1 = (Work) unmarshallFromPath("/record_2.0_rc3/samples/work-2.0_rc3.xml", Work.class);
    work1.setPutCode(null);
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    org.orcid.jaxb.model.record_rc3.WorkTitle title1 = new org.orcid.jaxb.model.record_rc3.WorkTitle();
    title1.setTitle(new Title("Work # 1"));
    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);
    //Add the work
    ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), postResponse.getStatus());
    Funding funding = (Funding) unmarshallFromPath("/record_2.0_rc3/samples/funding-2.0_rc3.xml", Funding.class);
    funding.setPutCode(null);
    funding.setVisibility(Visibility.PUBLIC);
    funding.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID fExtId = new ExternalID();
    fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
    fExtId.setValue("Funding Id " + time);
    fExtId.setRelationship(Relationship.SELF);
    funding.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
    //Add the funding
    postResponse = memberV2ApiClient.createFundingXml(this.getUser1OrcidId(), funding, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    // Delete funding        
    Map map = postResponse.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List resultWithPutCode = (List) map.get("Location");
    String location = resultWithPutCode.get(0).toString();
    Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    ClientResponse deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), putCode, accessToken);
    assertNotNull(deleteResponse);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Funding(org.orcid.jaxb.model.record_rc3.Funding) ExternalID(org.orcid.jaxb.model.record_rc3.ExternalID) Title(org.orcid.jaxb.model.common_rc3.Title) Url(org.orcid.jaxb.model.common_rc3.Url) Work(org.orcid.jaxb.model.record_rc3.Work) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 14 with Title

use of org.orcid.jaxb.model.common_rc2.Title in project ORCID-Source by ORCID.

the class MemberV2ApiServiceImplV2_0_rc2 method compareFundingAndCreditNameVisibility.

private void compareFundingAndCreditNameVisibility(Funding funding) {
    Visibility fundingVisibility = funding.getVisibility();
    if (funding.getContributors() != null && funding.getContributors().getContributor() != null) {
        for (FundingContributor contributor : funding.getContributors().getContributor()) {
            if (contributor.getCreditName() != null && contributor.getCreditName().getVisibility() != null && contributor.getCreditName().getVisibility().isMoreRestrictiveThan(fundingVisibility)) {
                String title = (funding.getTitle() == null || funding.getTitle().getTitle() == null) ? null : funding.getTitle().getTitle().getContent();
                LOGGER.error("Client posting funding '{}' with visibility ({}) less restrictive than its contributor credit name '{}' ({})", new Object[] { title, fundingVisibility, contributor.getCreditName().getContent(), contributor.getCreditName().getVisibility() });
            }
        }
    }
}
Also used : FundingContributor(org.orcid.jaxb.model.record_rc2.FundingContributor) Visibility(org.orcid.jaxb.model.common_rc2.Visibility)

Example 15 with Title

use of org.orcid.jaxb.model.common_rc2.Title in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_PeerReviewsTest method testAddPeerReviewWithSameExtIdValueButDifferentExtIdType.

@Test
public void testAddPeerReviewWithSameExtIdValueButDifferentExtIdType() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4444", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    PeerReview peerReview1 = new PeerReview();
    ExternalIDs weis1 = new ExternalIDs();
    ExternalID wei1 = new ExternalID();
    wei1.setRelationship(null);
    wei1.setValue("same_but_different_type");
    wei1.setType(WorkExternalIdentifierType.DOI.value());
    weis1.getExternalIdentifier().add(wei1);
    peerReview1.setExternalIdentifiers(weis1);
    peerReview1.setGroupId("issn:0000003");
    peerReview1.setOrganization(Utils.getOrganization());
    peerReview1.setRole(Role.CHAIR);
    peerReview1.setSubjectContainerName(new Title("subject-container-name"));
    peerReview1.setSubjectExternalIdentifier(wei1);
    WorkTitle workTitle1 = new WorkTitle();
    workTitle1.setTitle(new Title("work-title"));
    peerReview1.setSubjectName(workTitle1);
    peerReview1.setSubjectType(WorkType.DATA_SET);
    peerReview1.setType(PeerReviewType.EVALUATION);
    Response response1 = serviceDelegator.createPeerReview("4444-4444-4444-4444", peerReview1);
    assertNotNull(response1);
    assertEquals(Response.Status.CREATED.getStatusCode(), response1.getStatus());
    Map<?, ?> map = response1.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List<?> resultWithPutCode = (List<?>) map.get("Location");
    Long putCode1 = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
    PeerReview peerReview2 = new PeerReview();
    ExternalIDs weis2 = new ExternalIDs();
    ExternalID wei2 = new ExternalID();
    wei2.setRelationship(null);
    // Same value
    wei2.setValue("same_but_different_type");
    // But different
    wei2.setType(WorkExternalIdentifierType.ARXIV.value());
    // type
    weis2.getExternalIdentifier().add(wei2);
    peerReview2.setExternalIdentifiers(weis2);
    peerReview2.setGroupId("issn:0000003");
    peerReview2.setOrganization(Utils.getOrganization());
    peerReview2.setRole(Role.CHAIR);
    peerReview2.setSubjectContainerName(new Title("subject-container-name"));
    peerReview2.setSubjectExternalIdentifier(wei2);
    WorkTitle workTitle2 = new WorkTitle();
    workTitle2.setTitle(new Title("work-title"));
    peerReview2.setSubjectName(workTitle2);
    peerReview2.setSubjectType(WorkType.DATA_SET);
    peerReview2.setType(PeerReviewType.EVALUATION);
    Response response2 = serviceDelegator.createPeerReview("4444-4444-4444-4444", peerReview2);
    assertNotNull(response2);
    assertEquals(Response.Status.CREATED.getStatusCode(), response2.getStatus());
    map = response2.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    resultWithPutCode = (List<?>) map.get("Location");
    Long putCode2 = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
    // Delete new peer reviews so they don't affect other tests
    serviceDelegator.deletePeerReview("4444-4444-4444-4444", putCode1);
    serviceDelegator.deletePeerReview("4444-4444-4444-4444", putCode2);
}
Also used : Response(javax.ws.rs.core.Response) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) 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) List(java.util.List) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Title (org.orcid.jaxb.model.common_v2.Title)43 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)37 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)28 Test (org.junit.Test)26 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)24 Url (org.orcid.jaxb.model.common_v2.Url)23 FundingTitle (org.orcid.jaxb.model.record_v2.FundingTitle)23 Work (org.orcid.jaxb.model.record_v2.Work)22 ClientResponse (com.sun.jersey.api.client.ClientResponse)19 TranslatedTitle (org.orcid.jaxb.model.common_v2.TranslatedTitle)12 Funding (org.orcid.jaxb.model.record_v2.Funding)11 ArrayList (java.util.ArrayList)8 List (java.util.List)7 Visibility (org.orcid.jaxb.model.common_rc2.Visibility)7 Map (java.util.Map)6 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)6 ExternalID (org.orcid.jaxb.model.record_rc2.ExternalID)5 Url (org.orcid.jaxb.model.common_rc2.Url)4 ContributorOrcid (org.orcid.jaxb.model.common_v2.ContributorOrcid)4 BaseTest (org.orcid.core.BaseTest)3