use of org.orcid.jaxb.model.error_rc1.OrcidError in project ORCID-Source by ORCID.
the class MemberV2Test method createViewUpdateAndDeleteFunding.
@Test
public void createViewUpdateAndDeleteFunding() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
Funding funding = (Funding) unmarshallFromPath("/record_2.0/samples/read_samples/funding-2.0.xml", Funding.class);
funding.setPutCode(null);
funding.setVisibility(Visibility.PUBLIC);
funding.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID fExtId = new ExternalID();
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
fExtId.setValue("Funding Id " + time);
fExtId.setRelationship(Relationship.SELF);
funding.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createFundingXml(this.getUser1OrcidId(), funding, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0/" + this.getUser1OrcidId() + "/funding/\\d+"));
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Funding gotFunding = getResponse.getEntity(Funding.class);
assertEquals("common:title", gotFunding.getTitle().getTitle().getContent());
assertEquals("common:translated-title", gotFunding.getTitle().getTranslatedTitle().getContent());
assertEquals("en", gotFunding.getTitle().getTranslatedTitle().getLanguageCode());
//Save the original visibility
Visibility originalVisibility = gotFunding.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
//Verify you cant update the visibility
gotFunding.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotFunding);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
OrcidError error = putResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9035), error.getErrorCode());
//Set the visibility again to the initial one
gotFunding.setVisibility(originalVisibility);
gotFunding.getTitle().getTitle().setContent("Updated title");
gotFunding.getTitle().getTranslatedTitle().setContent("Updated translated title");
gotFunding.getTitle().getTranslatedTitle().setLanguageCode("es");
putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotFunding);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Funding gotAfterUpdateFunding = getAfterUpdateResponse.getEntity(Funding.class);
assertEquals("Updated title", gotAfterUpdateFunding.getTitle().getTitle().getContent());
assertEquals("Updated translated title", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getContent());
assertEquals("es", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getLanguageCode());
ClientResponse deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), gotFunding.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.error_rc1.OrcidError in project ORCID-Source by ORCID.
the class S3Updater method updateS3.
public void updateS3(String orcid, Object object) throws JsonProcessingException, AmazonClientException, JAXBException {
// API 1.2
if (OrcidMessage.class.isAssignableFrom(object.getClass())) {
OrcidMessage orcidProfile = (OrcidMessage) object;
putJsonElement(orcid, orcidProfile);
putXmlElement(orcid, orcidProfile);
return;
}
// API 1.2 ERROR
if (OrcidDeprecated.class.isAssignableFrom(object.getClass())) {
OrcidDeprecated error = (OrcidDeprecated) object;
putJsonElement(orcid, error);
putXmlElement(orcid, error);
return;
}
// API 2.0_v2
if (Record.class.isAssignableFrom(object.getClass())) {
Record record = (Record) object;
putJsonElement(orcid, record);
putXmlElement(orcid, record);
return;
}
// API 2.0 Error
if (OrcidError.class.isAssignableFrom(object.getClass())) {
OrcidError error = (OrcidError) object;
putJsonElement(orcid, error);
putXmlElement(orcid, error);
return;
}
}
use of org.orcid.jaxb.model.error_rc1.OrcidError 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);
}
}
}
use of org.orcid.jaxb.model.error_rc1.OrcidError 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());
}
Aggregations