Search in sources :

Example 91 with ExternalID

use of org.orcid.jaxb.model.record_rc3.ExternalID in project ORCID-Source by ORCID.

the class WorkManagerTest method getWork.

private Work getWork(String extIdValue) {
    Work work = new Work();
    WorkTitle title = new WorkTitle();
    if (extIdValue == null) {
        title.setTitle(new Title("Work title"));
    } else {
        title.setTitle(new Title("Work title " + extIdValue));
    }
    work.setWorkTitle(title);
    work.setWorkType(WorkType.BOOK);
    ExternalIDs extIds = new ExternalIDs();
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.SELF);
    extId.setType("doi");
    extId.setUrl(new Url("http://orcid.org"));
    if (extIdValue == null) {
        extId.setValue("ext-id-value");
    } else {
        extId.setValue("ext-id-value-" + extIdValue);
    }
    extIds.getExternalIdentifier().add(extId);
    work.setWorkExternalIdentifiers(extIds);
    work.setVisibility(Visibility.PUBLIC);
    return work;
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Title(org.orcid.jaxb.model.common_v2.Title) Url(org.orcid.jaxb.model.common_v2.Url)

Example 92 with ExternalID

use of org.orcid.jaxb.model.record_rc3.ExternalID in project ORCID-Source by ORCID.

the class WorkManagerImpl method buildExistingExternalIdsSet.

/**
     * Return the list of existing external identifiers for the given user where the source matches the given sourceId
     * 
     * @param orcid
     *          The user we want to add the works to
     * @param sourceId
     *          The client id we are evaluating
     * @return A set of all the existing external identifiers that belongs to the given user and to the given source id                  
     * */
private Set<ExternalID> buildExistingExternalIdsSet(String orcid, String sourceId) {
    Set<ExternalID> existingExternalIds = new HashSet<ExternalID>();
    long lastModifiedTime = getLastModified(orcid);
    List<Work> existingWorks = this.findWorks(orcid, lastModifiedTime);
    for (Work work : existingWorks) {
        //If it is the same source
        if (work.retrieveSourcePath().equals(sourceId)) {
            if (work.getExternalIdentifiers() != null && work.getExternalIdentifiers().getExternalIdentifier() != null) {
                for (ExternalID extId : work.getExternalIdentifiers().getExternalIdentifier()) {
                    //Don't include PART_OF external ids
                    if (!Relationship.PART_OF.equals(extId.getRelationship())) {
                        existingExternalIds.add(extId);
                    }
                }
            }
        }
    }
    return existingExternalIds;
}
Also used : ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) HashSet(java.util.HashSet)

Example 93 with ExternalID

use of org.orcid.jaxb.model.record_rc3.ExternalID in project ORCID-Source by ORCID.

the class ExternalIDValidatorTest method testValidExtIdsWorksFine_flagOff.

@Test
public void testValidExtIdsWorksFine_flagOff() {
    ExternalIDs extIds = new ExternalIDs();
    ExternalID id1 = new ExternalID();
    id1.setRelationship(null);
    id1.setType("doi");
    id1.setValue("value1");
    id1.setUrl(new Url("http://value1.com"));
    ExternalID id2 = new ExternalID();
    id2.setRelationship(null);
    id2.setType("doi");
    id2.setValue("value1");
    id2.setUrl(new Url("http://value1.com"));
    ExternalID id3 = new ExternalID();
    id3.setRelationship(null);
    id3.setType("doi");
    id3.setValue("value1");
    id3.setUrl(new Url("http://value1.com"));
    extIds.getExternalIdentifier().add(id1);
    extIds.getExternalIdentifier().add(id2);
    extIds.getExternalIdentifier().add(id3);
    validator.validateWorkOrPeerReview(extIds);
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test)

Example 94 with ExternalID

use of org.orcid.jaxb.model.record_rc3.ExternalID in project ORCID-Source by ORCID.

the class WorksTest method testUpdateWorkWithProfileCreationTokenWhenClaimedAndNotSource.

@Test
public void testUpdateWorkWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    Work workToCreate = (Work) unmarshallFromPath("/record_2.0/samples/read_samples/work-2.0.xml", Work.class);
    workToCreate.setPutCode(null);
    workToCreate.setSource(null);
    workToCreate.setVisibility(Visibility.PUBLIC);
    workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType(WorkExternalIdentifierType.AGR.value());
    wExtId.setRelationship(Relationship.SELF);
    workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), workToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0/" + this.getUser1OrcidId() + "/work/\\d+"));
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Work gotWork = getResponse.getEntity(Work.class);
    assertEquals("common:title", gotWork.getWorkTitle().getTitle().getContent());
    gotWork.getWorkTitle().getTitle().setContent("updated title");
    String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotWork);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Work gotAfterUpdateWork = getAfterUpdateResponse.getEntity(Work.class);
    assertEquals("common:title", gotAfterUpdateWork.getWorkTitle().getTitle().getContent());
    ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), gotWork.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 95 with ExternalID

use of org.orcid.jaxb.model.record_rc3.ExternalID in project ORCID-Source by ORCID.

the class MemberV2Test method testUpdatePeerReviewWithProfileCreationTokenWhenClaimedAndNotSource.

@Test
public void testUpdatePeerReviewWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.0/samples/read_samples/peer-review-2.0.xml", PeerReview.class);
    peerReviewToCreate.setPutCode(null);
    peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
    peerReviewToCreate.setVisibility(Visibility.PUBLIC);
    peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType(WorkExternalIdentifierType.AGR.value());
    wExtId.setRelationship(Relationship.SELF);
    peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReviewToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0/" + this.getUser1OrcidId() + "/peer-review/\\d+"));
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    PeerReview gotPeerReview = getResponse.getEntity(PeerReview.class);
    assertEquals("peer-review:subject-name", gotPeerReview.getSubjectName().getTitle().getContent());
    gotPeerReview.getSubjectName().getTitle().setContent("updated title");
    String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotPeerReview);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    PeerReview gotAfterUpdatePeerReview = getAfterUpdateResponse.getEntity(PeerReview.class);
    assertEquals("peer-review:subject-name", gotAfterUpdatePeerReview.getSubjectName().getTitle().getContent());
    ClientResponse deleteResponse = memberV2ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), gotAfterUpdatePeerReview.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Aggregations

ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)116 Test (org.junit.Test)104 Url (org.orcid.jaxb.model.common_v2.Url)58 ClientResponse (com.sun.jersey.api.client.ClientResponse)53 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)53 Work (org.orcid.jaxb.model.record_v2.Work)34 Title (org.orcid.jaxb.model.common_v2.Title)28 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)22 Funding (org.orcid.jaxb.model.record_v2.Funding)16 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)15 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)14 ExternalID (org.orcid.jaxb.model.record_rc3.ExternalID)13 ExternalID (org.orcid.jaxb.model.record_rc4.ExternalID)13 ArrayList (java.util.ArrayList)12 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)12 FundingTitle (org.orcid.jaxb.model.record_v2.FundingTitle)11 BaseTest (org.orcid.core.BaseTest)9 WorkGroup (org.orcid.jaxb.model.record.summary_v2.WorkGroup)8 ExternalID (org.orcid.jaxb.model.record_rc2.ExternalID)8 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)8