Search in sources :

Example 26 with ExternalID

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

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

the class MemberV2_1Test method testUpdateFundingWithProfileCreationTokenWhenClaimedAndNotSource.

@Test
public void testUpdateFundingWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    Funding funding = (Funding) unmarshallFromPath("/record_2.1/samples/read_samples/funding-2.1.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);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2_1ApiClient.createFundingXml(this.getUser1OrcidId(), funding, 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() + "/funding/\\d+"));
    ClientResponse getResponse = memberV2_1ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Funding gotFunding = getResponse.getEntity(Funding.class);
    assertEquals("common:title", gotFunding.getTitle().getTitle().getContent());
    assertEquals("common:translated-title", gotFunding.getTitle().getTranslatedTitle().getContent());
    assertEquals("en", gotFunding.getTitle().getTranslatedTitle().getLanguageCode());
    gotFunding.getTitle().getTitle().setContent("Updated title");
    gotFunding.getTitle().getTranslatedTitle().setContent("Updated translated title");
    gotFunding.getTitle().getTranslatedTitle().setLanguageCode("es");
    String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
    ClientResponse putResponse = memberV2_1ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotFunding);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2_1ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Funding gotAfterUpdateFunding = getAfterUpdateResponse.getEntity(Funding.class);
    assertEquals("common:title", gotAfterUpdateFunding.getTitle().getTitle().getContent());
    assertEquals("common:translated-title", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getContent());
    assertEquals("en", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getLanguageCode());
    ClientResponse deleteResponse = memberV2_1ApiClient.deleteFundingXml(this.getUser1OrcidId(), gotFunding.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Funding(org.orcid.jaxb.model.record_v2.Funding) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Test(org.junit.Test)

Example 28 with ExternalID

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

the class MemberV2ApiServiceDelegator_WorksTest method testUpdateWorkYouAreNotTheSourceOf.

@Test(expected = WrongSourceException.class)
public void testUpdateWorkYouAreNotTheSourceOf() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewWork("4444-4444-4444-4443", 2L);
    assertNotNull(response);
    Work work = (Work) response.getEntity();
    assertNotNull(work);
    Utils.verifyLastModified(work.getLastModifiedDate());
    assertEquals(Long.valueOf(2), work.getPutCode());
    assertNotNull(work.getWorkTitle());
    assertNotNull(work.getWorkTitle().getTitle());
    assertEquals("Another day in the life", work.getWorkTitle().getTitle().getContent());
    assertEquals(WorkType.BOOK, work.getWorkType());
    work.setWorkType(WorkType.EDITED_BOOK);
    work.getWorkTitle().getTitle().setContent("Updated work title");
    ExternalIDs extIds = new ExternalIDs();
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.PART_OF);
    extId.setType(WorkExternalIdentifierType.AGR.value());
    extId.setValue("ext-id-" + System.currentTimeMillis());
    extId.setUrl(new Url("http://thisIsANewUrl.com"));
    extIds.getExternalIdentifier().add(extId);
    work.setWorkExternalIdentifiers(extIds);
    serviceDelegator.updateWork("4444-4444-4444-4443", 2L, work);
    fail();
}
Also used : Response(javax.ws.rs.core.Response) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) Url(org.orcid.jaxb.model.common_v2.Url) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 29 with ExternalID

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

the class JpaJaxbNotificationAdapterTest method testToNotificationAmendedEntity.

