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:
parent
865c2255f7
commit
97e9f88f70
|
@ -4,6 +4,7 @@ import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
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.codeexceptions.WebCodeException;
|
||||||
import org.gcube.resourcemanagement.manager.io.rs.RMDeleteContextCode;
|
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()
|
* @see org.gcube.resourcemanagement.manager.webapp.context.RequestToResourceRegistry#validate()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public RequestToResourceRegistry validate() throws Exception {
|
public void validate() throws LocalCodeException {
|
||||||
if (!new Queries().contextExists(context, resourceRegistryContextClient)) {
|
if (!new Queries().contextExists(context, this.getContextClient())) {
|
||||||
ResponseFromResourceRegistry.fromException(new WebCodeException(RMDeleteContextCode.CONTEXT_DOES_NOT_EXIST));
|
throw new LocalCodeException(RMDeleteContextCode.CONTEXT_DOES_NOT_EXIST);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -42,7 +42,7 @@ public final class DeleteRequest extends RequestToResourceRegistry {
|
||||||
@Override
|
@Override
|
||||||
protected ResponseFromResourceRegistry send() {
|
protected ResponseFromResourceRegistry send() {
|
||||||
try {
|
try {
|
||||||
boolean deleted = resourceRegistryContextClient.delete(context);
|
boolean deleted = this.getContextClient().delete(context);
|
||||||
if (!deleted) {
|
if (!deleted) {
|
||||||
ResponseFromResourceRegistry.fromException(new WebCodeException(RMDeleteContextCode.GENERIC_ERROR_FROM_RR));
|
ResponseFromResourceRegistry.fromException(new WebCodeException(RMDeleteContextCode.GENERIC_ERROR_FROM_RR));
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,8 @@ final class Queries {
|
||||||
try {
|
try {
|
||||||
return client(registryClient).read(uuid);
|
return client(registryClient).read(uuid);
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
e.printStackTrace();
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResourceRegistryContextClient client(ResourceRegistryContextClient ... registryClient) {
|
private ResourceRegistryContextClient client(ResourceRegistryContextClient ... registryClient) {
|
||||||
|
|
|
@ -5,8 +5,8 @@ import java.util.Objects;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient;
|
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientFactory;
|
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientFactory;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientImpl;
|
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.codeexceptions.WebCodeException;
|
||||||
import org.gcube.resourcemanagement.manager.io.rs.RMCreateContextCode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base request to an operation exposed by the Resource Registry.
|
* Base request to an operation exposed by the Resource Registry.
|
||||||
|
@ -31,16 +31,16 @@ public abstract class RequestToResourceRegistry {
|
||||||
/**
|
/**
|
||||||
* Validates the request.
|
* 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() {
|
public ResponseFromResourceRegistry submit() {
|
||||||
try {
|
try {
|
||||||
this.validate();
|
this.validate();
|
||||||
} catch (Exception e) {
|
} catch (LocalCodeException e) {
|
||||||
ResponseFromResourceRegistry response = ResponseFromResourceRegistry.
|
ResponseFromResourceRegistry response = ResponseFromResourceRegistry.
|
||||||
fromException(new WebCodeException(RMCreateContextCode.INVALID_REQUEST_FOR_RR));
|
fromException(new WebCodeException(e));
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
if (Objects.isNull(this.resourceRegistryContextClient))
|
if (Objects.isNull(this.resourceRegistryContextClient))
|
||||||
|
@ -58,6 +58,13 @@ public abstract class RequestToResourceRegistry {
|
||||||
// by default, returns the response as it is
|
// by default, returns the response as it is
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the context client
|
||||||
|
*/
|
||||||
|
ResourceRegistryContextClient getContextClient() {
|
||||||
|
return resourceRegistryContextClient;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submits the request to the RR.
|
* Submits the request to the RR.
|
||||||
|
|
Loading…
Reference in New Issue