From 05f3c6a810ae5c3c4d044f12213069de6f6325a2 Mon Sep 17 00:00:00 2001 From: "manuele.simi" Date: Tue, 26 Dec 2017 11:56:05 +0000 Subject: [PATCH] Rename package to exceptions. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@161904 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../manager/io/exceptions/CodeException.java | 30 +++++++++++++++++ .../manager/io/exceptions/ErrorCode.java | 21 ++++++++++++ .../manager/io/exceptions/ExceptionCode.java | 31 +++++++++++++++++ .../manager/io/exceptions/RMCode.java | 33 +++++++++++++++++++ .../manager/io/exceptions/RMException.java | 29 ++++++++++++++++ .../manager/io/exceptions/package-info.java | 6 ++++ 6 files changed, 150 insertions(+) create mode 100644 io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/CodeException.java create mode 100644 io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/ErrorCode.java create mode 100644 io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/ExceptionCode.java create mode 100644 io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/RMCode.java create mode 100644 io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/RMException.java create mode 100644 io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/package-info.java diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/CodeException.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/CodeException.java new file mode 100644 index 0000000..ea35334 --- /dev/null +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/CodeException.java @@ -0,0 +1,30 @@ +package org.gcube.resourcemanagement.manager.io.exceptions; + +/** + * Exception returned by the Resource Manager. + * + * @author Manuele Simi (ISTI CNR) + * + */ +public class CodeException extends Exception { + + private static final long serialVersionUID = 333945715086602250L; + + private final int errorCode; + private final String errorMsg; + + public CodeException(RMCode code) { + super(); + this.errorMsg = code.getMessage(); + this.errorCode = code.getId(); + } + + public int getErrorCode() { + return errorCode; + } + + public String getErrorMsg() { + return errorMsg; + } + +} diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/ErrorCode.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/ErrorCode.java new file mode 100644 index 0000000..9a1a194 --- /dev/null +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/ErrorCode.java @@ -0,0 +1,21 @@ +package org.gcube.resourcemanagement.manager.io.exceptions; + +/** + * Interface for error codes. + * + * @author Manuele Simi (ISTI CNR) + * + */ +public interface ErrorCode { + + /** + * Identifier of the code. + */ + public int getId(); + + /** + * The message associated to the code + * @return the message + */ + public String getMessage(); +} diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/ExceptionCode.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/ExceptionCode.java new file mode 100644 index 0000000..ce28bd9 --- /dev/null +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/ExceptionCode.java @@ -0,0 +1,31 @@ +package org.gcube.resourcemanagement.manager.exception; + +/** + * Exception codes handled with {@link RMException}. + * + * @author Manuele Simi (ISTI CNR) + * + */ +public enum ExceptionCode implements ErrorCode { + + INVALID_REQUEST(0, "The request is invalid"), + MISSING_PARAMETER(1, "Required query parameter is missing"), + MISSING_HEADER(2, "Required header is missing"), + CONTEXT_ALREADY_EXIST(3, "Required header is missing"); + + private final int id; + private final String msg; + + ExceptionCode(int id, String msg) { + this.id = id; + this.msg = msg; + } + + public int getId() { + return this.id; + } + + public String getMsg() { + return this.msg; + } +} diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/RMCode.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/RMCode.java new file mode 100644 index 0000000..193259b --- /dev/null +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/RMCode.java @@ -0,0 +1,33 @@ +package org.gcube.resourcemanagement.manager.io.exceptions; + +/** + * Exception codes handled with {@link CodeException}. + * + * @author Manuele Simi (ISTI CNR) + * + */ +public enum RMCode implements ErrorCode { + + INVALID_REQUEST(0, "The request is invalid"), + MISSING_PARAMETER(1,"Required query parameter is missing"), + MISSING_HEADER(2, "Required header is missing"), + CONTEXT_ALREADY_EXIST(3, "Required header is missing"), + INVALID_REQUEST_FOR_RR(4, "Failed to validate the request. The request was not submitted to the Resource Registry."), + GENERIC_ERROR_FROM_RR(0, "The Resource Registry returned an error."); + + private final int id; + private final String msg; + + private RMCode(int id, String msg) { + this.id = id; + this.msg = msg; + } + + public int getId() { + return this.id; + } + + public String getMessage() { + return this.msg; + } +} diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/RMException.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/RMException.java new file mode 100644 index 0000000..466f9ad --- /dev/null +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/RMException.java @@ -0,0 +1,29 @@ +package org.gcube.resourcemanagement.manager.exception; + +/** + * Exception returned by the Resource Manager. + * + * @author Manuele Simi (ISTI CNR) + * + */ +public class RMException extends Exception { + + private static final long serialVersionUID = 333945715086602250L; + + private final int errorCode; + private final String errorMsg; + + public RMException(ExceptionCode code) { + this.errorMsg = code.getMsg(); + this.errorCode = code.getId(); + } + + public int getErrorCode() { + return errorCode; + } + + public String getErrorMsg() { + return errorMsg; + } + +} diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/package-info.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/package-info.java new file mode 100644 index 0000000..fb4958e --- /dev/null +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/exceptions/package-info.java @@ -0,0 +1,6 @@ +/** + * Exception handling in the Resource Management. + * @author Manuele Simi (ISTI - CNR) + * + */ +package org.gcube.resourcemanagement.manager.io.exceptions; \ No newline at end of file