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());
}
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);
}
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);
}
}
}
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);
}
}
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;
}
Aggregations