Search in sources :

Example 56 with OrcidMessage

use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.

the class LastModifiedMessageProcessorTest method recordStatusMarkAsSentFor12Test.

@Test
public void recordStatusMarkAsSentFor12Test() throws LockedRecordException, DeprecatedRecordException {
    when(mock_orcid12ApiClient.fetchPublicProfile(Matchers.anyString())).thenReturn(new OrcidMessage());
    when(mock_orcid20ApiClient.fetchPublicProfile(Matchers.anyString())).thenReturn(null);
    String orcid = "0000-0000-0000-0000";
    execute(orcid);
    verify(mock_recordStatusManager, times(1)).markAsSent(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
    verify(mock_recordStatusManager, times(0)).markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
    verify(mock_recordStatusManager, times(0)).markAsSent(orcid, AvailableBroker.DUMP_STATUS_2_0_API);
    verify(mock_recordStatusManager, times(0)).markAsFailed(orcid, AvailableBroker.DUMP_STATUS_2_0_API);
}
Also used : OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Test(org.junit.Test)

Example 57 with OrcidMessage

use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.

the class S3MessageProcessor method update_1_2_API.

private void update_1_2_API(String orcid) {
    if (is12IndexingEnabled) {
        try {
            OrcidMessage profile = orcid12ApiClient.fetchPublicProfile(orcid);
            // Update API 1.2
            if (profile != null) {
                s3Updater.updateS3(orcid, profile);
                recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
            }
        } catch (LockedRecordException | DeprecatedRecordException e) {
            try {
                if (e instanceof LockedRecordException) {
                    LOG.error("Record " + orcid + " is locked");
                    exceptionHandler.handle12LockedRecordException(orcid, ((LockedRecordException) e).getOrcidMessage());
                } else {
                    LOG.error("Record " + orcid + " is deprecated");
                    exceptionHandler.handle12DeprecatedRecordException(orcid, ((DeprecatedRecordException) e).getOrcidDeprecated());
                }
                recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
            } catch (JsonProcessingException | AmazonClientException | JAXBException e1) {
                LOG.error("Unable to handle LockedRecordException for record " + orcid, e1);
                recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
            }
        } catch (Exception e) {
            // something else went wrong fetching record from ORCID and
            // threw a
            // runtime exception
            LOG.error("Unable to fetch record " + orcid + " for 1.2 API");
            LOG.error(e.getMessage(), e);
            recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
        }
    }
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JAXBException(javax.xml.bind.JAXBException) AmazonClientException(com.amazonaws.AmazonClientException)

Example 58 with OrcidMessage

use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.

the class VisibilityFilterImplTest method testFilterStripWithVisibilities.

@Test
public void testFilterStripWithVisibilities() throws Exception {
    protectedOrcidMessage = getOrcidMessage("/orcid-protected-full-message-latest.xml");
    publicOrcidMessage = getOrcidMessage("/orcid-stripped-with-visibility-message-latest.xml");
    OrcidMessage orcidMessage = visibilityFilter.filter(cascadeSectionPrivacyToItems(protectedOrcidMessage), Visibility.PUBLIC);
    Diff myDiff = new Diff(publicOrcidMessage.toString(), orcidMessage.toString());
    assertEquals(publicOrcidMessage.toString(), orcidMessage.toString());
    assertTrue(myDiff.toString(), myDiff.similar());
}
Also used : Diff(org.custommonkey.xmlunit.Diff) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Test(org.junit.Test)

Example 59 with OrcidMessage

use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.

the class VisibilityFilterImplTest method testOrcidMessageWithNullOrcidProfile.

@Test
public void testOrcidMessageWithNullOrcidProfile() throws JAXBException {
    OrcidMessage orcidMessage = getOrcidMessage("/orcid-search-result-message.xml");
    OrcidMessage filteredMessage = visibilityFilter.filter(orcidMessage, Visibility.PUBLIC);
    assertNotNull(filteredMessage);
    assertNull(filteredMessage.getOrcidProfile());
    assertEquals(2, filteredMessage.getOrcidSearchResults().getNumFound());
    for (int i = 0; i < filteredMessage.getOrcidSearchResults().getNumFound(); i++) {
        OrcidSearchResult searchResult = filteredMessage.getOrcidSearchResults().getOrcidSearchResult().get(i);
        OrcidBio orcidBio = searchResult.getOrcidProfile().getOrcidBio();
        // check private emails stripped out
        assertEquals(1, orcidBio.getContactDetails().getEmail().size());
    }
}
Also used : OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Test(org.junit.Test)

Example 60 with OrcidMessage

use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.

the class RDFWriterTest method missingCreditName.

@Test
public void missingCreditName() throws Exception {
    ByteArrayOutputStream entityStream = new ByteArrayOutputStream(1024);
    OrcidMessage fakeBio = fakeBio();
    // empty creditName
    fakeBio.getOrcidProfile().getOrcidBio().getPersonalDetails().setCreditName(null);
    rdfWriter.writeTo(fakeBio, OrcidMessage.class, null, null, new MediaType("text", "turtle"), null, entityStream);
    String str = entityStream.toString("utf-8");
    System.out.println(str);
    // Should NOT include a foaf:name
    assertFalse(str.contains("foaf:name"));
    // but do include a concatenation as a label
    assertTrue(str.contains("rdfs:label"));
    assertTrue(str.contains("\"John Doe\""));
    // And family/given
    assertTrue(str.contains("foaf:familyName"));
    assertTrue(str.contains("\"Doe\""));
    assertTrue(str.contains("foaf:givenName"));
    assertTrue(str.contains("\"John\""));
}
Also used : OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) MediaType(javax.ws.rs.core.MediaType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)173 Test (org.junit.Test)108 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)64 DBUnitTest (org.orcid.test.DBUnitTest)49 ClientResponse (com.sun.jersey.api.client.ClientResponse)36 Response (javax.ws.rs.core.Response)26 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)22 Transactional (org.springframework.transaction.annotation.Transactional)22 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)20 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)19 Email (org.orcid.jaxb.model.message.Email)18 BaseTest (org.orcid.core.BaseTest)17 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)16 Affiliation (org.orcid.jaxb.model.message.Affiliation)13 OrcidSearchResult (org.orcid.jaxb.model.message.OrcidSearchResult)12 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)12 JAXBContext (javax.xml.bind.JAXBContext)11 Unmarshaller (javax.xml.bind.Unmarshaller)11 Organization (org.orcid.jaxb.model.message.Organization)11 OrganizationAddress (org.orcid.jaxb.model.message.OrganizationAddress)11