Search in sources :

Example 1 with LockedRecordException

use of org.orcid.listener.exception.LockedRecordException in project ORCID-Source by ORCID.

the class SolrMessageProcessor method updateSolrIndex.

private void updateSolrIndex(String orcid) {
    LOG.info("Updating using Record " + orcid + " in SOLR index");
    if (!isSolrIndexingEnabled) {
        LOG.info("Solr indexing is disabled");
        return;
    }
    try {
        org.orcid.jaxb.model.record_v2.Record record = orcid20ApiClient.fetchPublicProfile(orcid);
        //get detailed funding so we can discover org name and id
        List<Funding> fundings = new ArrayList<Funding>();
        if (record.getActivitiesSummary() != null && record.getActivitiesSummary().getFundings() != null && record.getActivitiesSummary().getFundings().getFundingGroup() != null) {
            for (FundingGroup group : record.getActivitiesSummary().getFundings().getFundingGroup()) {
                if (group.getFundingSummary() != null) {
                    for (FundingSummary f : group.getFundingSummary()) {
                        fundings.add(orcid20ApiClient.fetchFunding(record.getOrcidIdentifier().getPath(), f.getPutCode()));
                    }
                }
            }
        }
        solrUpdater.persist(recordConv.convert(record, fundings));
        recordStatusManager.markAsSent(orcid, AvailableBroker.SOLR);
    } catch (LockedRecordException lre) {
        LOG.error("Record " + orcid + " is locked");
        solrUpdater.updateSolrIndexForLockedOrDeprecatedRecord(orcid, solrUpdater.retrieveLastModified(orcid));
        recordStatusManager.markAsSent(orcid, AvailableBroker.SOLR);
    } catch (DeprecatedRecordException dre) {
        LOG.error("Record " + orcid + " is deprecated");
        solrUpdater.updateSolrIndexForLockedOrDeprecatedRecord(orcid, solrUpdater.retrieveLastModified(orcid));
        recordStatusManager.markAsSent(orcid, AvailableBroker.SOLR);
    } catch (Exception e) {
        LOG.error("Unable to fetch record " + orcid + " for SOLR");
        LOG.error(e.getMessage(), e);
        recordStatusManager.markAsFailed(orcid, AvailableBroker.SOLR);
    }
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) Funding(org.orcid.jaxb.model.record_v2.Funding) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) ArrayList(java.util.ArrayList) FundingSummary(org.orcid.jaxb.model.record.summary_v2.FundingSummary) FundingGroup(org.orcid.jaxb.model.record.summary_v2.FundingGroup) LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) JAXBException(javax.xml.bind.JAXBException)

Example 2 with LockedRecordException

use of org.orcid.listener.exception.LockedRecordException 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 3 with LockedRecordException

use of org.orcid.listener.exception.LockedRecordException in project ORCID-Source by ORCID.

the class Orcid20APIClient method fetchPublicProfile.

/**
     * Fetches the profile from the ORCID public API v1.2
     * 
     * @param orcid
     * @return
     */
public Record fetchPublicProfile(String orcid) throws LockedRecordException, DeprecatedRecordException {
    WebResource webResource = jerseyClient.resource(baseUri).path(orcid + "/record");
    webResource.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
    Builder builder = webResource.accept(MediaType.APPLICATION_XML).header("Authorization", "Bearer " + accessToken);
    ClientResponse response = builder.get(ClientResponse.class);
    if (response.getStatus() != 200) {
        OrcidError orcidError = null;
        switch(response.getStatus()) {
            case 301:
                orcidError = response.getEntity(OrcidError.class);
                throw new DeprecatedRecordException(orcidError);
            case 409:
                orcidError = response.getEntity(OrcidError.class);
                throw new LockedRecordException(orcidError);
            default:
                LOG.error("Unable to fetch public record " + orcid + " on API 2.0 HTTP error code: " + response.getStatus());
                throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
        }
    }
    return response.getEntity(Record.class);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) Builder(com.sun.jersey.api.client.WebResource.Builder) WebResource(com.sun.jersey.api.client.WebResource)

Example 4 with LockedRecordException

use of org.orcid.listener.exception.LockedRecordException in project ORCID-Source by ORCID.

the class SolrMessageProcessor method updateSolrIndex.

