Fixing REST exception management

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@131088 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-09-02 13:12:28 +00:00
parent d967f5e6f3
commit 4d2a519963
4 changed files with 19 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import org.gcube.informationsystem.resourceregistry.api.ContextManagement;
import org.gcube.informationsystem.resourceregistry.api.exceptions.InternalException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
@ -41,13 +42,14 @@ public class ContextManager {
* @param parentUUID
* @param name
* @return
* @throws InternalException
* @throws Exception
*/
@PUT
public String create(
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String parentUUID,
@QueryParam(ContextPath.NAME_PARAM) String name)
throws ContextCreationException {
throws ContextCreationException, InternalException {
logger.trace("requested to create context with name : {} ", name);
return contextManager.create(parentUUID, name);
}

View File

@ -5,6 +5,7 @@ import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.gcube.informationsystem.resourceregistry.api.exceptions.InternalException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotAllowedException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ObjectNotFound;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
@ -23,6 +24,10 @@ public class ResourceRegistryExceptionMapper implements ExceptionMapper<Resource
return Response.status(Status.FORBIDDEN).entity(exception.getMessage()).build();
}
if(InternalException.class.isAssignableFrom(exception.getClass())){
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(exception.getMessage()).build();
}
return Response.status(Status.BAD_REQUEST).entity(exception.getMessage()).build();
}

View File

@ -11,12 +11,13 @@ import org.gcube.informationsystem.model.embedded.Header;
import org.gcube.informationsystem.model.orientdb.impl.entity.Context;
import org.gcube.informationsystem.model.relation.IsParentOf;
import org.gcube.informationsystem.resourceregistry.api.ContextManagement;
import org.gcube.informationsystem.resourceregistry.api.exceptions.InternalException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
import org.gcube.informationsystem.resourceregistry.dbinitialization.SecurityContextMapper;
import org.gcube.informationsystem.resourceregistry.dbinitialization.SecurityContext;
import org.gcube.informationsystem.resourceregistry.dbinitialization.SecurityContextMapper;
import org.gcube.informationsystem.resourceregistry.dbinitialization.SecurityContextMapper.PermissionMode;
import org.gcube.informationsystem.resourceregistry.resources.utils.HeaderUtility;
import org.gcube.informationsystem.resourceregistry.resources.utils.Utility;
@ -112,7 +113,7 @@ public class ContextManagementImpl implements ContextManagement {
@Override
public String create(String parentContextUUID, String name)
throws ContextCreationException {
throws ContextCreationException, InternalException {
logger.info("Trying to create {} with name {} and parent {} UUID {}",
org.gcube.informationsystem.model.entity.Context.NAME, name,
@ -170,7 +171,7 @@ public class ContextManagementImpl implements ContextManagement {
} catch (Exception e) {
orientGraph.rollback();
throw new ContextCreationException(e.getMessage());
throw new InternalException(e.getMessage());
}
}

View File

@ -6,6 +6,7 @@ package org.gcube.informationsystem.resourceregistry.resources.impl;
import org.gcube.informationsystem.model.entity.facet.ContactFacet;
import org.gcube.informationsystem.model.entity.resource.Service;
import org.gcube.informationsystem.model.relation.isrelatedto.Runs;
import org.gcube.informationsystem.resourceregistry.api.exceptions.InternalException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextCreationException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
@ -50,7 +51,7 @@ public class ContextManagementImplTest {
public static final String CTX_NAME_B = "B";
public static final String CTX_NAME_C = "C";
protected void invalidCreation(String parentUUID, String name){
protected void invalidCreation(String parentUUID, String name) throws InternalException {
try {
contextManagementImpl.create(parentUUID, name);
throw new RuntimeException("The context " + name + " with parent " + parentUUID + " was already created and MUST throw " + ContextCreationException.class.getSimpleName() + ". This is a bug in your code.");
@ -94,7 +95,7 @@ public class ContextManagementImplTest {
}
@Test
public void simpleTest() throws ContextNotFoundException, ContextException {
public void simpleTest() throws ContextNotFoundException, ContextException, InternalException {
String A_1 = contextManagementImpl.create(null, CTX_NAME_A);
/*
* A(1)
@ -155,7 +156,7 @@ public class ContextManagementImplTest {
//@Test
public void devContextTest() throws ContextNotFoundException, ContextException {
public void devContextTest() throws ContextNotFoundException, ContextException, InternalException {
String gcube = contextManagementImpl.create(null, "gcube");
logger.trace("/gcube : {}", gcube);
String devsec = contextManagementImpl.create(gcube, "devsec");
@ -179,7 +180,7 @@ public class ContextManagementImplTest {
}
@Test
public void readTest() throws ContextNotFoundException, ContextException {
public void readTest() throws ContextNotFoundException, ContextException, InternalException {
String A_1 = contextManagementImpl.create(null, "LLL");
String read = contextManagementImpl.read(A_1);
logger.trace("A : {}", read);
@ -187,7 +188,7 @@ public class ContextManagementImplTest {
}
@Test
public void completeTest() throws ContextNotFoundException, ContextException {
public void completeTest() throws ContextNotFoundException, ContextException, InternalException {
String A_1 = contextManagementImpl.create(null, CTX_NAME_A);
/*
* A(1)
@ -330,7 +331,7 @@ public class ContextManagementImplTest {
@Test
public void moveToRootTest() throws ContextNotFoundException, ContextException {
public void moveToRootTest() throws ContextNotFoundException, ContextException, InternalException {
String A_1 = contextManagementImpl.create(null, CTX_NAME_A);
String A_2 = contextManagementImpl.create(A_1, CTX_NAME_B);
contextManagementImpl.move(null, A_2);