Search in sources :

Example 31 with Work

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

the class PublicV2Test method checkLimitedWork.

public void checkLimitedWork(String readPublicToken) throws JSONException, InterruptedException, URISyntaxException {
    changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
    workToCreate.setPutCode(null);
    workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createWorkXml(getUser1OrcidId(), workToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String path = postResponse.getLocation().getPath();
    String putCode = path.substring(path.lastIndexOf('/') + 1, path.length());
    ClientResponse response = null;
    if (readPublicToken != null) {
        response = publicV2ApiClient.viewWorkXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        response = publicV2ApiClient.viewWorkXml(getUser1OrcidId(), putCode);
    }
    assertNotNull(response);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
    OrcidError result = response.getEntity(OrcidError.class);
    assertNotNull(result);
    assertEquals(new Integer(9039), result.getErrorCode());
    assertEquals("403 Forbidden: The item is not public and cannot be accessed with the Public API.", result.getDeveloperMessage());
    response = null;
    if (readPublicToken != null) {
        response = publicV2ApiClient.viewWorkSummaryXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        response = publicV2ApiClient.viewWorkSummaryXml(getUser1OrcidId(), putCode);
    }
    assertNotNull(response);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
    result = response.getEntity(OrcidError.class);
    assertNotNull(result);
    assertEquals(new Integer(9039), result.getErrorCode());
    assertEquals("403 Forbidden: The item is not public and cannot be accessed with the Public API.", result.getDeveloperMessage());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_rc1.OrcidError) Work(org.orcid.jaxb.model.record_rc1.Work)

Example 32 with Work

use of org.orcid.jaxb.model.record_rc1.Work 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_rc1/samples/work-2.0_rc1.xml", Work.class);
    workToCreate.setPutCode(null);
    workToCreate.setVisibility(Visibility.PUBLIC);
    workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
    WorkExternalIdentifier wExtId = new WorkExternalIdentifier();
    wExtId.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
    wExtId.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
    wExtId.setRelationship(Relationship.SELF);
    wExtId.setUrl(new Url("http://test.orcid.org/" + time));
    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_rc1/" + 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("Current treatment of left main coronary artery disease", 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("Current treatment of left main coronary artery disease", 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) Work(org.orcid.jaxb.model.record_rc1.Work) WorkExternalIdentifierId(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId) WorkExternalIdentifier(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier) Url(org.orcid.jaxb.model.common_rc1.Url) Test(org.junit.Test)

Example 33 with Work

use of org.orcid.jaxb.model.record_rc1.Work 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.1/samples/read_samples/work-2.1.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 = memberV2_1ApiClient.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.1/" + this.getUser1OrcidId() + "/work/\\d+"));
    ClientResponse getResponse = memberV2_1ApiClient.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 = memberV2_1ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotWork);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2_1ApiClient.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 = memberV2_1ApiClient.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 34 with Work

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

the class BlackBoxBaseV2_1Release method unmarshallFromPath.

public Object unmarshallFromPath(String path, Class<?> type) {
    try (Reader reader = new InputStreamReader(getClass().getResourceAsStream(path))) {
        Object obj = unmarshall(reader, type);
        Object result = null;
        if (Address.class.equals(type)) {
            result = (Address) obj;
        } else if (Education.class.equals(type)) {
            result = (Education) obj;
        } else if (Employment.class.equals(type)) {
            result = (Employment) obj;
        } else if (Funding.class.equals(type)) {
            result = (Funding) obj;
        } else if (Keyword.class.equals(type)) {
            result = (Keyword) obj;
        } else if (Work.class.equals(type)) {
            result = (Work) obj;
        } else if (PeerReview.class.equals(type)) {
            result = (PeerReview) obj;
        } else if (ResearcherUrl.class.equals(type)) {
            result = (ResearcherUrl) obj;
        } else if (PersonalDetails.class.equals(type)) {
            result = (PersonalDetails) obj;
        } else if (OtherName.class.equals(type)) {
            result = (OtherName) obj;
        } else if (PersonExternalIdentifier.class.equals(type)) {
            result = (PersonExternalIdentifier) obj;
        }
        return result;
    } catch (IOException e) {
        throw new RuntimeException("Error reading notification from classpath", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Education(org.orcid.jaxb.model.record_v2.Education) Funding(org.orcid.jaxb.model.record_v2.Funding) Work(org.orcid.jaxb.model.record_v2.Work) OtherName(org.orcid.jaxb.model.record_v2.OtherName) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) IOException(java.io.IOException)

Example 35 with Work

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

the class PublicV2ApiServiceDelegatorTest method testGetPublicWorkUsingToken.

// Work
@Test
public void testGetPublicWorkUsingToken() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    Response r = serviceDelegator.viewWork(ORCID, 11L);
    assertNotNull(r);
    Work w = (Work) r.getEntity();
    assertNotNull(w);
    assertNotNull(w.getLastModifiedDate());
    assertNotNull(w.getLastModifiedDate().getValue());
    assertEquals(Long.valueOf(11), w.getPutCode());
}
Also used : Response(javax.ws.rs.core.Response) Work(org.orcid.jaxb.model.record_v2.Work) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)152 Work (org.orcid.jaxb.model.record_v2.Work)151 ClientResponse (com.sun.jersey.api.client.ClientResponse)56 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)35 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)26 DBUnitTest (org.orcid.test.DBUnitTest)25 Response (javax.ws.rs.core.Response)24 Title (org.orcid.jaxb.model.common_v2.Title)24 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)23 Url (org.orcid.jaxb.model.common_v2.Url)22 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)22 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)17 ArrayList (java.util.ArrayList)16 BaseTest (org.orcid.core.BaseTest)16 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)16 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)15 Work (org.orcid.jaxb.model.record_rc1.Work)12 WorkExternalIdentifier (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier)12 WorkExternalIdentifierId (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId)12 Work (org.orcid.jaxb.model.record_rc3.Work)11