Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return409 on postputdelete #7003

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.orcid.api.common.filter.ApiVersionFilter;
import org.orcid.api.common.util.ApiUtils;
import org.orcid.core.api.OrcidApiConstants;
import org.orcid.core.exception.ApplicationException;
import org.orcid.core.exception.ClientDeactivatedException;
import org.orcid.core.exception.DeactivatedException;
import org.orcid.core.exception.DuplicatedGroupIdRecordException;
Expand Down Expand Up @@ -180,6 +181,7 @@ private Response oAuthErrorResponse(Throwable t) {
return Response.status(error.getResponseStatus()).entity(error).build();
}

@Deprecated
private Response legacyErrorResponse(Throwable t) {
if (OrcidApiException.class.isAssignableFrom(t.getClass())) {
return Response.status(((OrcidApiException) t).getHttpStatus()).build();
Expand Down Expand Up @@ -282,9 +284,7 @@ private OrcidMessage getLegacyOrcidEntity(String prefix, Throwable e) {
}

private Response newStyleErrorResponse(Throwable t, String version) {
if(NotFoundException.class.isAssignableFrom(t.getClass())) {
return getOrcidErrorResponse(t, version);
} else if (WebApplicationException.class.isAssignableFrom(t.getClass())) {
if (WebApplicationException.class.isAssignableFrom(t.getClass())) {
return getOrcidErrorResponse((WebApplicationException) t, version);
} else {
return getOrcidErrorResponse(t, version);
Expand All @@ -310,7 +310,7 @@ private Response getOrcidErrorResponse(Object orcidError, Throwable t) {
int statusCode = 0;

if (org.orcid.jaxb.model.error_v2.OrcidError.class.isAssignableFrom(orcidError.getClass())) {
statusCode = ((org.orcid.jaxb.model.error_v2.OrcidError) orcidError).getResponseCode();
statusCode = ((org.orcid.jaxb.model.error_v2.OrcidError) orcidError).getResponseCode();
} else if (org.orcid.jaxb.model.v3.release.error.OrcidError.class.isAssignableFrom(orcidError.getClass())) {
statusCode = ((org.orcid.jaxb.model.v3.release.error.OrcidError) orcidError).getResponseCode();
}
Expand All @@ -324,7 +324,25 @@ private Response getOrcidErrorResponse(Object orcidError, Throwable t) {
location = getPrimaryRecordLocation(params);
}
}


RequestAttributes reqAttr = RequestContextHolder.getRequestAttributes();
ServletRequestAttributes servlReqAttr = (ServletRequestAttributes)reqAttr;
HttpServletRequest req = servlReqAttr.getRequest();
String requestMethod = (req == null) ? null : req.getMethod();

statusCode = Response.Status.MOVED_PERMANENTLY.getStatusCode();
if(requestMethod != null && !requestMethod.equals("GET")) {
statusCode = Response.Status.CONFLICT.getStatusCode();
// Create a new error object
if(org.orcid.jaxb.model.error_v2.OrcidError.class.isAssignableFrom(orcidError.getClass())) {
org.orcid.jaxb.model.error_v2.OrcidError v2Error = (org.orcid.jaxb.model.error_v2.OrcidError) orcidError;
orcidError = orcidCoreExceptionMapper.getDeprecatedOrcidErrorV2(v2Error.getErrorCode(), statusCode, params);
} else {
org.orcid.jaxb.model.v3.release.error.OrcidError v3Error = (org.orcid.jaxb.model.v3.release.error.OrcidError) orcidError;
orcidError = orcidCoreExceptionMapper.getDeprecatedOrcidErrorV3(v3Error.getErrorCode(), statusCode, params);
}
}

Response response = null;
if (location != null) {
response = Response.status(statusCode).header(LOCATION_HEADER, location).entity(orcidError).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,31 @@ public org.orcid.jaxb.model.error_v2.OrcidError getOrcidErrorV2(int errorCode, i
orcidError.setUserMessage(resolveMessage(messageSource.getMessage("apiError." + errorCode + ".userMessage", null, locale), params));
return orcidError;
}


public org.orcid.jaxb.model.error_v2.OrcidError getDeprecatedOrcidErrorV2(int errorCode, int status, Map<String, String> params) {
Locale locale = localeManager.getLocale();
org.orcid.jaxb.model.error_v2.OrcidError orcidError = new org.orcid.jaxb.model.error_v2.OrcidError();
orcidError.setResponseCode(status);
orcidError.setErrorCode(errorCode);
orcidError.setMoreInfo(resolveMessage(messageSource.getMessage("apiError." + errorCode + ".moreInfo", null, locale), params));
String message =resolveMessage(messageSource.getMessage("apiError." + errorCode + ".userMessage", null, locale), params);
orcidError.setDeveloperMessage(message);
orcidError.setUserMessage(message);
return orcidError;
}

public org.orcid.jaxb.model.v3.release.error.OrcidError getDeprecatedOrcidErrorV3(int errorCode, int status, Map<String, String> params) {
Locale locale = localeManager.getLocale();
org.orcid.jaxb.model.v3.release.error.OrcidError orcidError = new org.orcid.jaxb.model.v3.release.error.OrcidError();
orcidError.setResponseCode(status);
orcidError.setErrorCode(errorCode);
orcidError.setMoreInfo(resolveMessage(messageSource.getMessage("apiError." + errorCode + ".moreInfo", null, locale), params));
String message = resolveMessage(messageSource.getMessage("apiError." + errorCode + ".userMessage", null, locale), params);
orcidError.setDeveloperMessage(message);
orcidError.setUserMessage(message);
return orcidError;
}

public org.orcid.jaxb.model.v3.release.error.OrcidError getOrcidErrorV3(int errorCode, int status, Throwable t) {
Locale locale = localeManager.getLocale();
org.orcid.jaxb.model.v3.release.error.OrcidError orcidError = new org.orcid.jaxb.model.v3.release.error.OrcidError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
*/
public class OrcidDeprecatedException extends ApplicationException {
private static final long serialVersionUID = 1L;

public static final String ORCID = "orcid";
public static final String DEPRECATED_DATE = "deprecated_date";
public static final String DEPRECATED_ORCID = "deprecated_orcid";

public OrcidDeprecatedException() {
super();
}
public OrcidDeprecatedException(Map<String, String> params) {
super(params);
}
super();
}

public OrcidDeprecatedException(Map<String, String> params) {
super(params);
}
}
Loading