Fixed Exception management
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@131083 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
786ce74b88
commit
42b076f505
|
@ -5,6 +5,9 @@ package org.gcube.informationsystem.resourceregistry.dbinitialization;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.orientechnologies.orient.core.metadata.security.ORestrictedOperation;
|
||||
import com.orientechnologies.orient.core.metadata.security.ORole;
|
||||
import com.orientechnologies.orient.core.metadata.security.OSecurity;
|
||||
|
@ -23,6 +26,9 @@ import com.tinkerpop.blueprints.impls.orient.OrientVertex;
|
|||
*/
|
||||
public class SecurityContext {
|
||||
|
||||
private static Logger logger = LoggerFactory
|
||||
.getLogger(SecurityContext.class);
|
||||
|
||||
public static final String DEFAULT_WRITER_ROLE = "writer";
|
||||
public static final String DEFAULT_READER_ROLE = "reader";
|
||||
|
||||
|
@ -109,6 +115,9 @@ public class SecurityContext {
|
|||
|
||||
public static void deleteSecurityContext(OrientGraph orientGraph,
|
||||
String contextID) {
|
||||
|
||||
logger.trace("Going to remove Security Context (roles and users) with UUID {}", contextID);
|
||||
|
||||
OSecurity oSecurity = orientGraph.getRawGraph().getMetadata()
|
||||
.getSecurity();
|
||||
|
||||
|
@ -124,6 +133,10 @@ public class SecurityContext {
|
|||
oSecurity.dropRole(SecurityContextMapper.getSecurityRoleOrUserName(
|
||||
SecurityContextMapper.PermissionMode.WRITER,
|
||||
SecurityContextMapper.SecurityType.ROLE, contextID));
|
||||
|
||||
orientGraph.commit();
|
||||
|
||||
logger.trace("Security Context (roles and users) with UUID {} successfully removed", contextID);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.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.api.rest.ContextPath;
|
||||
|
@ -46,7 +47,7 @@ public class ContextManager {
|
|||
public String create(
|
||||
@QueryParam(ContextPath.PARENT_CONTEXT_ID_PARAM) String parentUUID,
|
||||
@QueryParam(ContextPath.NAME_PARAM) String name)
|
||||
throws Exception {
|
||||
throws ContextCreationException {
|
||||
logger.trace("requested to create context with name : {} ", name);
|
||||
return contextManager.create(parentUUID, name);
|
||||
}
|
||||
|
@ -60,7 +61,7 @@ public class ContextManager {
|
|||
@DELETE
|
||||
@Path("{" + ID_PATH_PARAM + "}")
|
||||
public String delete(@PathParam(ID_PATH_PARAM) String uuid)
|
||||
throws ContextException {
|
||||
throws ContextNotFoundException, ContextException {
|
||||
logger.trace("requested to delete context with id {} ", uuid);
|
||||
return contextManager.delete(uuid);
|
||||
}
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
package org.gcube.informationsystem.resourceregistry.exceptions;
|
||||
package org.gcube.informationsystem.resourceregistry.resources;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
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.NotAllowedException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ObjectNotFound;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
|
||||
@Provider
|
||||
public class ResourceRegistryExceptionMapper implements ExceptionMapper<ResourceRegistryException>{
|
||||
|
||||
@Override
|
||||
public Response toResponse(ResourceRegistryException exception) {
|
||||
|
||||
if(ObjectNotFound.class.isAssignableFrom(exception.getClass())){
|
||||
return Response.status(Status.NOT_FOUND).entity(exception.getMessage()).build();
|
||||
}
|
||||
|
@ -22,6 +25,6 @@ public class ResourceRegistryExceptionMapper implements ExceptionMapper<Resource
|
|||
|
||||
return Response.status(Status.BAD_REQUEST).entity(exception.getMessage()).build();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -114,6 +114,11 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
public String create(String parentContextUUID, String name)
|
||||
throws ContextCreationException {
|
||||
|
||||
logger.info("Trying to create {} with name {} and parent {} UUID {}",
|
||||
org.gcube.informationsystem.model.entity.Context.NAME, name,
|
||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
||||
parentContextUUID);
|
||||
|
||||
if (parentContextUUID != null && parentContextUUID.compareTo("") == 0) {
|
||||
parentContextUUID = null;
|
||||
}
|
||||
|
@ -153,12 +158,14 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
SecurityContext.addToSecurityContext(orientGraph,
|
||||
context.asVertex(), uuidString);
|
||||
|
||||
logger.trace("Creating {}",
|
||||
Utility.vertexToJsonString(context.asVertex()));
|
||||
String contextJsonString = Utility.vertexToJsonString(context
|
||||
.asVertex());
|
||||
logger.trace("Creating {}", contextJsonString);
|
||||
|
||||
orientGraph.commit();
|
||||
orientGraph.shutdown();
|
||||
|
||||
logger.info("Context {} created", contextJsonString);
|
||||
return uuidString;
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -187,6 +194,10 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
public String rename(String contextUUID, String newName)
|
||||
throws ContextNotFoundException, ContextException {
|
||||
|
||||
logger.info("Trying to rename {} with UUID {} to {}",
|
||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
||||
contextUUID, newName);
|
||||
|
||||
OrientGraph orientGraph = SecurityContextMapper
|
||||
.getSecurityContextFactory(null, PermissionMode.WRITER).getTx();
|
||||
|
||||
|
@ -215,6 +226,9 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
orientGraph.commit();
|
||||
orientGraph.shutdown();
|
||||
|
||||
String contextJsonString = Utility.vertexToJsonString(context);
|
||||
logger.info("Context renamed {}", contextJsonString);
|
||||
|
||||
return contextUUID;
|
||||
}
|
||||
|
||||
|
@ -222,6 +236,13 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
public String move(String newParentUUID, String contextToMoveUUID)
|
||||
throws ContextNotFoundException, ContextException {
|
||||
|
||||
logger.info(
|
||||
"Trying to move {} with UUID {} as child of {} with UUID {}",
|
||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
||||
contextToMoveUUID,
|
||||
org.gcube.informationsystem.model.entity.Context.NAME,
|
||||
newParentUUID);
|
||||
|
||||
OrientGraph orientGraph = SecurityContextMapper
|
||||
.getSecurityContextFactory(null, PermissionMode.WRITER).getTx();
|
||||
Vertex context = getContext(orientGraph, contextToMoveUUID);
|
||||
|
@ -250,6 +271,10 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
orientGraph.commit();
|
||||
orientGraph.shutdown();
|
||||
|
||||
context = getContext(orientGraph, contextToMoveUUID);
|
||||
String contextJsonString = Utility.vertexToJsonString(context);
|
||||
logger.info("Context moved {}", contextJsonString);
|
||||
|
||||
return contextToMoveUUID;
|
||||
}
|
||||
|
||||
|
@ -257,6 +282,9 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
public String delete(String uuid) throws ContextNotFoundException,
|
||||
ContextException {
|
||||
|
||||
logger.info("Trying to remove {} with UUID {}",
|
||||
org.gcube.informationsystem.model.entity.Context.NAME, uuid);
|
||||
|
||||
OrientGraph orientGraph = SecurityContextMapper
|
||||
.getSecurityContextFactory(null, PermissionMode.WRITER).getTx();
|
||||
Vertex context = getContext(orientGraph, uuid);
|
||||
|
@ -276,6 +304,9 @@ public class ContextManagementImpl implements ContextManagement {
|
|||
orientGraph.commit();
|
||||
orientGraph.shutdown();
|
||||
|
||||
logger.info("{} with UUID {} successfully removed",
|
||||
org.gcube.informationsystem.model.entity.Context.NAME, uuid);
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ import org.gcube.informationsystem.resourceregistry.QueryManagerFactory;
|
|||
import org.gcube.informationsystem.resourceregistry.api.EntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.api.Query;
|
||||
import org.gcube.informationsystem.resourceregistry.api.SchemaManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.exceptions.ResourceRegistryExceptionMapper;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.Access;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.ResourceRegistryExceptionMapper;
|
||||
import org.glassfish.hk2.utilities.binding.AbstractBinder;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
|
|
|
@ -6,8 +6,8 @@ import javax.ws.rs.core.Response;
|
|||
|
||||
import org.gcube.informationsystem.resourceregistry.ContextManagerFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.api.ContextManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.exceptions.ResourceRegistryExceptionMapper;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.ContextManager;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.ResourceRegistryExceptionMapper;
|
||||
import org.glassfish.hk2.utilities.binding.AbstractBinder;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
|
|
|
@ -6,8 +6,8 @@ import javax.ws.rs.core.Response;
|
|||
|
||||
import org.gcube.informationsystem.resourceregistry.EntityManagementFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.api.EntityManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.exceptions.ResourceRegistryExceptionMapper;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.EntityManager;
|
||||
import org.gcube.informationsystem.resourceregistry.resources.ResourceRegistryExceptionMapper;
|
||||
import org.glassfish.hk2.utilities.binding.AbstractBinder;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
|
|
Loading…
Reference in New Issue