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
This commit is contained in:
Manuele Simi 2017-12-26 11:56:05 +00:00
parent 8a09c93ce2
commit 05f3c6a810
6 changed files with 150 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,6 @@
/**
* Exception handling in the Resource Management.
* @author Manuele Simi (ISTI - CNR)
*
*/
package org.gcube.resourcemanagement.manager.io.exceptions;