Search in sources :

Example 81 with OrcidError

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) Funding(org.orcid.jaxb.model.record_v2.Funding) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Test(org.junit.Test)

Example 82 with OrcidError

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;
    }
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Record(org.orcid.jaxb.model.record_v2.Record)

Example 83 with OrcidError

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);
        }
    }
}
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 84 with OrcidError

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());
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)65 ClientResponse (com.sun.jersey.api.client.ClientResponse)54 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)43 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)24 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)21 Work (org.orcid.jaxb.model.record_v2.Work)19 Visibility (org.orcid.jaxb.model.common_v2.Visibility)10 BulkElement (org.orcid.jaxb.model.record_v2.BulkElement)9 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)9 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)8 OrcidError (org.orcid.jaxb.model.error_rc4.OrcidError)8 Response (javax.ws.rs.core.Response)7 Locale (java.util.Locale)6 DBUnitTest (org.orcid.test.DBUnitTest)6 Visibility (org.orcid.jaxb.model.common_rc1.Visibility)5 Visibility (org.orcid.jaxb.model.common_rc2.Visibility)5 Visibility (org.orcid.jaxb.model.common_rc4.Visibility)5 Visibility (org.orcid.jaxb.model.common_rc3.Visibility)4 Url (org.orcid.jaxb.model.common_v2.Url)4 ArrayList (java.util.ArrayList)3