Search in sources :

Example 1 with OrcidIdentifier

use of org.orcid.jaxb.model.common_v2.OrcidIdentifier in project ORCID-Source by ORCID.

the class PublicV2ApiServiceDelegatorTest method validateRecord.

private void validateRecord(Record record) {
    assertNotNull(record);
    assertEquals("/" + ORCID, record.getPath());
    validatePerson(record.getPerson());
    validateActivities(record.getActivitiesSummary());
    assertNotNull(record.getHistory());
    assertEquals(OrcidType.USER, record.getOrcidType());
    assertNotNull(record.getPreferences());
    assertEquals(Locale.EN, record.getPreferences().getLocale());
    History history = record.getHistory();
    assertTrue(history.getClaimed());
    assertNotNull(history.getCompletionDate());
    assertEquals(CreationMethod.INTEGRATION_TEST, history.getCreationMethod());
    assertNull(history.getDeactivationDate());
    assertNotNull(history.getLastModifiedDate());
    assertNotNull(history.getLastModifiedDate().getValue());
    assertNotNull(history.getSource());
    assertEquals("APP-5555555555555555", history.getSource().retrieveSourcePath());
    assertNotNull(history.getSubmissionDate());
    assertNotNull(record.getOrcidIdentifier());
    OrcidIdentifier id = record.getOrcidIdentifier();
    assertEquals("0000-0000-0000-0003", id.getPath());
}
Also used : OrcidIdentifier(org.orcid.jaxb.model.common_v2.OrcidIdentifier) History(org.orcid.jaxb.model.record_v2.History)

Example 2 with OrcidIdentifier

use of org.orcid.jaxb.model.common_v2.OrcidIdentifier in project ORCID-Source by ORCID.

the class PublicV2ApiServiceDelegatorTest method testSearchByQuery.

@Test
public void testSearchByQuery() {
    Search search = new Search();
    Result result = new Result();
    result.setOrcidIdentifier(new OrcidIdentifier("some-orcid-id"));
    search.getResults().add(result);
    OrcidSearchManager orcidSearchManager = Mockito.mock(OrcidSearchManagerImpl.class);
    Mockito.when(orcidSearchManager.findOrcidIds(Matchers.<Map<String, List<String>>>any())).thenReturn(search);
    PublicV2ApiServiceDelegatorImpl delegator = new PublicV2ApiServiceDelegatorImpl();
    ReflectionTestUtils.setField(delegator, "orcidSearchManager", orcidSearchManager);
    OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class);
    Mockito.when(orcidSecurityManager.getClientIdFromAPIRequest()).thenReturn(null);
    ReflectionTestUtils.setField(delegator, "orcidSecurityManager", orcidSecurityManager);
    Response response = delegator.searchByQuery(new HashMap<String, List<String>>());
    assertNotNull(response);
    assertNotNull(response.getEntity());
    assertTrue(response.getEntity() instanceof Search);
    assertEquals(1, ((Search) response.getEntity()).getResults().size());
    assertEquals("some-orcid-id", ((Search) response.getEntity()).getResults().get(0).getOrcidIdentifier().getPath());
}
Also used : PublicV2ApiServiceDelegatorImpl(org.orcid.api.publicV2.server.delegator.impl.PublicV2ApiServiceDelegatorImpl) Response(javax.ws.rs.core.Response) OrcidIdentifier(org.orcid.jaxb.model.common_v2.OrcidIdentifier) Search(org.orcid.jaxb.model.search_v2.Search) OrcidSecurityManager(org.orcid.core.manager.OrcidSecurityManager) List(java.util.List) ArrayList(java.util.ArrayList) OrcidSearchManager(org.orcid.core.manager.OrcidSearchManager) Result(org.orcid.jaxb.model.search_v2.Result) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 3 with OrcidIdentifier

use of org.orcid.jaxb.model.common_v2.OrcidIdentifier in project ORCID-Source by ORCID.

the class MemberV2ApiServiceVersionedDelegatorTest method testSearchByQuery.

@Test
public void testSearchByQuery() {
    MockitoAnnotations.initMocks(this);
    Search search = new Search();
    Result result = new Result();
    result.setOrcidIdentifier(new OrcidIdentifier("some-orcid-id"));
    search.getResults().add(result);
    Response searchResponse = Response.ok(search).build();
    Mockito.when(mockServiceDelegatorNonVersioned.searchByQuery(Matchers.<Map<String, List<String>>>any())).thenReturn(searchResponse);
    TargetProxyHelper.injectIntoProxy(serviceDelegator, "memberV2ApiServiceDelegator", mockServiceDelegatorNonVersioned);
    Response response = serviceDelegator.searchByQuery(new HashMap<String, List<String>>());
    // just testing MemberV2ApiServiceDelegatorImpl's response is returned
    assertNotNull(response);
    assertNotNull(response.getEntity());
    assertTrue(response.getEntity() instanceof Search);
    assertEquals(1, ((Search) response.getEntity()).getResults().size());
    assertEquals("some-orcid-id", ((Search) response.getEntity()).getResults().get(0).getOrcidIdentifier().getPath());
    TargetProxyHelper.injectIntoProxy(serviceDelegator, "memberV2ApiServiceDelegator", serviceDelegatorNonVersioned);
}
Also used : Response(javax.ws.rs.core.Response) OrcidIdentifier(org.orcid.jaxb.model.common_v2.OrcidIdentifier) Search(org.orcid.jaxb.model.search_v2.Search) List(java.util.List) Result(org.orcid.jaxb.model.search_v2.Result) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 4 with OrcidIdentifier