private void updateSolrIndex(BaseMessage message) {
    String orcid = message.getOrcid();
    LOG.info("Updating using Record " + orcid + " in SOLR index");
    if (!isSolrIndexingEnabled) {
        LOG.info("Solr indexing is disabled");
        return;
    }
    try {
        org.orcid.jaxb.model.record_v2.Record record = orcid20ApiClient.fetchPublicRecord(message);
        // Remove deactivated records from SOLR index
        if (record.getHistory() != null && record.getHistory().getDeactivationDate() != null && record.getHistory().getDeactivationDate().getValue() != null) {
            solrUpdater.processInvalidRecord(orcid);
            recordStatusManager.markAsSent(orcid, AvailableBroker.SOLR);
            return;
        }
        // get detailed funding so we can discover org name and id
        List<Funding> fundings = new ArrayList<Funding>();
        if (record.getActivitiesSummary() != null && record.getActivitiesSummary().getFundings() != null && record.getActivitiesSummary().getFundings().getFundingGroup() != null) {
            for (FundingGroup group : record.getActivitiesSummary().getFundings().getFundingGroup()) {
                if (group.getFundingSummary() != null) {
                    for (FundingSummary f : group.getFundingSummary()) {
                        fundings.add(orcid20ApiClient.fetchFunding(record.getOrcidIdentifier().getPath(), f.getPutCode()));
                    }
                }
            }
        }
        solrUpdater.persist(recordConv.convert(record, fundings));
        recordStatusManager.markAsSent(orcid, AvailableBroker.SOLR);
    } catch (LockedRecordException lre) {
        LOG.error("Record " + orcid + " is locked");
        solrUpdater.processInvalidRecord(orcid);
        recordStatusManager.markAsSent(orcid, AvailableBroker.SOLR);
    } catch (DeprecatedRecordException dre) {
        LOG.error("Record " + orcid + " is deprecated");
        solrUpdater.processInvalidRecord(orcid);
        recordStatusManager.markAsSent(orcid, AvailableBroker.SOLR);
    } catch (Exception e) {
        LOG.error("Unable to fetch record " + orcid + " for SOLR");
        LOG.error(e.getMessage(), e);
        recordStatusManager.markAsFailed(orcid, AvailableBroker.SOLR);
    }
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) Funding(org.orcid.jaxb.model.record_v2.Funding) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) ArrayList(java.util.ArrayList) FundingGroup(org.orcid.jaxb.model.record.summary_v2.FundingGroup) LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) JAXBException(javax.xml.bind.JAXBException) FundingSummary(org.orcid.jaxb.model.record.summary_v2.FundingSummary)

Example 5 with LockedRecordException

use of org.orcid.listener.exception.LockedRecordException in project ORCID-Source by ORCID.

the class LastModifiedMessageProcessorTest method recrodStatusMarkAsSentForLockedRecordException20Test.

@Test
public void recrodStatusMarkAsSentForLockedRecordException20Test() throws LockedRecordException, DeprecatedRecordException, IOException {
    when(mock_orcid12ApiClient.fetchPublicProfile(anyString(), anyString())).thenReturn(null);
    when(mock_orcid20ApiClient.fetchPublicRecord(any())).thenThrow(new LockedRecordException(new OrcidMessage()));
    when(mock_orcid20ApiClient.fetchPublicActivities(any())).thenThrow(new LockedRecordException(new OrcidMessage()));
    String orcid = "0000-0000-0000-0000";
    execute(orcid);
    verify(mock_recordStatusManager, times(0)).markAsSent(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
    verify(mock_recordStatusManager, times(1)).markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
    verify(mock_recordStatusManager, times(1)).markAsSent(orcid, AvailableBroker.DUMP_STATUS_2_0_API);
    verify(mock_recordStatusManager, times(0)).markAsFailed(orcid, AvailableBroker.DUMP_STATUS_2_0_API);
    verify(mock_recordStatusManager, times(1)).markAsSent(orcid, AvailableBroker.DUMP_STATUS_2_0_ACTIVITIES_API);
    verify(mock_recordStatusManager, times(0)).markAsFailed(orcid, AvailableBroker.DUMP_STATUS_2_0_ACTIVITIES_API);
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

LockedRecordException (org.orcid.listener.exception.LockedRecordException)15 DeprecatedRecordException (org.orcid.listener.exception.DeprecatedRecordException)10 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)7 Test (org.junit.Test)5 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)5 AmazonClientException (com.amazonaws.AmazonClientException)4 JAXBException (javax.xml.bind.JAXBException)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Record (org.orcid.jaxb.model.record_v2.Record)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 WebResource (com.sun.jersey.api.client.WebResource)3 Builder (com.sun.jersey.api.client.WebResource.Builder)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Document (org.bson.Document)2 FundingGroup (org.orcid.jaxb.model.record.summary_v2.FundingGroup)2 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)2 Funding (org.orcid.jaxb.model.record_v2.Funding)2 CacheBuilder (com.google.common.cache.CacheBuilder)1