Search in sources :

Example 46 with Works

use of org.orcid.jaxb.model.v3.dev1.record.summary.Works in project ORCID-Source by ORCID.

the class ActivityUtilsTest method getWorks.

private Works getWorks() {
    Works x = new Works();
    WorkGroup g = new WorkGroup();
    WorkSummary e = new WorkSummary();
    e.setPutCode(123L);
    g.getWorkSummary().add(e);
    x.getWorkGroup().add(g);
    return x;
}
Also used : WorkGroup(org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup) WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works)

Example 47 with Works

use of org.orcid.jaxb.model.v3.dev1.record.summary.Works in project ORCID-Source by ORCID.

the class ActivityUtilsTest method cleanWorksTest.

@Test
public void cleanWorksTest() {
    // Test it cleans empty fields
    WorkSummary s = getEmptyWorkSummary();
    Works w = new Works();
    WorkGroup g = new WorkGroup();
    g.getWorkSummary().add(s);
    w.getWorkGroup().add(g);
    assertNotNull(w.getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle());
    ActivityUtils.cleanEmptyFields(w);
    assertNull(w.getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle());
    // Test it doesn't remove non empty fields
    s = getEmptyWorkSummary();
    s.getTitle().getTranslatedTitle().setContent("test");
    s.getTitle().getTranslatedTitle().setLanguageCode("en_us");
    w = new Works();
    g = new WorkGroup();
    g.getWorkSummary().add(s);
    w.getWorkGroup().add(g);
    assertEquals("test", w.getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle().getContent());
    assertEquals("en_us", w.getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle().getLanguageCode());
    ActivityUtils.cleanEmptyFields(w);
    assertEquals("test", w.getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle().getContent());
    assertEquals("en_us", w.getWorkGroup().get(0).getWorkSummary().get(0).getTitle().getTranslatedTitle().getLanguageCode());
}
Also used : WorkGroup(org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup) WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works) Test(org.junit.Test)

Example 48 with Works

use of org.orcid.jaxb.model.v3.dev1.record.summary.Works 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(org.orcid.jaxb.model.notification_v2.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(org.orcid.jaxb.model.notification.permission_v2.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.v3.dev1.notification.permission.AuthorizationUrl) NotificationAddItemsEntity(org.orcid.persistence.jpa.entities.NotificationAddItemsEntity) Item(org.orcid.jaxb.model.v3.dev1.notification.permission.Item) SourceClientId(org.orcid.jaxb.model.v3.dev1.common.SourceClientId) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) Items(org.orcid.jaxb.model.v3.dev1.notification.permission.Items) NotificationItemEntity(org.orcid.persistence.jpa.entities.NotificationItemEntity) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Source(org.orcid.jaxb.model.v3.dev1.common.Source) Test(org.junit.Test)

Example 49 with Works

use of org.orcid.jaxb.model.v3.dev1.record.summary.Works in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_ResearcherUrlsTest method testReadPublicScope_ResearcherUrls.

