Fixing log and exception throwing

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@146909 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-04-14 12:37:57 +00:00
parent 4c0e3ef978
commit b559d2f546
4 changed files with 37 additions and 5 deletions

View File

@ -186,11 +186,19 @@ public abstract class EntityManagement<E extends Entity> extends
public static EntityManagement getEntityManagement(OrientGraph orientGraph, public static EntityManagement getEntityManagement(OrientGraph orientGraph,
Vertex vertex) throws ResourceRegistryException { 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; OrientVertexType orientVertexType = null;
try { try {
orientVertexType = ((OrientVertex) vertex).getType(); orientVertexType = ((OrientVertex) vertex).getType();
}catch (Exception e) { }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); logger.error(error, e);
throw new ResourceRegistryException(error); throw new ResourceRegistryException(error);
} }

View File

@ -62,6 +62,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
* vertex.getEdges(Direction.OUT, ConsistsOf.NAME); * vertex.getEdges(Direction.OUT, ConsistsOf.NAME);
* TODO Looks for a different query * TODO Looks for a different query
*/ */
Iterable<Edge> edges = getElement().getEdges(Direction.OUT); Iterable<Edge> edges = getElement().getEdges(Direction.OUT);
for (Edge edge : edges) { for (Edge edge : edges) {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@ -73,13 +74,17 @@ public class ResourceManagement extends EntityManagement<Resource> {
.serializeAsJson(); .serializeAsJson();
sourceResource = addConsistsOf(sourceResource, consistsOf); sourceResource = addConsistsOf(sourceResource, consistsOf);
}catch (ResourceRegistryException e) { }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 * 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)){ * else if(orientEdgeType.isSubClassOf(IsRelatedTo.NAME)){
* JSONObject isRelatedTo = relationManagement * JSONObject isRelatedTo = relationManagement

View File

@ -107,8 +107,12 @@ public abstract class RelationManagement<R extends Relation> extends
.getEntityManagement(orientGraph, target); .getEntityManagement(orientGraph, target);
relation.put(Relation.TARGET_PROPERTY, relation.put(Relation.TARGET_PROPERTY,
entityManagement.serializeAsJson()); 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) { } 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; return relation;
@ -463,6 +467,15 @@ public abstract class RelationManagement<R extends Relation> extends
public static RelationManagement getRelationManagement( public static RelationManagement getRelationManagement(
OrientGraph orientGraph, Edge edge) OrientGraph orientGraph, Edge edge)
throws ResourceRegistryException { 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(); OrientEdgeType orientEdgeType = ((OrientEdge) edge).getType();
RelationManagement relationManagement = null; RelationManagement relationManagement = null;
if (orientEdgeType.isSubClassOf(ConsistsOf.NAME)) { if (orientEdgeType.isSubClassOf(ConsistsOf.NAME)) {

View File

@ -329,7 +329,13 @@ public class ERManager {
Resource.NAME, uuid, ContextUtility.getCurrentContext()); Resource.NAME, uuid, ContextUtility.getCurrentContext());
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString(uuid)); resourceManagement.setUUID(UUID.fromString(uuid));
return resourceManagement.addToContext(); boolean added = resourceManagement.addToContext();
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString(uuid));
resourceManagement.read();
return added;
} }
/** /**