use of org.orcid.jaxb.model.common_v2.OrcidIdentifier in project ORCID-Source by ORCID.

the class MongoMessageProcessorTest method testInsertAndUpsert.

@Test
public void testInsertAndUpsert() throws LockedRecordException, DeprecatedRecordException {
    Record record = new Record();
    record.setOrcidIdentifier(new OrcidIdentifier("http://orcid.org/" + this.orcid));
    ActivitiesSummary sum = new ActivitiesSummary();
    Works works = new Works();
    WorkGroup group = new WorkGroup();
    WorkSummary work = new WorkSummary();
    WorkTitle title = new WorkTitle();
    title.setTitle(new Title("blah"));
    work.setTitle(title);
    group.getWorkSummary().add(work);
    works.getWorkGroup().add(group);
    sum.setWorks(works);
    record.setActivitiesSummary(sum);
    when(mock_orcid20ApiClient.fetchPublicRecord(Matchers.any())).thenReturn(record);
    LastModifiedMessage m = new LastModifiedMessage(this.orcid, new Date());
    mongo.accept(m);
    // test record inserted (has work, no name)
    Document d = new Document();
    d.put("_id", this.orcid);
    assertEquals(col.count(d), 1);
    FindIterable<Document> it = col.find(d);
    Document found = it.first();
    assertEquals(found.get("orcid-identifier", Document.class).get("path"), "http://orcid.org/" + this.orcid);
    List<Document> groups = (List<Document>) found.get("activities-summary", Document.class).get("works", Document.class).get("group");
    List<Document> sums = (List<Document>) groups.get(0).get("work-summary");
    assertEquals(sums.get(0).get("title", Document.class).get("title", Document.class).get("value"), "blah");
    record.setPerson(new Person());
    record.getPerson().setName(new Name());
    record.getPerson().getName().setCreditName(new CreditName());
    record.getPerson().getName().getCreditName().setContent("name");
    ;
    LastModifiedMessage m2 = new LastModifiedMessage(this.orcid, new Date());
    mongo.accept(m2);
    it = col.find(d);
    found = it.first();
    assertEquals(found.get("person", Document.class).get("name", Document.class).get("credit-name", Document.class).get("value"), "name");
}
Also used : LastModifiedMessage(org.orcid.utils.listener.LastModifiedMessage) CreditName(org.orcid.jaxb.model.record_v2.CreditName) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) Title(org.orcid.jaxb.model.common_v2.Title) Document(org.bson.Document) Date(java.util.Date) DeactivationDate(org.orcid.jaxb.model.record_v2.DeactivationDate) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary) CreditName(org.orcid.jaxb.model.record_v2.CreditName) Name(org.orcid.jaxb.model.record_v2.Name) WorkGroup(org.orcid.jaxb.model.record.summary_v2.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) OrcidIdentifier(org.orcid.jaxb.model.common_v2.OrcidIdentifier) Record(org.orcid.jaxb.model.record_v2.Record) List(java.util.List) Works(org.orcid.jaxb.model.record.summary_v2.Works) Person(org.orcid.jaxb.model.record_v2.Person) Test(org.junit.Test)

Example 5 with OrcidIdentifier

use of org.orcid.jaxb.model.common_v2.OrcidIdentifier in project ORCID-Source by ORCID.

the class EmailMessageSenderTest method testCreateDigest.