@Test
public void testReadPublicScope_ResearcherUrls() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    // Public works
    Response r = serviceDelegator.viewResearcherUrls(ORCID);
    assertNotNull(r);
    ResearcherUrls ru = (ResearcherUrls) r.getEntity();
    assertNotNull(ru);
    assertEquals("/0000-0000-0000-0003/researcher-urls", ru.getPath());
    Utils.verifyLastModified(ru.getLastModifiedDate());
    assertEquals(3, ru.getResearcherUrls().size());
    boolean found13 = false, found14 = false, found15 = false;
    for (ResearcherUrl element : ru.getResearcherUrls()) {
        if (element.getPutCode() == 13) {
            found13 = true;
        } else if (element.getPutCode() == 14) {
            found14 = true;
        } else if (element.getPutCode() == 15) {
            found15 = true;
        } else {
            fail("Invalid put code " + element.getPutCode());
        }
    }
    assertTrue(found13);
    assertTrue(found14);
    assertTrue(found15);
    r = serviceDelegator.viewResearcherUrl(ORCID, 13L);
    assertNotNull(r);
    assertEquals(ResearcherUrl.class.getName(), r.getEntity().getClass().getName());
    // Limited am the source of should work
    serviceDelegator.viewResearcherUrl(ORCID, 14L);
    // Limited am not the source of should fail
    try {
        serviceDelegator.viewResearcherUrl(ORCID, 16L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Private am the source of should work
    serviceDelegator.viewResearcherUrl(ORCID, 15L);
    // Private am not the source of should fail
    try {
        serviceDelegator.viewResearcherUrl(ORCID, 17L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) ResearcherUrls(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) NoResultException(javax.persistence.NoResultException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) WrongSourceException(org.orcid.core.exception.WrongSourceException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 50 with Works

use of org.orcid.jaxb.model.v3.dev1.record.summary.Works in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_WorksTest method viewWorksTest.

@Test
public void viewWorksTest() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
    Response r = serviceDelegator.viewWorks(ORCID);
    assertNotNull(r);
    Works works = (Works) r.getEntity();
    assertNotNull(works);
    assertEquals("/0000-0000-0000-0003/works", works.getPath());
    Utils.verifyLastModified(works.getLastModifiedDate());
    assertNotNull(works.getWorkGroup());
    assertNotNull(works.getPath());
    assertEquals(4, works.getWorkGroup().size());
    boolean found1 = false, found2 = false, found3 = false, found4 = false;
    for (WorkGroup workGroup : works.getWorkGroup()) {
        Utils.verifyLastModified(workGroup.getLastModifiedDate());
        assertNotNull(workGroup.getIdentifiers());
        assertNotNull(workGroup.getIdentifiers().getExternalIdentifier());
        assertEquals(1, workGroup.getIdentifiers().getExternalIdentifier().size());
        assertNotNull(workGroup.getWorkSummary());
        assertEquals(1, workGroup.getWorkSummary().size());
        WorkSummary summary = workGroup.getWorkSummary().get(0);
        Utils.verifyLastModified(summary.getLastModifiedDate());
        assertNotNull(summary.getTitle());
        assertNotNull(summary.getTitle().getTitle());
        switch(workGroup.getIdentifiers().getExternalIdentifier().get(0).getValue()) {
            case "1":
                assertEquals("PUBLIC", summary.getTitle().getTitle().getContent());
                assertEquals(Long.valueOf(11), summary.getPutCode());
                found1 = true;
                break;
            case "2":
                assertEquals("LIMITED", summary.getTitle().getTitle().getContent());
                assertEquals(Long.valueOf(12), summary.getPutCode());
                found2 = true;
                break;
            case "3":
                assertEquals("PRIVATE", summary.getTitle().getTitle().getContent());
                assertEquals(Long.valueOf(13), summary.getPutCode());
                found3 = true;
                break;
            case "4":
                assertEquals("SELF LIMITED", summary.getTitle().getTitle().getContent());
                assertEquals(Long.valueOf(14), summary.getPutCode());
                found4 = true;
                break;
            default:
                fail("Invalid external id found: " + workGroup.getIdentifiers().getExternalIdentifier().get(0).getValue());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    assertTrue(found4);
}
Also used : Response(javax.ws.rs.core.Response) WorkGroup(org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup) WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)83 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)65 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)46 FundingSummary (org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary)38 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)37 EmploymentSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EmploymentSummary)37 PeerReviewSummary (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewSummary)37 Works (org.orcid.jaxb.model.v3.dev1.record.summary.Works)37 DistinctionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.DistinctionSummary)35 InvitedPositionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.InvitedPositionSummary)35 MembershipSummary (org.orcid.jaxb.model.v3.dev1.record.summary.MembershipSummary)35 QualificationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.QualificationSummary)35 ServiceSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ServiceSummary)35 DBUnitTest (org.orcid.test.DBUnitTest)21 Response (javax.ws.rs.core.Response)20 WorkGroup (org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup)20 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)17 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)17 Address (org.orcid.jaxb.model.v3.dev1.record.Address)16 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)16