Search in sources :

Example 11 with LockedRecordException

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

the class LastModifiedMessageProcessorTest method recordLocked20LockedExceptionTest.

@Test
public void recordLocked20LockedExceptionTest() throws LockedRecordException, AmazonClientException, JAXBException, DeprecatedRecordException, IOException {
    when(mock_orcid12ApiClient.fetchPublicProfile(anyString(), anyString())).thenReturn(null);
    when(mock_orcid20ApiClient.fetchPublicRecord(any())).thenThrow(new LockedRecordException(new OrcidError()));
    when(mock_orcid20ApiClient.fetchPublicActivities(any())).thenThrow(new LockedRecordException(new OrcidError()));
    String orcid = "0000-0000-0000-0000";
    execute(orcid);
    verify(mock_exceptionHandler, times(1)).handle20Exception(any(), any());
    verify(mock_exceptionHandler, times(1)).handle20ActivitiesException(any(), any());
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 12 with LockedRecordException

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

the class LastModifiedMessageProcessorTest method recrodStatusMarkAsSentForLockedRecordException12Test.

@Test
public void recrodStatusMarkAsSentForLockedRecordException12Test() throws LockedRecordException, DeprecatedRecordException, IOException {
    when(mock_orcid12ApiClient.fetchPublicProfile(anyString(), anyString())).thenThrow(new LockedRecordException(new OrcidMessage()));
    when(mock_orcid20ApiClient.fetchPublicRecord(any())).thenReturn(null);
    when(mock_orcid20ApiClient.fetchPublicActivities(any())).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);
    verify(mock_recordStatusManager, times(0)).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)

Example 13 with LockedRecordException

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

the class S3MessageProcessor method update_2_0_Activities_API.

private void update_2_0_Activities_API(BaseMessage message) {
    String orcid = message.getOrcid();
    if (is20ActivitiesIndexingEnabled) {
        // Update API 2.0
        try {
            ActivitiesSummary as = orcid20ApiClient.fetchPublicActivities(message);
            if (as != null) {
                s3Updater.updateS3(orcid, as);
                recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_2_0_ACTIVITIES_API);
            }
        } catch (LockedRecordException | DeprecatedRecordException e) {
            try {
                OrcidError error = null;
                if (e instanceof LockedRecordException) {
                    LOG.error("Record " + orcid + " is locked");
                    error = ((LockedRecordException) e).getOrcidError();
                } else {
                    LOG.error("Record " + orcid + " is deprecated");
                    error = ((DeprecatedRecordException) e).getOrcidError();
                }
                exceptionHandler.handle20ActivitiesException(orcid, error);
                recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_2_0_ACTIVITIES_API);
            } catch (Exception e1) {
                LOG.error("Unable to handle LockedRecordException for record " + orcid, e1);
                recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_2_0_ACTIVITIES_API);
            }
        } catch (AmazonClientException e) {
            LOG.error("Unable to fetch activities for record record " + orcid + " for 2.0 API: " + e.getMessage(), e);
            recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
        } catch (Exception e) {
            // something else went wrong fetching activities from ORCID and
            // threw a
            // runtime exception
            LOG.error("Unable to fetch activities for record record " + orcid + " for 2.0 API: " + e.getMessage(), e);
            recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_2_0_ACTIVITIES_API);
        }
    }
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) AmazonClientException(com.amazonaws.AmazonClientException) LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) IOException(java.io.IOException) AmazonClientException(com.amazonaws.AmazonClientException) ActivitiesSummary(org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)

Example 14 with LockedRecordException

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

the class MongoMessageProcessor method updateMongo.

private void updateMongo(BaseMessage message) {
    String orcid = message.getOrcid();
    LOG.info("Updating using Record " + orcid + " in Mongo");
    try {
        Record record = orcid20ApiClient.fetchPublicRecord(message);
        // Remove deactivated records from Mongo
        if (record.getHistory() != null && record.getHistory().getDeactivationDate() != null && record.getHistory().getDeactivationDate().getValue() != null) {
            delete(message.getOrcid(), "deactivated");
            return;
        }
        Document d = Document.parse(mapper.writeValueAsString(record));
        d.put("_id", message.getOrcid());
        Document index = new Document();
        index.put("_id", message.getOrcid());
        col.replaceOne(index, d, upsert);
        recordStatusManager.markAsSent(orcid, AvailableBroker.MONGO);
    } catch (LockedRecordException lre) {
        LOG.error("Record " + orcid + " is locked");
        delete(message.getOrcid(), "locked");
    } catch (DeprecatedRecordException dre) {
        LOG.error("Record " + orcid + " is deprecated");
        delete(message.getOrcid(), "deprecated");
    } catch (Exception e) {
        LOG.error("pants", e);
        recordStatusManager.markAsFailed(message.getOrcid(), AvailableBroker.MONGO);
    }
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) Record(org.orcid.jaxb.model.record_v2.Record) Document(org.bson.Document) LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) MongoException(com.mongodb.MongoException)

Example 15 with LockedRecordException

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

the class Orcid12APIClient method fetchPublicProfile.

/**
 * Fetches the profile from the ORCID public API v1.2
 *
 * @param orcid
 * @return
 * @throws LockedRecordException
 * @throws IOException
 */
public byte[] fetchPublicProfile(String orcid, String mediaType) throws LockedRecordException, DeprecatedRecordException, IOException {
    WebResource webResource = jerseyClient.resource(baseUri).path(orcid + "/orcid-profile");
    webResource.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
    Builder builder = webResource.accept(mediaType).header("Authorization", "Bearer " + accessToken);
    ClientResponse response = builder.get(ClientResponse.class);
    if (response.getStatus() != 200) {
        switch(response.getStatus()) {
            case 301:
                OrcidDeprecated orcidDeprecated = response.getEntity(OrcidDeprecated.class);
                throw new DeprecatedRecordException(orcidDeprecated);
            case 409:
                OrcidMessage orcidMessage = response.getEntity(OrcidMessage.class);
                throw new LockedRecordException(orcidMessage);
            default:
                LOG.error("Unable to fetch public record " + orcid + " on API 1.2 HTTP error code: " + response.getStatus());
                throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
        }
    }
    byte[] elements = IOUtils.toByteArray(response.getEntityInputStream());
    response.close();
    return elements;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) LockedRecordException(org.orcid.listener.exception.LockedRecordException) OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) Builder(com.sun.jersey.api.client.WebResource.Builder) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) WebResource(com.sun.jersey.api.client.WebResource)

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