Search in sources :

Example 66 with Work

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

the class WorksTest method createViewUpdateAndDeleteWork.

@Test
public void createViewUpdateAndDeleteWork() throws JSONException, InterruptedException, URISyntaxException {
    showMyOrcidPage();
    changeDefaultUserVisibility(webDriver, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.name());
    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.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType("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/" + 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());
    assertEquals("work:citation", gotWork.getWorkCitation().getCitation());
    assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotWork.getWorkCitation().getWorkCitationType());
    gotWork.getWorkTitle().getTitle().setContent("updated title");
    // Save the original visibility
    Visibility originalVisibility = gotWork.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotWork.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    OrcidError error = putResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    gotWork.setVisibility(originalVisibility);
    putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Work gotAfterUpdateWork = getAfterUpdateResponse.getEntity(Work.class);
    assertEquals("updated title", gotAfterUpdateWork.getWorkTitle().getTitle().getContent());
    assertEquals("work:citation", gotAfterUpdateWork.getWorkCitation().getCitation());
    assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotAfterUpdateWork.getWorkCitation().getWorkCitationType());
    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) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test)

Example 67 with Work

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

the class WorksTest method testCreateBulkWork.

@Test
public void testCreateBulkWork() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    WorkBulk bulk = createBulk(10, null);
    ClientResponse postResponse = memberV2ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
    bulk = postResponse.getEntity(WorkBulk.class);
    assertNotNull(bulk);
    assertNotNull(bulk.getBulk());
    // All elements might be ok
    for (BulkElement element : bulk.getBulk()) {
        assertTrue(Work.class.isAssignableFrom(element.getClass()));
        Work work = (Work) element;
        // Remove the work
        memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 68 with Work

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

the class WorksTest method createViewUpdateAndDeleteWorkWithLegacyScope.

@Test
public void createViewUpdateAndDeleteWorkWithLegacyScope() throws JSONException, InterruptedException, URISyntaxException {
    showMyOrcidPage();
    changeDefaultUserVisibility(webDriver, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC.name());
    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.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID wExtId = new ExternalID();
    wExtId.setValue("Work Id " + time);
    wExtId.setType("agr");
    wExtId.setRelationship(Relationship.SELF);
    wExtId.setUrl(new Url("http://test.orcid.org/" + time));
    workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
    String accessToken = getAccessToken(getScopes(ScopePathType.ORCID_WORKS_UPDATE));
    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());
    assertEquals("work:citation", gotWork.getWorkCitation().getCitation());
    assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotWork.getWorkCitation().getWorkCitationType());
    gotWork.getWorkTitle().getTitle().setContent("updated title");
    // Save the original visibility
    Visibility originalVisibility = gotWork.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    // Verify you cant update the visibility
    gotWork.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    OrcidError error = putResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    // Set the visibility again to the initial one
    gotWork.setVisibility(originalVisibility);
    putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Work gotAfterUpdateWork = getAfterUpdateResponse.getEntity(Work.class);
    assertEquals("updated title", gotAfterUpdateWork.getWorkTitle().getTitle().getContent());
    assertEquals("work:citation", gotAfterUpdateWork.getWorkCitation().getCitation());
    assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotAfterUpdateWork.getWorkCitation().getWorkCitationType());
    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) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test)

Example 69 with Work

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

the class MultipleTokensPerUserAndScopeTest method useSameScopesGetDifferentTokensTest.

