Search in sources :

Example 6 with DeprecatedRecordException

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

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

the class S3MessageProcessor method update_2_0_API.

private void update_2_0_API(String orcid) {
    if (is20IndexingEnabled) {
        // Update API 2.0
        try {
            Record record = orcid20ApiClient.fetchPublicProfile(orcid);
            if (record != null) {
                s3Updater.updateS3(orcid, record);
                recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_2_0_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.handle20Exception(orcid, error);
                recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_2_0_API);
            } catch (JsonProcessingException | AmazonClientException | JAXBException e1) {
                LOG.error("Unable to handle LockedRecordException for record " + orcid, e1);
                recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_2_0_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 2.0 API");
            LOG.error(e.getMessage(), e);
            recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_2_0_API);
        }
    }
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) Record(org.orcid.jaxb.model.record_v2.Record) 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 8 with DeprecatedRecordException

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

the class LastModifiedMessageProcessorTest method recrodStatusMarkAsSentForDeprecatedRecordException20Test.

@Test
public void recrodStatusMarkAsSentForDeprecatedRecordException20Test() throws LockedRecordException, DeprecatedRecordException {
    when(mock_orcid12ApiClient.fetchPublicProfile(Matchers.anyString())).thenReturn(null);
    when(mock_orcid20ApiClient.fetchPublicProfile(Matchers.anyString())).thenThrow(new DeprecatedRecordException(new OrcidDeprecated()));
    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(0)).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);
}
Also used : OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) Test(org.junit.Test)

Example 9 with DeprecatedRecordException

use of org.orcid.listener.exception.DeprecatedRecordException 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
     */
public OrcidMessage fetchPublicProfile(String orcid) throws LockedRecordException, DeprecatedRecordException {
    WebResource webResource = jerseyClient.resource(baseUri).path(orcid + "/orcid-profile");
    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) {
        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());
        }
    }
    return response.getEntity(OrcidMessage.class);
}
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

DeprecatedRecordException (org.orcid.listener.exception.DeprecatedRecordException)9 OrcidDeprecated (org.orcid.jaxb.model.message.OrcidDeprecated)5 LockedRecordException (org.orcid.listener.exception.LockedRecordException)5 Test (org.junit.Test)4 JAXBException (javax.xml.bind.JAXBException)3 AmazonClientException (com.amazonaws.AmazonClientException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 WebResource (com.sun.jersey.api.client.WebResource)2 Builder (com.sun.jersey.api.client.WebResource.Builder)2 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)2 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)2 ArrayList (java.util.ArrayList)1 FundingGroup (org.orcid.jaxb.model.record.summary_v2.FundingGroup)1 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)1 Funding (org.orcid.jaxb.model.record_v2.Funding)1 Record (org.orcid.jaxb.model.record_v2.Record)1