From 74be68d2b6466e0f5d156720ccb99c134473549d Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 17 Feb 2021 11:29:43 +0100 Subject: [PATCH] Revisited serilization --- .../contexts/entities/ContextManagement.java | 10 +++---- .../relations/IsParentOfManagement.java | 13 ++++----- .../instances/base/ElementManagement.java | 19 ++++++------- .../relations/RelationElementManagement.java | 17 ++++++------ .../model/entities/EntityManagement.java | 12 ++++----- .../model/entities/FacetManagement.java | 2 +- .../model/entities/ResourceManagement.java | 4 +-- .../model/relations/RelationManagement.java | 27 ++++++++++--------- .../resourceregistry/query/QueryImpl.java | 2 +- .../EntityTypeDefinitionManagement.java | 4 +-- .../PropertyTypeDefinitionManagement.java | 4 +-- .../RelationTypeDefinitionManagement.java | 6 ++--- 12 files changed, 61 insertions(+), 59 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java index 616c86d..22e03ef 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java @@ -134,7 +134,7 @@ public class ContextManagement extends EntityElementManagement { message.append("A context with name ("); message.append(getName()); message.append(") has been already created as child of "); - message.append(parentContext.serializeSelf().toString()); + message.append(parentContext.getElement().toString()); logger.trace("Checking if {} -> {}", message, select); @@ -161,9 +161,9 @@ public class ContextManagement extends EntityElementManagement { } @Override - public JsonNode createCompleteJsonNode() throws ResourceRegistryException { + protected JsonNode createCompleteJsonNode() throws ResourceRegistryException { - JsonNode context = serializeSelf().deepCopy(); + JsonNode context = serializeSelfAsJsonNode(); int count = 0; Iterable parents = getElement().getEdges(ODirection.IN); @@ -174,7 +174,7 @@ public class ContextManagement extends EntityElementManagement { try { IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument); isParentOfManagement.setElement(edge); - JsonNode isParentOf = isParentOfManagement.serializeAsJson(true, false); + JsonNode isParentOf = isParentOfManagement.serializeAsJsonNode(); if(isParentOf!=null) { ((ObjectNode) context).replace(Context.PARENT_PROPERTY, isParentOf); } @@ -190,7 +190,7 @@ public class ContextManagement extends EntityElementManagement { IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument); isParentOfManagement.setElement(edge); try { - JsonNode isParentOf = isParentOfManagement.createCompleteJsonNode(); + JsonNode isParentOf = isParentOfManagement.serializeAsJsonNode(); context = addRelation(context, isParentOf, Context.CHILDREN_PROPERTY); } catch(ResourceRegistryException e) { logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java index c84ef87..94bdb81 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java @@ -55,26 +55,27 @@ public class IsParentOfManagement extends RelationElementManagement { } } - protected JsonNode createSelfJsonNode() throws ResourceRegistryException { + + private JsonNode createSelfJsonNode() throws ResourceRegistryException { try { ObjectMapper objectMapper = new ObjectMapper(); @@ -294,20 +295,20 @@ public abstract class ElementManagement { } } - public JsonNode serializeSelf() throws ResourceRegistryException { + public JsonNode serializeSelfAsJsonNode() throws ResourceRegistryException { try { if(self==null) { self = createSelfJsonNode(); } - return self; + return self.deepCopy(); } catch(Exception e) { throw new ResourceRegistryException(e); } } - public abstract JsonNode createCompleteJsonNode() throws ResourceRegistryException; + protected abstract JsonNode createCompleteJsonNode() throws ResourceRegistryException; - public JsonNode serializeComplete() throws ResourceRegistryException { + public JsonNode serializeAsJsonNode() throws ResourceRegistryException { try { if(complete==null) { complete = createCompleteJsonNode(); @@ -516,7 +517,7 @@ public abstract class ElementManagement { // TODO Notify to subscriptionNotification - return serializeComplete().toString(); + return serializeAsJsonNode().toString(); } catch(ResourceRegistryException e) { logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid); @@ -553,7 +554,7 @@ public abstract class ElementManagement { // TODO Notify to subscriptionNotification - return serializeComplete().toString(); + return serializeAsJsonNode().toString(); } catch(ResourceRegistryException e) { logger.error("Unable to create {}", accessType.getName()); @@ -586,7 +587,7 @@ public abstract class ElementManagement { getElement(); - return serializeComplete().toString(); + return serializeAsJsonNode().toString(); } catch(ResourceRegistryException e) { logger.error("Unable to read {} with UUID {}", accessType.getName(), uuid); throw e; @@ -618,7 +619,7 @@ public abstract class ElementManagement { // TODO Notify to subscriptionNotification - return serializeComplete().toString(); + return serializeAsJsonNode().toString(); } catch(ResourceRegistryException e) { logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java index 6fbc4cb..440411b 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java @@ -86,22 +86,22 @@ public abstract class RelationElementManagement sourceEntityManagement = getSourceEntityManagement(); - ((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelf()); + ((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelfAsJsonNode()); } if(includeTarget) { EntityElementManagement targetEntityManagement = getTargetEntityManagement(); - ((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeComplete()); + ((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeAsJsonNode()); } } catch(ResourceRegistryException e) { @@ -159,12 +159,11 @@ public abstract class RelationElementManagement {}", elementType, getSourceEntityManagement().serializeSelf().toString(), - getTargetEntityManagement().serializeSelf().toString()); - OVertex source = (OVertex) getSourceEntityManagement().getElement(); OVertex target = (OVertex) getTargetEntityManagement().getElement(); + logger.trace("Going to create {} beetween {} -> {}", elementType, source.toString(), target.toString()); + element = oDatabaseDocument.newEdge(source, target, elementType); updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java index f27cd5e..bbddf61 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java @@ -327,7 +327,7 @@ public abstract class EntityManagement extends EntityElementMa HeaderUtility.updateModifiedByAndLastUpdate(element); element.save(); } - affectedInstances.put(uuid, serializeSelf()); + affectedInstances.put(uuid, serializeSelfAsJsonNode()); return affectedInstances; } catch(ResourceRegistryException e) { throw e; @@ -384,7 +384,7 @@ public abstract class EntityManagement extends EntityElementMa HeaderUtility.updateModifiedByAndLastUpdate(element); element.save(); } - affectedInstances.put(uuid, serializeSelf()); + affectedInstances.put(uuid, serializeSelfAsJsonNode()); return affectedInstances; } catch(ResourceRegistryException e) { throw e; @@ -473,7 +473,7 @@ public abstract class EntityManagement extends EntityElementMa EntityManagement entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(), oDatabaseDocument, (OVertex) vertex); try { - JsonNode jsonNode = entityManagement.serializeComplete(); + JsonNode jsonNode = entityManagement.serializeAsJsonNode(); arrayNode.add(jsonNode); } catch(ResourceRegistryException e) { logger.error("Unable to correctly serialize {}. It will be excluded from results. {}", @@ -647,9 +647,9 @@ public abstract class EntityManagement extends EntityElementMa @SuppressWarnings("rawtypes") RelationManagement relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(), oDatabaseDocument, edge); - jsonNode = relationManagement.createCompleteJsonNode(); + jsonNode = relationManagement.serializeAsJsonNode(); }else { - jsonNode = entityManagement.serializeComplete(); + jsonNode = entityManagement.serializeAsJsonNode(); } arrayNode.add(jsonNode); @@ -760,7 +760,7 @@ public abstract class EntityManagement extends EntityElementMa continue; } } - JsonNode jsonNode = entityManagement.serializeComplete(); + JsonNode jsonNode = entityManagement.serializeAsJsonNode(); arrayNode.add(jsonNode); } catch(ResourceRegistryException e) { logger.error("Unable to correctly serialize {}. It will be excluded from results. {}", diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java index 4d9c05c..b27756a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/FacetManagement.java @@ -41,7 +41,7 @@ public class FacetManagement extends EntityManagement { @Override public JsonNode createCompleteJsonNode() throws ResourceRegistryException { - return serializeSelf().deepCopy(); + return serializeSelfAsJsonNode(); } @Override diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java index 543bce4..feebfea 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java @@ -71,7 +71,7 @@ public class ResourceManagement extends EntityManagement { @Override public JsonNode createCompleteJsonNode() throws ResourceRegistryException { - JsonNode sourceResource = serializeSelf().deepCopy(); + JsonNode sourceResource = serializeSelfAsJsonNode(); /* * Cannot get ConsistsOf edge only because is not polymorphic for a @@ -101,7 +101,7 @@ public class ResourceManagement extends EntityManagement { if(relationManagement instanceof ConsistsOfManagement) { try { - JsonNode consistsOf = relationManagement.serializeAsJson(true, true); + JsonNode consistsOf = relationManagement.serializeAsJsonNode(); sourceResource = addConsistsOf(sourceResource, consistsOf); } catch(ResourceRegistryException e) { logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java index fa26a7f..2083a36 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java @@ -201,22 +201,23 @@ public abstract class RelationManagement sourceEntityManagement = getSourceEntityManagement(); - ((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelf()); + ((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelfAsJsonNode()); } if(includeTarget) { EntityManagement targetEntityManagement = getTargetEntityManagement(); - ((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeComplete()); + ((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeAsJsonNode()); } } catch(ResourceRegistryException e) { @@ -246,7 +247,7 @@ public abstract class RelationManagement exten } @Override - public JsonNode createCompleteJsonNode() throws ResourceRegistryException { - return serializeSelf().deepCopy(); + protected JsonNode createCompleteJsonNode() throws ResourceRegistryException { + return serializeSelfAsJsonNode(); } @Override diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java index fac1947..996c783 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java @@ -73,8 +73,8 @@ public class PropertyTypeDefinitionManagement extends ElementManagement {}", elementType, getSourceEntityManagement().serializeSelf().toString(), - getTargetEntityManagement().serializeSelf().toString()); - OVertex source = (OVertex) getSourceEntityManagement().getElement(); OVertex target = (OVertex) getTargetEntityManagement().getElement(); + logger.trace("Creating {} beetween {} -> {}", elementType, source.toString(), + target.toString()); + element = oDatabaseDocument.newEdge(source, target, elementType); updateProperties(oClass, element, jsonNode, ignoreKeys, ignoreStartWithKeys);