Commit 18a016c6 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Refactoring for error detail endpoint development

parent 75beaddc
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummaryFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
......@@ -8,7 +7,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
public class ContainerNotFoundException extends VoSpaceErrorSummarizableException {
public ContainerNotFoundException(String path) {
super("Container Not Found at path: " + path,
ErrorSummaryFactory.VOSpaceFault.NODE_NOT_FOUND);
super("Path: " + path,
VOSpaceFaultEnum.NODE_NOT_FOUND);
}
}
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummaryFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
......@@ -8,7 +7,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
public class DuplicateNodeException extends VoSpaceErrorSummarizableException {
public DuplicateNodeException(String path) {
super("Duplicate Node at path: " + path,
ErrorSummaryFactory.VOSpaceFault.DUPLICATE_NODE);
super("Path: " + path,
VOSpaceFaultEnum.DUPLICATE_NODE);
}
}
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummary;
public class ErrorSummaryFactory {
public static ErrorSummary newErrorSummary(VOSpaceFaultEnum error, String detailMessage) {
ErrorSummary result = new ErrorSummary();
result.setMessage(error.getFaultRepresentation());
result.setType(error.getType());
if (detailMessage == null || detailMessage.isBlank()) {
result.setHasDetail(false);
} else {
result.setHasDetail(true);
result.setDetailMessage(error.getFaultCaptionForDetails()
+ ". "
+ detailMessage);
}
return result;
}
public static ErrorSummary newErrorSummary(VOSpaceFaultEnum error) {
return newErrorSummary(error, null);
}
public static ErrorSummary newErrorSummary(VoSpaceErrorSummarizableException e)
{
return newErrorSummary(e.getFault(), e.getDetailMessage());
}
}
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummaryFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
......@@ -12,13 +11,13 @@ public class InternalFaultException extends VoSpaceErrorSummarizableException {
private static final Logger LOG = LoggerFactory.getLogger(InternalFaultException.class);
public InternalFaultException(String msg) {
super("InternalFaultException: " + msg,
ErrorSummaryFactory.VOSpaceFault.INTERNAL_FAULT);
super("Description: " + msg,
VOSpaceFaultEnum.INTERNAL_FAULT);
}
public InternalFaultException(Throwable cause) {
super("InternalFaultException: " + getMessage(cause),
ErrorSummaryFactory.VOSpaceFault.INTERNAL_FAULT);
super("Description: " + getMessage(cause),
VOSpaceFaultEnum.INTERNAL_FAULT);
}
private static String getMessage(Throwable cause) {
......
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummaryFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
......@@ -8,6 +7,6 @@ import org.springframework.web.bind.annotation.ResponseStatus;
public class InvalidArgumentException extends VoSpaceErrorSummarizableException {
public InvalidArgumentException(String message) {
super(message, ErrorSummaryFactory.VOSpaceFault.NODE_NOT_FOUND);
super("Description: " + message, VOSpaceFaultEnum.NODE_NOT_FOUND);
}
}
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummaryFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
......@@ -8,18 +7,18 @@ import org.springframework.web.bind.annotation.ResponseStatus;
public class InvalidURIException extends VoSpaceErrorSummarizableException {
public InvalidURIException(String URI, String path) {
super("InvalidURI. Payload node URI: " + URI
super("Payload node URI: " + URI
+ " is not consistent with request path: " + path,
ErrorSummaryFactory.VOSpaceFault.INVALID_URI);
VOSpaceFaultEnum.INVALID_URI);
}
public InvalidURIException(String URI) {
super("InvalidURI. URI: " + URI + " is not in a valid format",
ErrorSummaryFactory.VOSpaceFault.INVALID_URI);
super("URI: " + URI + " is not in a valid format",
VOSpaceFaultEnum.INVALID_URI);
}
public InvalidURIException(IllegalArgumentException ex) {
super("InvalidURI. " + ex.getMessage(),
ErrorSummaryFactory.VOSpaceFault.INVALID_URI);
super("Description: " + ex.getMessage(),
VOSpaceFaultEnum.INVALID_URI);
}
}
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummaryFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
......@@ -8,7 +7,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
public class LinkFoundException extends VoSpaceErrorSummarizableException {
public LinkFoundException(String path) {
super("Link Found at path: " + path,
ErrorSummaryFactory.VOSpaceFault.INVALID_URI);
super("Link Node found at path: " + path,
VOSpaceFaultEnum.INVALID_URI);
}
}
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummaryFactory;
public class NodeBusyException extends VoSpaceErrorSummarizableException {
public NodeBusyException(String path) {
super("Node Busy: at path " + path,
ErrorSummaryFactory.VOSpaceFault.NODE_BUSY);
super("Path: " + path,
VOSpaceFaultEnum.NODE_BUSY);
}
}
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummaryFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
......@@ -8,7 +7,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
public class NodeNotFoundException extends VoSpaceErrorSummarizableException {
public NodeNotFoundException(String path) {
super("NodeNotFound: " + path,
ErrorSummaryFactory.VOSpaceFault.NODE_NOT_FOUND);
super("Path: " + path,
VOSpaceFaultEnum.NODE_NOT_FOUND);
}
}
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummaryFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
......@@ -8,7 +7,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
public class PermissionDeniedException extends VoSpaceErrorSummarizableException {
public PermissionDeniedException(String path) {
super("Permission Denied at path: " + path,
ErrorSummaryFactory.VOSpaceFault.PERMISSION_DENIED);
super("Path: " + path,
VOSpaceFaultEnum.PERMISSION_DENIED);
}
}
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummaryFactory;
public class ProtocolNotSupportedException extends VoSpaceErrorSummarizableException{
public ProtocolNotSupportedException(String protocol) {
super("Protocol Not Supported: " + protocol,
ErrorSummaryFactory.VOSpaceFault.PROTOCOL_NOT_SUPPORTED);
super("Protocol: " + protocol,
VOSpaceFaultEnum.PROTOCOL_NOT_SUPPORTED);
}
}
package it.inaf.oats.vospace.exception;
// NFC: ErrorType usage is not covered in documentation, as far as I can see
// these are tentative default values.
import net.ivoa.xml.uws.v1.ErrorType;
public enum VOSpaceFaultEnum {
// pushto
OPERATION_NOT_SUPPORTED("Operation Not Supported", ErrorType.FATAL, "OperationNotSupported"),
INTERNAL_FAULT("Internal Fault", ErrorType.TRANSIENT, "InternalFault"),
PERMISSION_DENIED("Permission Denied", ErrorType.FATAL, "PermissionDenied"),
VIEW_NOT_SUPPORTED("View Not Supported", ErrorType.FATAL, "ViewNotSupported"),
PROTOCOL_NOT_SUPPORTED("Protocol Not Supported", ErrorType.FATAL, "ProtocolNotSupported"),
INVALID_ARGUMENT("Invalid Argument", ErrorType.FATAL, "InvalidArgument"),
NODE_BUSY("Node Busy", ErrorType.TRANSIENT, "NodeBusy"),
// additional for pullto
INVALID_URI("Invalid URI", ErrorType.FATAL, "InvalidURI"),
INVALID_DATA("Invalid Data", ErrorType.FATAL, "InvalidData"),
// additional for pullfrom
NODE_NOT_FOUND("Node Not Found", ErrorType.FATAL, "NodeNotFound"),
// additional for pushfrom
TRANSFER_FAILED("Transfer Failed", ErrorType.FATAL, "TransferFailed"),
// additional for movenode/copynode
DUPLICATE_NODE("Duplicate Node", ErrorType.FATAL, "DuplicateNode");
private final String faultRepresentation;
private final ErrorType type;
private final String faultCaptionForDetails;
private VOSpaceFaultEnum(String faultRepresentation,
ErrorType type,
String faultCaptionForDetails) {
this.faultRepresentation = faultRepresentation;
this.type = type;
this.faultCaptionForDetails = faultCaptionForDetails;
}
public String getFaultRepresentation() {
return this.faultRepresentation;
}
public ErrorType getType() {
return this.type;
}
public String getFaultCaptionForDetails() {
return faultCaptionForDetails;
}
}
package it.inaf.oats.vospace.exception;
import net.ivoa.xml.uws.v1.ErrorSummaryFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public class VoSpaceErrorSummarizableException extends VoSpaceException {
public abstract class VoSpaceErrorSummarizableException extends VoSpaceException {
ErrorSummaryFactory.VOSpaceFault fault;
VOSpaceFaultEnum fault;
public VoSpaceErrorSummarizableException(String message,
ErrorSummaryFactory.VOSpaceFault fault)
public VoSpaceErrorSummarizableException(String message, VOSpaceFaultEnum fault)
{
super(message);
this.fault = fault;
}
public ErrorSummaryFactory.VOSpaceFault getFault()
public VOSpaceFaultEnum getFault()
{
return this.fault;
}
public String getDetailMessage()
{
return this.getMessage();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment