diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java index f13b151..9ec61a7 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java @@ -48,16 +48,11 @@ public class ContextManagement extends EntityManagement { if(++count>1) { throw new ContextException("A " + Context.NAME + " can not have more than one parent"); } - ContextManagement contextManagement = new ContextManagement(orientGraph); - contextManagement.setElement(edge.getVertex(Direction.OUT)); - JSONObject parent = contextManagement.serializeSelfOnly(); try { IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph); isParentOfManagement.setElement(edge); - JSONObject isParentOf = isParentOfManagement.serializeAsJson(false,false); - parent = addRelation(parent, isParentOf, Context.CHILDREN_PROPERTY); - - context.putOpt(Context.PARENT_PROPERTY, parent); + JSONObject isParentOf = isParentOfManagement.serializeAsJson(true,false); + context.putOpt(Context.PARENT_PROPERTY, isParentOf); } catch (JSONException e) { logger.error("Unable to correctly serialize {}. This is really strange and should not occur.", edge); throw new ContextException(""); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java index d1f1ac2..5f232c6 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java @@ -32,14 +32,14 @@ public class ContextManagementTest { logger.debug("{}", ISMapper.marshal(context)); - logger.debug("Parent : {}", ISMapper.marshal(context.getParent())); + logger.debug("Parent : {}", ISMapper.marshal(context.getParent().getSource())); for(IsParentOf isParentOf : context.getChildren()){ - logger.debug("Children : {}", ISMapper.marshal(isParentOf)); + logger.debug("Children : {}", ISMapper.marshal(isParentOf.getTarget())); } - Context parent = context.getParent(); //.getSource(); + Context parent = context.getParent().getSource(); Context sameOfContext = parent.getChildren().get(0).getTarget(); Assert.assertTrue(context==sameOfContext); @@ -47,6 +47,8 @@ public class ContextManagementTest { List> children = context.getChildren(); for(IsParentOf child : children) { Assert.assertTrue(child.getSource()==context); + Context childContext = child.getTarget(); + Assert.assertTrue(childContext.getParent().getSource()==context); } } @@ -73,6 +75,14 @@ public class ContextManagementTest { devNext.addChild(NextNext); logger.debug("NextNext : {}", ISMapper.marshal(NextNext)); + + logger.debug("------------------------------------"); + + logger.debug("gcube : {}", ISMapper.marshal(gcube)); + logger.debug("devsec : {}", ISMapper.marshal(devsec)); + logger.debug("devVRE : {}", ISMapper.marshal(devVRE)); + logger.debug("devNext : {}", ISMapper.marshal(devNext)); + logger.debug("NextNext : {}", ISMapper.marshal(NextNext)); } }