From 97e9f88f7015a96dd6d9f9ed2b7eaf9ec48fa93a Mon Sep 17 00:00:00 2001 From: "manuele.simi" Date: Sun, 21 Jan 2018 20:34:21 +0000 Subject: [PATCH] Use LocalCodeExceptions across delete and create contexts. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@162405 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../manager/webapp/context/DeleteRequest.java | 10 +++++----- .../manager/webapp/context/Queries.java | 3 +-- .../context/RequestToResourceRegistry.java | 17 ++++++++++++----- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/DeleteRequest.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/DeleteRequest.java index b9fce92..ec10d97 100644 --- a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/DeleteRequest.java +++ b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/DeleteRequest.java @@ -4,6 +4,7 @@ import java.util.Objects; import java.util.UUID; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.gcube.resourcemanagement.manager.io.codeexceptions.LocalCodeException; import org.gcube.resourcemanagement.manager.io.codeexceptions.WebCodeException; import org.gcube.resourcemanagement.manager.io.rs.RMDeleteContextCode; @@ -29,11 +30,10 @@ public final class DeleteRequest extends RequestToResourceRegistry { * @see org.gcube.resourcemanagement.manager.webapp.context.RequestToResourceRegistry#validate() */ @Override - public RequestToResourceRegistry validate() throws Exception { - if (!new Queries().contextExists(context, resourceRegistryContextClient)) { - ResponseFromResourceRegistry.fromException(new WebCodeException(RMDeleteContextCode.CONTEXT_DOES_NOT_EXIST)); + public void validate() throws LocalCodeException { + if (!new Queries().contextExists(context, this.getContextClient())) { + throw new LocalCodeException(RMDeleteContextCode.CONTEXT_DOES_NOT_EXIST); } - return null; } /* (non-Javadoc) @@ -42,7 +42,7 @@ public final class DeleteRequest extends RequestToResourceRegistry { @Override protected ResponseFromResourceRegistry send() { try { - boolean deleted = resourceRegistryContextClient.delete(context); + boolean deleted = this.getContextClient().delete(context); if (!deleted) { ResponseFromResourceRegistry.fromException(new WebCodeException(RMDeleteContextCode.GENERIC_ERROR_FROM_RR)); } diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java index 0db4ff6..f6e08e0 100644 --- a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java +++ b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java @@ -47,9 +47,8 @@ final class Queries { try { return client(registryClient).read(uuid); } catch (ResourceRegistryException e) { - e.printStackTrace(); + return null; } - return null; } private ResourceRegistryContextClient client(ResourceRegistryContextClient ... registryClient) { diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/RequestToResourceRegistry.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/RequestToResourceRegistry.java index 958721b..dfc4249 100644 --- a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/RequestToResourceRegistry.java +++ b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/RequestToResourceRegistry.java @@ -5,8 +5,8 @@ import java.util.Objects; import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient; import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientFactory; import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientImpl; +import org.gcube.resourcemanagement.manager.io.codeexceptions.LocalCodeException; import org.gcube.resourcemanagement.manager.io.codeexceptions.WebCodeException; -import org.gcube.resourcemanagement.manager.io.rs.RMCreateContextCode; /** * Base request to an operation exposed by the Resource Registry. @@ -31,16 +31,16 @@ public abstract class RequestToResourceRegistry { /** * Validates the request. * - * @return the response from the service. + * @throws LocalCodeException */ - abstract public RequestToResourceRegistry validate() throws Exception; + abstract public void validate() throws LocalCodeException; public ResponseFromResourceRegistry submit() { try { this.validate(); - } catch (Exception e) { + } catch (LocalCodeException e) { ResponseFromResourceRegistry response = ResponseFromResourceRegistry. - fromException(new WebCodeException(RMCreateContextCode.INVALID_REQUEST_FOR_RR)); + fromException(new WebCodeException(e)); return response; } if (Objects.isNull(this.resourceRegistryContextClient)) @@ -58,6 +58,13 @@ public abstract class RequestToResourceRegistry { // by default, returns the response as it is return response; } + + /** + * @return the context client + */ + ResourceRegistryContextClient getContextClient() { + return resourceRegistryContextClient; + } /** * Submits the request to the RR.