Search in sources :

Example 16 with Work

use of org.orcid.jaxb.model.record_rc2.Work 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 17 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class PublicV2ApiServiceDelegatorImpl method viewWork.

@Override
public Response viewWork(String orcid, Long putCode) {
    long lastModifiedTime = getLastModifiedTime(orcid);
    Work w = workManagerReadOnly.getWork(orcid, putCode, lastModifiedTime);
    publicAPISecurityManagerV2.checkIsPublic(w);
    ActivityUtils.cleanEmptyFields(w);
    ActivityUtils.setPathToActivity(w, orcid);
    sourceUtilsReadOnly.setSourceName(w);
    contributorUtilsReadOnly.filterContributorPrivateData(w);
    return Response.ok(w).build();
}
Also used : Work(org.orcid.jaxb.model.record_v2.Work)

Example 18 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class WorkToCiteprocTranslatorTest method testBibtexWorkTranslationHyperAuthorLiteralAndMissingDOI.

@Test
public void testBibtexWorkTranslationHyperAuthorLiteralAndMissingDOI() {
    Work w = makeWork(bibtexHyperLiteral);
    ExternalIDs wei = new ExternalIDs();
    ExternalID eid = new ExternalID();
    eid.setType(WorkExternalIdentifierType.DOI.name());
    //WorkExternalIdentifierId id = new WorkExternalIdentifierId();
    eid.setValue("10.1234/1234");
    wei.getExternalIdentifier().add(eid);
    w.setWorkExternalIdentifiers(wei);
    WorkToCiteprocTranslator t = new WorkToCiteprocTranslator();
    CSLItemData d = t.toCiteproc(w, null, true);
    Assert.assertEquals(d.getAuthor().length, 1);
    Assert.assertEquals(d.getAuthor()[0].getLiteral(), "Altshuler, D.M. and Durbin, R.M. and Abecasis, G.R. and Bentley, D.R. and Chakravarti, A. and Clark, A.G. and Donnelly, P. and Eichler, E.E. and Flicek, P. and Gabriel, S.B. and Gibbs, R.A. and Gre...");
    Assert.assertEquals(d.getDOI(), "10.1234/1234");
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) CSLItemData(de.undercouch.citeproc.csl.CSLItemData) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 19 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class WorkToCiteprocTranslatorTest method makeWork.

private Work makeWork(String bibtex) {
    Work work = new Work();
    Citation citation = new Citation();
    citation.setWorkCitationType(CitationType.BIBTEX);
    citation.setCitation(bibtex);
    work.setWorkCitation(citation);
    return work;
}
Also used : Work(org.orcid.jaxb.model.record_v2.Work) Citation(org.orcid.jaxb.model.record_v2.Citation)

Example 20 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_GeneralTest method testOrcidProfileCreate_CAN_CRUDOnUnclaimedAccounts.

