Search in sources :

Example 1 with OrcidDeprecated

use of org.orcid.jaxb.model.message.OrcidDeprecated in project ORCID-Source by ORCID.

the class LastModifiedMessageProcessorTest method recordLocked20DeprecatedExceptionTest.

@Test
public void recordLocked20DeprecatedExceptionTest() throws LockedRecordException, JsonProcessingException, AmazonClientException, JAXBException, 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_exceptionHandler, times(1)).handle20Exception(Matchers.any(), Matchers.any());
}
Also used : OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) Test(org.junit.Test)

Example 2 with OrcidDeprecated

use of org.orcid.jaxb.model.message.OrcidDeprecated in project ORCID-Source by ORCID.

the class LastModifiedMessageProcessorTest method recrodStatusMarkAsSentForDeprecatedRecordException12Test.

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

Example 3 with OrcidDeprecated

use of org.orcid.jaxb.model.message.OrcidDeprecated in project ORCID-Source by ORCID.

the class LastModifiedMessageProcessorTest method deprecatedRecordExceptionTest.

@Test
public void deprecatedRecordExceptionTest() throws LockedRecordException, JsonProcessingException, AmazonClientException, JAXBException, DeprecatedRecordException {
    when(mock_orcid12ApiClient.fetchPublicProfile(Matchers.anyString())).thenThrow(new DeprecatedRecordException(new OrcidDeprecated()));
    when(mock_orcid20ApiClient.fetchPublicProfile(Matchers.anyString())).thenReturn(null);
    String orcid = "0000-0000-0000-0000";
    execute(orcid);
    verify(mock_exceptionHandler, times(1)).handle12DeprecatedRecordException(Matchers.any(), Matchers.any());
}
Also used : OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) Test(org.junit.Test)

Example 4 with OrcidDeprecated

use of org.orcid.jaxb.model.message.OrcidDeprecated 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)

Example 5 with OrcidDeprecated

use of org.orcid.jaxb.model.message.OrcidDeprecated in project ORCID-Source by ORCID.

the class OrcidExceptionMapper method legacyErrorResponse.

private Response legacyErrorResponse(Throwable t) {
    if (OrcidApiException.class.isAssignableFrom(t.getClass())) {
        return ((OrcidApiException) t).getResponse();
    } else if (OrcidValidationException.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacyOrcidEntity("Bad Request: ", t);
        return Response.status(Response.Status.BAD_REQUEST).entity(entity).build();
    } else if (NotFoundException.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacyOrcidEntity("Please specify a version number (1.2 or higher) : ", t);
        return Response.status(OrcidCoreExceptionMapper.getHttpStatusAndErrorCode(t).getKey()).entity(entity).build();
    } else if (WebApplicationException.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacy500OrcidEntity(t);
        WebApplicationException webException = (WebApplicationException) t;
        return Response.status(webException.getResponse().getStatus()).entity(entity).build();
    } else if (AuthenticationException.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacyOrcidEntity("Authentication problem : ", t);
        return Response.status(Response.Status.UNAUTHORIZED).entity(entity).build();
    } else if (OAuth2Exception.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacyOrcidEntity("OAuth2 problem : ", t);
        return Response.status(Response.Status.UNAUTHORIZED).entity(entity).build();
    } else if (OrcidInvalidScopeException.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacyOrcidEntity("OAuth2 problem : ", t);
        return Response.status(Response.Status.UNAUTHORIZED).entity(entity).build();
    } else if (SecurityException.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacyOrcidEntity("Security problem : ", t);
        return Response.status(Response.Status.FORBIDDEN).entity(entity).build();
    } else if (IllegalStateException.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacyOrcidEntity("Illegal state : ", t);
        return Response.status(Response.Status.FORBIDDEN).entity(entity).build();
    } else if (IllegalArgumentException.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacyOrcidEntity("Bad Request : ", t);
        return Response.status(Response.Status.BAD_REQUEST).entity(entity).build();
    } else if (OrcidDeprecatedException.class.isAssignableFrom(t.getClass())) {
        OrcidDeprecatedException exception = (OrcidDeprecatedException) t;
        OrcidDeprecated depreciatedError = new OrcidDeprecated();
        Map<String, String> params = exception.getParams();
        String location = null;
        if (params != null) {
            if (params.containsKey(OrcidDeprecatedException.ORCID)) {
                PrimaryRecord pr = new PrimaryRecord();
                pr.setOrcid(new Orcid(params.get(OrcidDeprecatedException.ORCID)));
                depreciatedError.setPrimaryRecord(pr);
                location = getPrimaryRecordLocation(params);
            }
            if (params.containsKey(OrcidDeprecatedException.DEPRECATED_DATE)) {
                DeprecatedDate dd = new DeprecatedDate();
                String dateString = params.get(OrcidDeprecatedException.DEPRECATED_DATE);
                dd.setValue(DateUtils.convertToXMLGregorianCalendar(dateString, false));
                depreciatedError.setDate(dd);
            }
        }
        Response response = null;
        if (location != null) {
            response = Response.status(Response.Status.MOVED_PERMANENTLY).header(LOCATION_HEADER, location).entity(depreciatedError).build();
        } else {
            response = Response.status(Response.Status.MOVED_PERMANENTLY).entity(depreciatedError).build();
        }
        return response;
    } else if (LockedException.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacyOrcidEntity("Account locked : ", t);
        return Response.status(Response.Status.CONFLICT).entity(entity).build();
    } else if (NoResultException.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacyOrcidEntity("Not found : ", t);
        return Response.status(Response.Status.NOT_FOUND).entity(entity).build();
    } else if (ExceedMaxNumberOfElementsException.class.isAssignableFrom(t.getClass())) {
        OrcidMessage entity = getLegacyOrcidEntity("This version of the API does not support adding more than 10,000 works to a record. Please consider using the 2.0 API.", null);
        return Response.status(Response.Status.CONFLICT).entity(entity).build();
    } else {
        OrcidMessage entity = getLegacy500OrcidEntity(t);
        return Response.status(OrcidCoreExceptionMapper.getHttpStatusAndErrorCode(t).getKey()).entity(entity).build();
    }
}
Also used : PrimaryRecord(org.orcid.jaxb.model.message.PrimaryRecord) LockedException(org.orcid.core.security.aop.LockedException) WebApplicationException(javax.ws.rs.WebApplicationException) ExceedMaxNumberOfElementsException(org.orcid.core.exception.ExceedMaxNumberOfElementsException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) Response(javax.ws.rs.core.Response) OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated) Orcid(org.orcid.jaxb.model.message.Orcid) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidDeprecatedException(org.orcid.core.exception.OrcidDeprecatedException) DeprecatedDate(org.orcid.jaxb.model.message.DeprecatedDate) OrcidApiException(org.orcid.core.exception.OrcidApiException) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception)

Aggregations

OrcidDeprecated (org.orcid.jaxb.model.message.OrcidDeprecated)9 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)5 DeprecatedRecordException (org.orcid.listener.exception.DeprecatedRecordException)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)2 Email (org.orcid.jaxb.model.message.Email)2 ExternalIdReference (org.orcid.jaxb.model.message.ExternalIdReference)2 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)2 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)2 Funding (org.orcid.jaxb.model.message.Funding)2 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)2 LastModifiedDate (org.orcid.jaxb.model.message.LastModifiedDate)2 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)2 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)2 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)2 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)2 OtherName (org.orcid.jaxb.model.message.OtherName)2