@Test
public void testToNotificationAmendedEntity() {
    NotificationAmended notification = new NotificationAmended();
    notification.setNotificationType(NotificationType.AMENDED);
    Source source = new Source();
    notification.setSource(source);
    SourceClientId clientId = new SourceClientId();
    source.setSourceClientId(clientId);
    clientId.setPath("APP-5555-5555-5555-5555");
    Items activities = new Items();
    notification.setItems(activities);
    Item activity = new Item();
    activities.getItems().add(activity);
    activity.setItemType(ItemType.WORK);
    activity.setItemName("Latest Research Article");
    ExternalID extId = new ExternalID();
    activity.setExternalIdentifier(extId);
    extId.setType("doi");
    extId.setValue("1234/abc123");
    NotificationEntity notificationEntity = jpaJaxbNotificationAdapter.toNotificationEntity(notification);
    assertTrue(notificationEntity instanceof NotificationAmendedEntity);
    NotificationAmendedEntity notificationAmendedEntity = (NotificationAmendedEntity) notificationEntity;
    assertNotNull(notificationEntity);
    assertEquals(NotificationType.AMENDED, notificationEntity.getNotificationType());
    // Source
    assertNull(notificationAmendedEntity.getSourceId());
    assertNull(notificationAmendedEntity.getClientSourceId());
    assertNull(notificationAmendedEntity.getElementSourceId());
}
Also used : NotificationAmendedEntity(org.orcid.persistence.jpa.entities.NotificationAmendedEntity) Item(org.orcid.jaxb.model.notification.permission_v2.Item) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Items(org.orcid.jaxb.model.notification.permission_v2.Items) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Source(org.orcid.jaxb.model.common_v2.Source) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended) Test(org.junit.Test)

Example 30 with ExternalID

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

the class JpaJaxbNotificationAdapterTest method testToNotificationPermissionEntity.

@Test
public void testToNotificationPermissionEntity() {
    NotificationPermission notification = new NotificationPermission();
    notification.setNotificationType(NotificationType.PERMISSION);
    String authorizationUrlString = "https://orcid.org/oauth/authorize?client_id=APP-U4UKCNSSIM1OCVQY&response_type=code&scope=/orcid-works/create&redirect_uri=http://somethirdparty.com";
    AuthorizationUrl url = new AuthorizationUrl();
    notification.setAuthorizationUrl(url);
    notification.setNotificationIntro("This is the intro");
    notification.setNotificationSubject("This is the subject");
    Source source = new Source();
    notification.setSource(source);
    SourceClientId clientId = new SourceClientId();
    source.setSourceClientId(clientId);
    clientId.setPath("APP-5555-5555-5555-5555");
    url.setUri(authorizationUrlString);
    Items activities = new Items();
    notification.setItems(activities);
    Item activity = new Item();
    activities.getItems().add(activity);
    activity.setItemType(ItemType.WORK);
    activity.setItemName("Latest Research Article");
    ExternalID extId = new ExternalID();
    activity.setExternalIdentifier(extId);
    extId.setType("doi");
    extId.setValue("1234/abc123");
    NotificationEntity notificationEntity = jpaJaxbNotificationAdapter.toNotificationEntity(notification);
    assertTrue(notificationEntity instanceof NotificationAddItemsEntity);
    NotificationAddItemsEntity addActivitiesEntity = (NotificationAddItemsEntity) notificationEntity;
    assertNotNull(notificationEntity);
    assertEquals(NotificationType.PERMISSION, notificationEntity.getNotificationType());
    assertEquals(authorizationUrlString, addActivitiesEntity.getAuthorizationUrl());
    assertEquals(notification.getNotificationIntro(), notificationEntity.getNotificationIntro());
    assertEquals(notification.getNotificationSubject(), notificationEntity.getNotificationSubject());
    // Source
    assertNull(notificationEntity.getSourceId());
    assertNull(notificationEntity.getClientSourceId());
    assertNull(notificationEntity.getElementSourceId());
    Set<NotificationItemEntity> activityEntities = addActivitiesEntity.getNotificationItems();
    assertNotNull(activityEntities);
    assertEquals(1, activityEntities.size());
    NotificationItemEntity activityEntity = activityEntities.iterator().next();
    assertEquals(ItemType.WORK, activityEntity.getItemType());
    assertEquals("Latest Research Article", activityEntity.getItemName());
    assertEquals("DOI", activityEntity.getExternalIdType());
    assertEquals("1234/abc123", activityEntity.getExternalIdValue());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) NotificationAddItemsEntity(org.orcid.persistence.jpa.entities.NotificationAddItemsEntity) Item(org.orcid.jaxb.model.notification.permission_v2.Item) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Items(org.orcid.jaxb.model.notification.permission_v2.Items) NotificationItemEntity(org.orcid.persistence.jpa.entities.NotificationItemEntity) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Source(org.orcid.jaxb.model.common_v2.Source) 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