@Test
public void testOrcidProfileCreate_CAN_CRUDOnUnclaimedAccounts() {
    String orcid = "0000-0000-0000-0001";
    SecurityContextTestUtils.setUpSecurityContextForClientOnly();
    // Test address
    Response response = serviceDelegator.createAddress(orcid, Utils.getAddress());
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    Long putCode = Utils.getPutCode(response);
    response = serviceDelegator.viewAddress(orcid, putCode);
    assertNotNull(response);
    Address address = (Address) response.getEntity();
    assertNotNull(address);
    address.getCountry().setValue(Iso3166Country.ZW);
    response = serviceDelegator.updateAddress(orcid, putCode, address);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.deleteAddress(orcid, putCode);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    // Test education
    response = serviceDelegator.createEducation(orcid, Utils.getEducation());
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    putCode = Utils.getPutCode(response);
    response = serviceDelegator.viewEducation(orcid, putCode);
    assertNotNull(response);
    Education education = (Education) response.getEntity();
    assertNotNull(education);
    education.setDepartmentName("Updated department name");
    response = serviceDelegator.updateEducation(orcid, putCode, education);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.deleteAffiliation(orcid, putCode);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    // Test employment
    response = serviceDelegator.createEmployment(orcid, Utils.getEmployment());
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    putCode = Utils.getPutCode(response);
    response = serviceDelegator.viewEmployment(orcid, putCode);
    assertNotNull(response);
    Employment employment = (Employment) response.getEntity();
    assertNotNull(employment);
    employment.setDepartmentName("Updated department name");
    response = serviceDelegator.updateEmployment(orcid, putCode, employment);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.deleteAffiliation(orcid, putCode);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    // Test external identifiers
    response = serviceDelegator.createExternalIdentifier(orcid, Utils.getPersonExternalIdentifier());
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    putCode = Utils.getPutCode(response);
    response = serviceDelegator.viewExternalIdentifier(orcid, putCode);
    assertNotNull(response);
    PersonExternalIdentifier externalIdentifier = (PersonExternalIdentifier) response.getEntity();
    assertNotNull(externalIdentifier);
    response = serviceDelegator.updateExternalIdentifier(orcid, putCode, externalIdentifier);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.deleteExternalIdentifier(orcid, putCode);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    // Test funding
    response = serviceDelegator.createFunding(orcid, Utils.getFunding());
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    putCode = Utils.getPutCode(response);
    response = serviceDelegator.viewFunding(orcid, putCode);
    assertNotNull(response);
    Funding funding = (Funding) response.getEntity();
    assertNotNull(funding);
    response = serviceDelegator.updateFunding(orcid, putCode, funding);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.deleteFunding(orcid, putCode);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    // Test keyword
    response = serviceDelegator.createKeyword(orcid, Utils.getKeyword());
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    putCode = Utils.getPutCode(response);
    response = serviceDelegator.viewKeyword(orcid, putCode);
    assertNotNull(response);
    Keyword keyword = (Keyword) response.getEntity();
    assertNotNull(keyword);
    response = serviceDelegator.updateKeyword(orcid, putCode, keyword);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.deleteKeyword(orcid, putCode);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    // Test other names
    response = serviceDelegator.createOtherName(orcid, Utils.getOtherName());
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    putCode = Utils.getPutCode(response);
    response = serviceDelegator.viewOtherName(orcid, putCode);
    assertNotNull(response);
    OtherName otherName = (OtherName) response.getEntity();
    assertNotNull(otherName);
    response = serviceDelegator.updateOtherName(orcid, putCode, otherName);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.deleteOtherName(orcid, putCode);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    // Test peer review
    response = serviceDelegator.createPeerReview(orcid, Utils.getPeerReview());
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    putCode = Utils.getPutCode(response);
    response = serviceDelegator.viewPeerReview(orcid, putCode);
    assertNotNull(response);
    PeerReview peerReview = (PeerReview) response.getEntity();
    assertNotNull(peerReview);
    response = serviceDelegator.updatePeerReview(orcid, putCode, peerReview);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.deletePeerReview(orcid, putCode);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    // Test researcher url
    response = serviceDelegator.createResearcherUrl(orcid, Utils.getResearcherUrl());
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    putCode = Utils.getPutCode(response);
    response = serviceDelegator.viewResearcherUrl(orcid, putCode);
    assertNotNull(response);
    ResearcherUrl rUrl = (ResearcherUrl) response.getEntity();
    assertNotNull(rUrl);
    response = serviceDelegator.updateResearcherUrl(orcid, putCode, rUrl);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.deleteResearcherUrl(orcid, putCode);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    // Test work
    response = serviceDelegator.createWork(orcid, Utils.getWork("work # 1 " + System.currentTimeMillis()));
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    putCode = Utils.getPutCode(response);
    response = serviceDelegator.viewWork(orcid, putCode);
    assertNotNull(response);
    Work work = (Work) response.getEntity();
    assertNotNull(work);
    response = serviceDelegator.updateWork(orcid, putCode, work);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    response = serviceDelegator.deleteWork(orcid, putCode);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Also used : Address(org.orcid.jaxb.model.record_v2.Address) Keyword(org.orcid.jaxb.model.record_v2.Keyword) Funding(org.orcid.jaxb.model.record_v2.Funding) OtherName(org.orcid.jaxb.model.record_v2.OtherName) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) Response(javax.ws.rs.core.Response) Education(org.orcid.jaxb.model.record_v2.Education) Employment(org.orcid.jaxb.model.record_v2.Employment) Work(org.orcid.jaxb.model.record_v2.Work) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Work (org.orcid.jaxb.model.record_v2.Work)150 Test (org.junit.Test)147 ClientResponse (com.sun.jersey.api.client.ClientResponse)52 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)33 DBUnitTest (org.orcid.test.DBUnitTest)24 Response (javax.ws.rs.core.Response)23 Title (org.orcid.jaxb.model.common_v2.Title)22 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)22 Url (org.orcid.jaxb.model.common_v2.Url)21 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)21 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)19 ArrayList (java.util.ArrayList)16 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)16 BaseTest (org.orcid.core.BaseTest)14 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)13 Work (org.orcid.jaxb.model.record_rc1.Work)12 Work (org.orcid.jaxb.model.record_rc3.Work)11 Work (org.orcid.jaxb.model.record_rc4.Work)11 Funding (org.orcid.jaxb.model.record_v2.Funding)11 BulkElement (org.orcid.jaxb.model.record_v2.BulkElement)9