fixing HTTP response codes

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@146755 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-04-11 13:22:53 +00:00
parent 4eca4513da
commit 6e4e0fe259
2 changed files with 27 additions and 7 deletions

View File

@ -441,7 +441,8 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
} }
public boolean exists() throws ERNotFoundException, ResourceRegistryException { public boolean exists() throws ERNotFoundException,
ERAvailableInAnotherContextException, ResourceRegistryException {
try { try {
orientGraph = ContextUtility.getActualSecurityContextGraph(PermissionMode.READER); orientGraph = ContextUtility.getActualSecurityContextGraph(PermissionMode.READER);
@ -460,7 +461,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
} }
public String read() throws ERNotFoundException, public String read() throws ERNotFoundException,
ResourceRegistryException { ERAvailableInAnotherContextException, ResourceRegistryException {
try { try {
orientGraph = ContextUtility orientGraph = ContextUtility
.getActualSecurityContextGraph(PermissionMode.READER); .getActualSecurityContextGraph(PermissionMode.READER);
@ -480,7 +481,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
} }
public String update() throws ERNotFoundException, public String update() throws ERNotFoundException,
ResourceRegistryException { ERAvailableInAnotherContextException, ResourceRegistryException {
try { try {
orientGraph = ContextUtility orientGraph = ContextUtility
@ -510,7 +511,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
} }
public boolean delete() throws ERNotFoundException, public boolean delete() throws ERNotFoundException,
ResourceRegistryException { ERAvailableInAnotherContextException, ResourceRegistryException {
logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid); logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
try { try {

View File

@ -9,9 +9,12 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; 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.ResourceInitializer;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; 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.er.ERNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
@ -79,8 +82,9 @@ public class Access {
@HEAD @HEAD
@Path(AccessPath.INSTANCE_PATH_PART + "/" + "{" + TYPE_PATH_PARAM + "}" @Path(AccessPath.INSTANCE_PATH_PART + "/" + "{" + TYPE_PATH_PARAM + "}"
+ "/{" + ID_PATH_PARAM + "}") + "/{" + ID_PATH_PARAM + "}")
public void exists(@PathParam(TYPE_PATH_PARAM) String type, public Response exists(@PathParam(TYPE_PATH_PARAM) String type,
@PathParam(ID_PATH_PARAM) String id) throws ERNotFoundException, ResourceRegistryException { @PathParam(ID_PATH_PARAM) String id) throws ERNotFoundException,
ERAvailableInAnotherContextException, ResourceRegistryException {
logger.info("Requested to check if {} with id {} exists", type, id); logger.info("Requested to check if {} with id {} exists", type, id);
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ERManagement erManagement = ERManagement.getERManagement(type); ERManagement erManagement = ERManagement.getERManagement(type);
@ -91,7 +95,22 @@ public class Access {
throw new ResourceRegistryException(e); throw new ResourceRegistryException(e);
} }
erManagement.setUUID(uuid); 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;
}
} }
/* /*