@Test
public void useSameScopesGetDifferentTokensTest() throws InterruptedException, JSONException, URISyntaxException {
    List<String> scopes = getScopes(ScopePathType.READ_LIMITED);
    String token1 = getNonCachedAccessTokens(getUser1UserName(), getUser1Password(), scopes, getClient1ClientId(), getClient1ClientSecret(), getClient1RedirectUri());
    String token2 = getNonCachedAccessTokens(getUser1UserName(), getUser1Password(), scopes, getClient1ClientId(), getClient1ClientSecret(), getClient1RedirectUri());
    // Check the scopes are not null
    assertNotNull(token1);
    assertNotNull(token2);
    assertFalse(token1.equals(token2));
    // Check token 1 is working
    ClientResponse token1Response = memberV2ApiClient.viewActivities(this.getUser1OrcidId(), token1);
    assertNotNull(token1Response);
    assertEquals(Response.Status.OK.getStatusCode(), token1Response.getStatus());
    ActivitiesSummary token1Activities = token1Response.getEntity(ActivitiesSummary.class);
    assertNotNull(token1Activities);
    // Check token 2 is working
    ClientResponse token2Response = memberV2ApiClient.viewActivities(this.getUser1OrcidId(), token2);
    assertNotNull(token2Response);
    assertEquals(Response.Status.OK.getStatusCode(), token2Response.getStatus());
    ActivitiesSummary token2Activities = token2Response.getEntity(ActivitiesSummary.class);
    assertNotNull(token2Activities);
    assertTrue(token1Activities.equals(token2Activities));
    // Check tokens works just for his scopes
    Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
    workToCreate.setPutCode(null);
    workToCreate.getWorkTitle().getTitle().setContent("Title " + System.currentTimeMillis());
    ClientResponse token1AddWorkresponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), workToCreate, token1);
    assertNotNull(token1AddWorkresponse);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), token1AddWorkresponse.getStatus());
    ClientResponse token2AddWorkresponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), workToCreate, token2);
    assertNotNull(token2AddWorkresponse);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), token2AddWorkresponse.getStatus());
    // Check a new token with other scope can add the work
    scopes.add(ScopePathType.ACTIVITIES_UPDATE.value());
    String token3 = getNonCachedAccessTokens(getUser1UserName(), getUser1Password(), scopes, getClient1ClientId(), getClient1ClientSecret(), getClient1RedirectUri());
    assertNotNull(token3);
    assertFalse(token1.equals(token3));
    // Check token 3 is working
    ClientResponse token3Response = memberV2ApiClient.viewActivities(this.getUser1OrcidId(), token3);
    assertNotNull(token3Response);
    assertEquals(Response.Status.OK.getStatusCode(), token3Response.getStatus());
    ActivitiesSummary token3Activities = token3Response.getEntity(ActivitiesSummary.class);
    assertNotNull(token3Activities);
    assertTrue(token1Activities.equals(token3Activities));
    // Check that token 3 can add works
    ClientResponse token3AddWorkresponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), workToCreate, token3);
    assertNotNull(token3AddWorkresponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), token3AddWorkresponse.getStatus());
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(token3AddWorkresponse.getLocation(), token3);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Work gotWork = getResponse.getEntity(Work.class);
    assertNotNull(gotWork);
    assertNotNull(gotWork.getPutCode());
    ClientResponse deleteNewWork = memberV2ApiClient.deleteWorkXml(getUser1OrcidId(), gotWork.getPutCode(), token3);
    assertNotNull(deleteNewWork);
    assertEquals(ClientResponse.Status.NO_CONTENT.getStatusCode(), deleteNewWork.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Work(org.orcid.jaxb.model.record_rc1.Work) ActivitiesSummary(org.orcid.jaxb.model.record.summary_rc1.ActivitiesSummary) Test(org.junit.Test)

Example 70 with Work

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

the class VerifyOrcidBeforeFetchElementTest method testWork.

@Test
public void testWork() throws InterruptedException, JSONException, 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.getExternalIdentifiers().getExternalIdentifier().clear();
    WorkExternalIdentifier wExtId = new WorkExternalIdentifier();
    wExtId.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
    wExtId.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
    wExtId.setRelationship(Relationship.PART_OF);
    workToCreate.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId);
    String user1AccessToken = getAccessToken();
    // Create a work
    ClientResponse postResponse = memberV2ApiClient.createWorkXml(getUser1OrcidId(), workToCreate, user1AccessToken);
    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/" + getUser1OrcidId() + "/work/\\d+"));
    // Fetch it with the owner
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), user1AccessToken);
    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());
    String user2AccessToken = getAccessToken(getUser2OrcidId(), getUser2Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE), getClient1ClientId(), getClient1ClientSecret(), getClient1RedirectUri());
    // Try to fetch it with other user orcid
    // Using the members API
    ClientResponse user2GetResponse = memberV2ApiClient.viewWorkXml(getUser2OrcidId(), gotWork.getPutCode(), user2AccessToken);
    assertNotNull(user2GetResponse);
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
    OrcidError error = user2GetResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9016), error.getErrorCode());
    // Using the public API
    user2GetResponse = publicV2ApiClient.viewWorkXml(getUser2OrcidId(), String.valueOf(gotWork.getPutCode()));
    assertNotNull(user2GetResponse);
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
    error = user2GetResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9016), error.getErrorCode());
    // Delete it
    ClientResponse deletedResponse = memberV2ApiClient.deleteWorkXml(getUser1OrcidId(), gotWork.getPutCode(), user1AccessToken);
    assertNotNull(deletedResponse);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deletedResponse.getStatus());
}
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) WorkExternalIdentifierId(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId) WorkExternalIdentifier(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)153 Work (org.orcid.jaxb.model.record_v2.Work)151 ClientResponse (com.sun.jersey.api.client.ClientResponse)53 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 Work (org.orcid.jaxb.model.record_rc3.Work)11 ExternalID (org.orcid.jaxb.model.record_rc4.ExternalID)11 Work (org.orcid.jaxb.model.record_rc4.Work)11