diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/er/entity/EntityManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/er/entity/EntityManagement.java index 33f9012..0f8ab80 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/er/entity/EntityManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/er/entity/EntityManagement.java @@ -186,11 +186,19 @@ public abstract class EntityManagement extends public static EntityManagement getEntityManagement(OrientGraph orientGraph, Vertex vertex) throws ResourceRegistryException { + if(orientGraph==null){ + throw new ResourceRegistryException(OrientGraph.class.getSimpleName() + "instance is null. This is really strage please contact the administrator."); + } + + if(vertex==null){ + throw new ResourceRegistryException(Vertex.class.getSimpleName() + "instance is null. This is really strage please contact the administrator."); + } + OrientVertexType orientVertexType = null; try { orientVertexType = ((OrientVertex) vertex).getType(); }catch (Exception e) { - String error = String.format("Unable to detect type of %s. This is really strage please contact the administrator", vertex.toString()); + String error = String.format("Unable to detect type of %s. This is really strage please contact the administrator.", vertex.toString()); logger.error(error, e); throw new ResourceRegistryException(error); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/er/entity/ResourceManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/er/entity/ResourceManagement.java index 085ffd2..272ef3e 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/er/entity/ResourceManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/er/entity/ResourceManagement.java @@ -62,6 +62,7 @@ public class ResourceManagement extends EntityManagement { * vertex.getEdges(Direction.OUT, ConsistsOf.NAME); * TODO Looks for a different query */ + Iterable edges = getElement().getEdges(Direction.OUT); for (Edge edge : edges) { @SuppressWarnings("rawtypes") @@ -73,13 +74,17 @@ public class ResourceManagement extends EntityManagement { .serializeAsJson(); sourceResource = addConsistsOf(sourceResource, consistsOf); }catch (ResourceRegistryException e) { - logger.error("Unable to correctly serialize {}. It will be excluded from results. This is really strange and should not occur.", edge.toString()); + logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", edge); + throw e; + }catch (Exception e) { + logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", edge); + throw new ResourceRegistryException(e); } } /* * This comment is just to show that IsRelatedTo is not serialized - * by default as desing choice and not because forget + * by default as design choice and not because forget * * else if(orientEdgeType.isSubClassOf(IsRelatedTo.NAME)){ * JSONObject isRelatedTo = relationManagement diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/er/relation/RelationManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/er/relation/RelationManagement.java index e7b3918..2124e47 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/er/relation/RelationManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/er/relation/RelationManagement.java @@ -107,8 +107,12 @@ public abstract class RelationManagement extends .getEntityManagement(orientGraph, target); relation.put(Relation.TARGET_PROPERTY, entityManagement.serializeAsJson()); + } catch (ResourceRegistryException e) { + logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", element, e); + throw e; } catch (Exception e) { - logger.error("Unable to correctly serialize {}. It will be excluded from results. This is really strange and should not occur.", target.toString()); + logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", element, e); + throw new ResourceRegistryException(e); } return relation; @@ -463,6 +467,15 @@ public abstract class RelationManagement extends public static RelationManagement getRelationManagement( OrientGraph orientGraph, Edge edge) throws ResourceRegistryException { + + if(orientGraph==null){ + throw new ResourceRegistryException(OrientGraph.class.getSimpleName() + "instance is null. This is really strage please contact the administrator."); + } + + if(edge==null){ + throw new ResourceRegistryException(Edge.class.getSimpleName() + "instance is null. This is really strage please contact the administrator."); + } + OrientEdgeType orientEdgeType = ((OrientEdge) edge).getType(); RelationManagement relationManagement = null; if (orientEdgeType.isSubClassOf(ConsistsOf.NAME)) { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ERManager.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ERManager.java index 6c42e25..3039d15 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ERManager.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/ERManager.java @@ -329,7 +329,13 @@ public class ERManager { Resource.NAME, uuid, ContextUtility.getCurrentContext()); ResourceManagement resourceManagement = new ResourceManagement(); resourceManagement.setUUID(UUID.fromString(uuid)); - return resourceManagement.addToContext(); + boolean added = resourceManagement.addToContext(); + + resourceManagement = new ResourceManagement(); + resourceManagement.setUUID(UUID.fromString(uuid)); + resourceManagement.read(); + + return added; } /**