Fixing serilization

This commit is contained in:
Luca Frosini 2021-02-17 15:16:25 +01:00
parent 74be68d2b6
commit 2597379ad4
2 changed files with 5 additions and 29 deletions

View File

@ -174,7 +174,7 @@ public class ContextManagement extends EntityElementManagement<Context> {
try { try {
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument); IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
isParentOfManagement.setElement(edge); isParentOfManagement.setElement(edge);
JsonNode isParentOf = isParentOfManagement.serializeAsJsonNode(); JsonNode isParentOf = isParentOfManagement.createCompleteJsonNode(true, false);
if(isParentOf!=null) { if(isParentOf!=null) {
((ObjectNode) context).replace(Context.PARENT_PROPERTY, isParentOf); ((ObjectNode) context).replace(Context.PARENT_PROPERTY, isParentOf);
} }
@ -405,7 +405,7 @@ public class ContextManagement extends EntityElementManagement<Context> {
ContextManagement contextManagement = new ContextManagement(); ContextManagement contextManagement = new ContextManagement();
contextManagement.setElement((OVertex) vertex); contextManagement.setElement((OVertex) vertex);
try { try {
JsonNode jsonObject = contextManagement.createCompleteJsonNode(); JsonNode jsonObject = contextManagement.serializeAsJsonNode();
arrayNode.add(jsonObject); arrayNode.add(jsonObject);
} catch(ResourceRegistryException e) { } catch(ResourceRegistryException e) {
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}", logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",

View File

@ -89,11 +89,7 @@ public abstract class ElementManagement<El extends OElement> {
protected JsonNode jsonNode; protected JsonNode jsonNode;
protected OClass oClass; protected OClass oClass;
protected String elementType; protected String elementType;
protected JsonNode self;
protected JsonNode complete;
protected El element; protected El element;
protected boolean reload; protected boolean reload;
@ -297,10 +293,7 @@ public abstract class ElementManagement<El extends OElement> {
public JsonNode serializeSelfAsJsonNode() throws ResourceRegistryException { public JsonNode serializeSelfAsJsonNode() throws ResourceRegistryException {
try { try {
if(self==null) { return createSelfJsonNode();
self = createSelfJsonNode();
}
return self.deepCopy();
} catch(Exception e) { } catch(Exception e) {
throw new ResourceRegistryException(e); throw new ResourceRegistryException(e);
} }
@ -310,10 +303,7 @@ public abstract class ElementManagement<El extends OElement> {
public JsonNode serializeAsJsonNode() throws ResourceRegistryException { public JsonNode serializeAsJsonNode() throws ResourceRegistryException {
try { try {
if(complete==null) { return createCompleteJsonNode();
complete = createCompleteJsonNode();
}
return complete;
} catch(Exception e) { } catch(Exception e) {
throw new ResourceRegistryException(e); throw new ResourceRegistryException(e);
} }
@ -416,8 +406,6 @@ public abstract class ElementManagement<El extends OElement> {
if(uuid == null) { if(uuid == null) {
throw new NotFoundException("null UUID does not allow to retrieve the Element"); throw new NotFoundException("null UUID does not allow to retrieve the Element");
} }
return Utility.getElementByUUID(oDatabaseDocument, elementType == null ? accessType.getName() : elementType, uuid, return Utility.getElementByUUID(oDatabaseDocument, elementType == null ? accessType.getName() : elementType, uuid,
elementClass); elementClass);
} catch(NotFoundException e) { } catch(NotFoundException e) {
@ -463,9 +451,7 @@ public abstract class ElementManagement<El extends OElement> {
} }
} }
} }
public boolean exists() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { public boolean exists() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try { try {
@ -682,8 +668,6 @@ public abstract class ElementManagement<El extends OElement> {
if(current!=null) { if(current!=null) {
current.activateOnCurrentThread(); current.activateOnCurrentThread();
} }
} }
} }
@ -730,8 +714,6 @@ public abstract class ElementManagement<El extends OElement> {
public ArrayNode getContextsAsArrayNode(ObjectMapper objectMapper) throws NotFoundException, ContextException, ResourceRegistryException { public ArrayNode getContextsAsArrayNode(ObjectMapper objectMapper) throws NotFoundException, ContextException, ResourceRegistryException {
try { try {
Set<String> contexts = getContextsSet(); Set<String> contexts = getContextsSet();
ArrayNode arrayNode = objectMapper.createArrayNode(); ArrayNode arrayNode = objectMapper.createArrayNode();
for(String contextUUID : contexts) { for(String contextUUID : contexts) {
arrayNode.add(contextUUID); arrayNode.add(contextUUID);
@ -784,8 +766,6 @@ public abstract class ElementManagement<El extends OElement> {
return value.asBoolean(); return value.asBoolean();
case NULL: case NULL:
break; break;
case NUMBER: case NUMBER:
@ -831,9 +811,7 @@ public abstract class ElementManagement<El extends OElement> {
} }
Iterator<Entry<String,JsonNode>> fields = jsonNode.fields(); Iterator<Entry<String,JsonNode>> fields = jsonNode.fields();
OUTER_WHILE: while(fields.hasNext()) { OUTER_WHILE: while(fields.hasNext()) {
Entry<String,JsonNode> entry = fields.next(); Entry<String,JsonNode> entry = fields.next();
@ -991,9 +969,7 @@ public abstract class ElementManagement<El extends OElement> {
if(object instanceof Collection) { if(object instanceof Collection) {
Collection<?> collection = (Collection<?>) object; Collection<?> collection = (Collection<?>) object;
ArrayNode arrayNode = objectMapper.createArrayNode(); ArrayNode arrayNode = objectMapper.createArrayNode();
for(Object o : collection) { for(Object o : collection) {
Object obj = getPropertyForJson("PLACEHOLDER", o); Object obj = getPropertyForJson("PLACEHOLDER", o);