use of org.orcid.listener.exception.LockedRecordException in project ORCID-Source by ORCID.
the class LastModifiedMessageProcessorTest method recordLocked20LockedExceptionTest.
@Test
public void recordLocked20LockedExceptionTest() throws LockedRecordException, JsonProcessingException, AmazonClientException, JAXBException, DeprecatedRecordException {
when(mock_orcid12ApiClient.fetchPublicProfile(Matchers.anyString())).thenReturn(null);
when(mock_orcid20ApiClient.fetchPublicProfile(Matchers.anyString())).thenThrow(new LockedRecordException(new OrcidError()));
String orcid = "0000-0000-0000-0000";
execute(orcid);
verify(mock_exceptionHandler, times(1)).handle20Exception(Matchers.any(), Matchers.any());
}
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 {
when(mock_orcid12ApiClient.fetchPublicProfile(Matchers.anyString())).thenThrow(new LockedRecordException(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);
}
use of org.orcid.listener.exception.LockedRecordException in project ORCID-Source by ORCID.
the class LastModifiedMessageProcessorTest method recordLockedExceptionTest.
@Test
public void recordLockedExceptionTest() throws LockedRecordException, JsonProcessingException, AmazonClientException, JAXBException, DeprecatedRecordException {
when(mock_orcid12ApiClient.fetchPublicProfile(Matchers.anyString())).thenThrow(new LockedRecordException(new OrcidMessage()));
when(mock_orcid20ApiClient.fetchPublicProfile(Matchers.anyString())).thenReturn(null);
String orcid = "0000-0000-0000-0000";
execute(orcid);
verify(mock_exceptionHandler, times(1)).handle12LockedRecordException(Matchers.any(), Matchers.any());
}
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
*/
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);
}
Aggregations