diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java index 71e1400..d3f8cdd 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/er/ERManagement.java @@ -441,7 +441,8 @@ public abstract class ERManagement { } - public boolean exists() throws ERNotFoundException, ResourceRegistryException { + public boolean exists() throws ERNotFoundException, + ERAvailableInAnotherContextException, ResourceRegistryException { try { orientGraph = ContextUtility.getActualSecurityContextGraph(PermissionMode.READER); @@ -460,7 +461,7 @@ public abstract class ERManagement { } public String read() throws ERNotFoundException, - ResourceRegistryException { + ERAvailableInAnotherContextException, ResourceRegistryException { try { orientGraph = ContextUtility .getActualSecurityContextGraph(PermissionMode.READER); @@ -480,7 +481,7 @@ public abstract class ERManagement { } public String update() throws ERNotFoundException, - ResourceRegistryException { + ERAvailableInAnotherContextException, ResourceRegistryException { try { orientGraph = ContextUtility @@ -510,7 +511,7 @@ public abstract class ERManagement { } public boolean delete() throws ERNotFoundException, - ResourceRegistryException { + ERAvailableInAnotherContextException, ResourceRegistryException { logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid); try { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java index d9faec3..ba4e732 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java @@ -9,9 +9,12 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; import org.gcube.informationsystem.resourceregistry.ResourceInitializer; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; @@ -79,8 +82,9 @@ public class Access { @HEAD @Path(AccessPath.INSTANCE_PATH_PART + "/" + "{" + TYPE_PATH_PARAM + "}" + "/{" + ID_PATH_PARAM + "}") - public void exists(@PathParam(TYPE_PATH_PARAM) String type, - @PathParam(ID_PATH_PARAM) String id) throws ERNotFoundException, ResourceRegistryException { + public Response exists(@PathParam(TYPE_PATH_PARAM) String type, + @PathParam(ID_PATH_PARAM) String id) throws ERNotFoundException, + ERAvailableInAnotherContextException, ResourceRegistryException { logger.info("Requested to check if {} with id {} exists", type, id); @SuppressWarnings("rawtypes") ERManagement erManagement = ERManagement.getERManagement(type); @@ -91,7 +95,22 @@ public class Access { throw new ResourceRegistryException(e); } erManagement.setUUID(uuid); - erManagement.exists(); + try { + boolean found = erManagement.exists(); + if(found){ + return Response.status(Status.NO_CONTENT).build(); + }else{ + // This code should never be reached due to exception management + // anyway adding it for safety reason + return Response.status(Status.NOT_FOUND).build(); + } + } catch (ERNotFoundException e) { + return Response.status(Status.NOT_FOUND).build(); + } catch (ERAvailableInAnotherContextException e) { + return Response.status(Status.CONFLICT).build(); + } catch (ResourceRegistryException e) { + throw e; + } } /*