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
This commit is contained in:
Manuele Simi 2018-01-21 20:34:21 +00:00
parent 865c2255f7
commit 97e9f88f70
3 changed files with 18 additions and 12 deletions

View File

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

View File

@ -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) {

View File

@ -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))
@ -59,6 +59,13 @@ public abstract class RequestToResourceRegistry {
return response;
}
/**
* @return the context client
*/
ResourceRegistryContextClient getContextClient() {
return resourceRegistryContextClient;
}
/**
* Submits the request to the RR.
*