@Test
public void testCreateDigest() throws IOException {
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidProfile.setOrcidIdentifier(new OrcidIdentifier("0000-0000-0000-0000"));
    OrcidBio orcidBio = new OrcidBio();
    orcidProfile.setOrcidBio(orcidBio);
    PersonalDetails personalDetails = new PersonalDetails();
    orcidBio.setPersonalDetails(personalDetails);
    personalDetails.setGivenNames(new GivenNames("John"));
    personalDetails.setFamilyName(new FamilyName("Watson"));
    OrcidInternal orcidInternal = new OrcidInternal();
    Preferences preferences = new Preferences();
    orcidProfile.setOrcidInternal(orcidInternal);
    orcidInternal.setPreferences(preferences);
    preferences.setSendEmailFrequencyDays("7.0");
    List<Notification> notifications = new ArrayList<>();
    NotificationPermission notification1 = new NotificationPermission();
    notification1.setPutCode(1L);
    Items activities1 = new Items();
    notification1.setItems(activities1);
    activities1.getItems().add(createActivity(ItemType.WORK, "Work 1", "123446/67654"));
    activities1.getItems().add(createActivity(ItemType.WORK, "Work 2", "http://dx.doi.org/123446/67655"));
    notification1.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T13:39:31"));
    notification1.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/12345"));
    Source source1 = new Source();
    source1.setSourceName(new SourceName("Super Institution 1"));
    source1.setSourceClientId(new SourceClientId("APP-5555-5555-5555-5555"));
    notification1.setSource(source1);
    notifications.add(notification1);
    NotificationPermission notification2 = new NotificationPermission();
    notification2.setPutCode(2L);
    Items activities2 = new Items();
    notification2.setItems(activities2);
    activities2.getItems().add(createActivity(ItemType.EMPLOYMENT, "Employment 1 ", "12345/abc"));
    notification2.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-08-17T10:22:15"));
    notification2.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/abc"));
    Source source2 = new Source();
    source2.setSourceName(new SourceName("Super Institution 1"));
    source2.setSourceClientId(new SourceClientId("APP-5555-5555-5555-5555"));
    notification2.setSource(source2);
    notifications.add(notification2);
    NotificationPermission notification3 = new NotificationPermission();
    notification3.setPutCode(3L);
    Items activities3 = new Items();
    notification3.setItems(activities3);
    activities3.getItems().add(createActivity(ItemType.WORK, "Work 3", "12345/def"));
    activities3.getItems().add(createActivity(ItemType.WORK, "Work 4", "12345/ghi"));
    notification3.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T08:53:56"));
    notification3.setAuthorizationUrl(new AuthorizationUrl("https://thirdparty.com/add-to-orcid/def"));
    Source source3 = new Source();
    source3.setSourceName(new SourceName("Lovely Publisher 1"));
    notification3.setSource(source3);
    source3.setSourceClientId(new SourceClientId("APP-ABCD-ABCD-ABCD-ABCD"));
    notifications.add(notification3);
    NotificationCustom notification4 = new NotificationCustom();
    notification4.setPutCode(4L);
    notification4.setSubject("We have release a new messaging feature");
    notification4.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-10T08:53:56"));
    notifications.add(notification4);
    NotificationCustom notification5 = new NotificationCustom();
    notification5.setPutCode(5L);
    notification5.setSubject("The ORCID registry is now available in Orc");
    notification5.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-11T06:42:18"));
    notifications.add(notification5);
    NotificationAmended notification6 = new NotificationAmended();
    notification6.setPutCode(6L);
    notification6.setSubject("Amended by member");
    notification6.setAmendedSection(AmendedSection.FUNDING);
    notification6.setCreatedDate(DateUtils.convertToXMLGregorianCalendar("2014-07-12T18:44:36"));
    notification6.setSource(source3);
    notifications.add(notification6);
    EmailMessage emailMessage = emailMessageSender.createDigest("0000-0000-0000-0000", notifications);
    assertNotNull(emailMessage);
    String expectedBodyText = IOUtils.toString(getClass().getResourceAsStream("example_digest_email_body.txt"));
    String expectedBodyHtml = IOUtils.toString(getClass().getResourceAsStream("example_digest_email_body.html"));
    assertTrue(expectedBodyText.contains("Lovely Publisher 1 has updated recent funding on your ORCID record."));
    assertTrue(expectedBodyHtml.contains("Lovely Publisher 1 has updated recent funding on your ORCID record."));
    assertTrue(expectedBodyText.contains("Super Institution 1: Request to add items"));
    assertTrue(expectedBodyHtml.contains("Super Institution 1: Request to add items"));
    assertTrue(expectedBodyText.contains("/action"));
    assertTrue(expectedBodyHtml.contains("/action"));
    assertEquals("[ORCID] John Watson you have 6 new notifications", emailMessage.getSubject());
}
Also used : OrcidBio(org.orcid.jaxb.model.message.OrcidBio) FamilyName(org.orcid.jaxb.model.message.FamilyName) SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) ArrayList(java.util.ArrayList) SourceName(org.orcid.jaxb.model.common_v2.SourceName) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) Notification(org.orcid.jaxb.model.notification_v2.Notification) Source(org.orcid.jaxb.model.common_v2.Source) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) GivenNames(org.orcid.jaxb.model.message.GivenNames) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Items(org.orcid.jaxb.model.notification.permission_v2.Items) Preferences(org.orcid.jaxb.model.message.Preferences) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

OrcidIdentifier (org.orcid.jaxb.model.common_v2.OrcidIdentifier)13 Test (org.junit.Test)10 Response (javax.ws.rs.core.Response)6 DBUnitTest (org.orcid.test.DBUnitTest)6 List (java.util.List)5 History (org.orcid.jaxb.model.record_v2.History)5 Record (org.orcid.jaxb.model.record_v2.Record)5 ArrayList (java.util.ArrayList)4 Result (org.orcid.jaxb.model.search_v2.Result)4 Search (org.orcid.jaxb.model.search_v2.Search)4 Date (java.util.Date)3 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)3 WorkGroup (org.orcid.jaxb.model.record.summary_v2.WorkGroup)3 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 Document (org.bson.Document)2 OrcidSearchManager (org.orcid.core.manager.OrcidSearchManager)2 OrcidSecurityManager (org.orcid.core.manager.OrcidSecurityManager)2 CreditName (org.orcid.jaxb.model.common_v2.CreditName)2 Title (org.orcid.jaxb.model.common_v2.Title)2