Rivisiting element serilization
This commit is contained in:
parent
fe37358ea7
commit
845ddde2c8
|
@ -134,7 +134,7 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
message.append("A context with name (");
|
message.append("A context with name (");
|
||||||
message.append(getName());
|
message.append(getName());
|
||||||
message.append(") has been already created as child of ");
|
message.append(") has been already created as child of ");
|
||||||
message.append(parentContext.serializeSelfOnly().toString());
|
message.append(parentContext.serializeSelf().toString());
|
||||||
|
|
||||||
logger.trace("Checking if {} -> {}", message, select);
|
logger.trace("Checking if {} -> {}", message, select);
|
||||||
|
|
||||||
|
@ -161,14 +161,9 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String serialize() throws ResourceRegistryException {
|
public JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||||
return serializeAsJson().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
JsonNode context = serializeSelf().deepCopy();
|
||||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
|
||||||
|
|
||||||
JsonNode context = serializeSelfOnly();
|
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
Iterable<OEdge> parents = getElement().getEdges(ODirection.IN);
|
Iterable<OEdge> parents = getElement().getEdges(ODirection.IN);
|
||||||
|
@ -195,7 +190,7 @@ public class ContextManagement extends EntityElementManagement<Context> {
|
||||||
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
|
||||||
isParentOfManagement.setElement(edge);
|
isParentOfManagement.setElement(edge);
|
||||||
try {
|
try {
|
||||||
JsonNode isParentOf = isParentOfManagement.serializeAsJson();
|
JsonNode isParentOf = isParentOfManagement.createCompleteJsonNode();
|
||||||
context = addRelation(context, isParentOf, Context.CHILDREN_PROPERTY);
|
context = addRelation(context, isParentOf, Context.CHILDREN_PROPERTY);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
logger.error("Unable to correctly serialize {}. {}", edge, Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
|
@ -410,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.serializeAsJson();
|
JsonNode jsonObject = contextManagement.createCompleteJsonNode();
|
||||||
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. {}",
|
||||||
|
|
|
@ -55,26 +55,26 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
public JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||||
return serializeAsJson(false, true);
|
return serializeAsJson(false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonNode serializeAsJson(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
|
public JsonNode serializeAsJson(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
|
||||||
JsonNode relation = serializeSelfOnly();
|
JsonNode relation = serializeSelf();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OVertex source = element.getVertex(ODirection.OUT);
|
OVertex source = element.getVertex(ODirection.OUT);
|
||||||
ContextManagement sourceContextManagement = new ContextManagement(oDatabaseDocument);
|
ContextManagement sourceContextManagement = new ContextManagement(oDatabaseDocument);
|
||||||
sourceContextManagement.setElement(source);
|
sourceContextManagement.setElement(source);
|
||||||
if(includeSource) {
|
if(includeSource) {
|
||||||
((ObjectNode)relation).replace(Relation.SOURCE_PROPERTY, sourceContextManagement.serializeSelfOnly());
|
((ObjectNode)relation).replace(Relation.SOURCE_PROPERTY, sourceContextManagement.serializeSelf());
|
||||||
}
|
}
|
||||||
|
|
||||||
OVertex target = element.getVertex(ODirection.IN);
|
OVertex target = element.getVertex(ODirection.IN);
|
||||||
ContextManagement targetContextManagement = new ContextManagement(oDatabaseDocument);
|
ContextManagement targetContextManagement = new ContextManagement(oDatabaseDocument);
|
||||||
targetContextManagement.setElement(target);
|
targetContextManagement.setElement(target);
|
||||||
if(includeTarget) {
|
if(includeTarget) {
|
||||||
((ObjectNode)relation).replace(Relation.TARGET_PROPERTY, targetContextManagement.serializeSelfOnly());
|
((ObjectNode)relation).replace(Relation.TARGET_PROPERTY, targetContextManagement.serializeSelf());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
|
|
|
@ -90,6 +90,10 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
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;
|
||||||
|
|
||||||
|
@ -258,19 +262,61 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonNode serializeSelfOnly() throws ResourceRegistryException {
|
protected JsonNode createSelfJsonNode() throws ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
return toJsonNode();
|
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||||
|
OElement element = getElement();
|
||||||
|
Set<String> keys = element.getPropertyNames();
|
||||||
|
for(String key : keys) {
|
||||||
|
Object object = element.getProperty(key);
|
||||||
|
JsonNode jsonNode = getPropertyForJson(key, object);
|
||||||
|
if(jsonNode != null) {
|
||||||
|
objectNode.replace(key, jsonNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OClass oClass = getOClass();
|
||||||
|
String type = oClass.getName();
|
||||||
|
objectNode.put(Element.CLASS_PROPERTY, type);
|
||||||
|
|
||||||
|
Collection<String> superClasses = getSuperclasses();
|
||||||
|
ArrayNode arrayNode = objectMapper.valueToTree(superClasses);
|
||||||
|
|
||||||
|
objectNode.replace(Element.SUPERCLASSES_PROPERTY, arrayNode);
|
||||||
|
|
||||||
|
return objectNode;
|
||||||
|
} catch(ResourceRegistryException e) {
|
||||||
|
throw e;
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new ResourceRegistryException("Error while serializing " + getElement().toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonNode serializeSelf() throws ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
if(self==null) {
|
||||||
|
self = createSelfJsonNode();
|
||||||
|
}
|
||||||
|
return self;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String serialize() throws ResourceRegistryException {
|
public abstract JsonNode createCompleteJsonNode() throws ResourceRegistryException;
|
||||||
return serializeAsJson().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract JsonNode serializeAsJson() throws ResourceRegistryException;
|
public JsonNode serializeComplete() throws ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
if(complete==null) {
|
||||||
|
complete = createCompleteJsonNode();
|
||||||
|
}
|
||||||
|
return complete;
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract El reallyCreate() throws AlreadyPresentException, ResourceRegistryException;
|
protected abstract El reallyCreate() throws AlreadyPresentException, ResourceRegistryException;
|
||||||
|
|
||||||
|
@ -369,6 +415,8 @@ 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) {
|
||||||
|
@ -415,6 +463,8 @@ 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 {
|
||||||
|
@ -466,7 +516,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
// TODO Notify to subscriptionNotification
|
// TODO Notify to subscriptionNotification
|
||||||
|
|
||||||
return serialize();
|
return serializeComplete().toString();
|
||||||
|
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid);
|
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid);
|
||||||
|
@ -503,7 +553,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
// TODO Notify to subscriptionNotification
|
// TODO Notify to subscriptionNotification
|
||||||
|
|
||||||
return serialize();
|
return serializeComplete().toString();
|
||||||
|
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
logger.error("Unable to create {}", accessType.getName());
|
logger.error("Unable to create {}", accessType.getName());
|
||||||
|
@ -536,8 +586,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
jsonNode = serializeAsJson();
|
return serializeComplete().toString();
|
||||||
return jsonNode.toString();
|
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
logger.error("Unable to read {} with UUID {}", accessType.getName(), uuid);
|
logger.error("Unable to read {} with UUID {}", accessType.getName(), uuid);
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -569,7 +618,7 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
// TODO Notify to subscriptionNotification
|
// TODO Notify to subscriptionNotification
|
||||||
|
|
||||||
return serialize();
|
return serializeComplete().toString();
|
||||||
|
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid);
|
logger.error("Unable to update {} with UUID {}", accessType.getName(), uuid);
|
||||||
|
@ -632,6 +681,8 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
|
|
||||||
if(current!=null) {
|
if(current!=null) {
|
||||||
current.activateOnCurrentThread();
|
current.activateOnCurrentThread();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -678,6 +729,8 @@ 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);
|
||||||
|
@ -730,6 +783,8 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
return value.asBoolean();
|
return value.asBoolean();
|
||||||
|
|
||||||
case NULL:
|
case NULL:
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NUMBER:
|
case NUMBER:
|
||||||
|
@ -776,6 +831,8 @@ 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();
|
||||||
|
|
||||||
|
@ -934,6 +991,8 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
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);
|
||||||
|
|
||||||
|
@ -975,38 +1034,6 @@ public abstract class ElementManagement<El extends OElement> {
|
||||||
return superClasses;
|
return superClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonNode toJsonNode() throws ResourceRegistryException {
|
|
||||||
try {
|
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
ObjectNode objectNode = objectMapper.createObjectNode();
|
|
||||||
OElement element = getElement();
|
|
||||||
Set<String> keys = element.getPropertyNames();
|
|
||||||
for(String key : keys) {
|
|
||||||
Object object = element.getProperty(key);
|
|
||||||
JsonNode jsonNode = getPropertyForJson(key, object);
|
|
||||||
if(jsonNode != null) {
|
|
||||||
objectNode.replace(key, jsonNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OClass oClass = getOClass();
|
|
||||||
String type = oClass.getName();
|
|
||||||
objectNode.put(Element.CLASS_PROPERTY, type);
|
|
||||||
|
|
||||||
Collection<String> superClasses = getSuperclasses();
|
|
||||||
ArrayNode arrayNode = objectMapper.valueToTree(superClasses);
|
|
||||||
|
|
||||||
objectNode.replace(Element.SUPERCLASSES_PROPERTY, arrayNode);
|
|
||||||
|
|
||||||
return objectNode;
|
|
||||||
} catch(ResourceRegistryException e) {
|
|
||||||
throw e;
|
|
||||||
} catch(Exception e) {
|
|
||||||
throw new ResourceRegistryException("Error while serializing " + getElement().toString(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAvailableOnContext(OElement element, SecurityContext securityContext) {
|
public boolean isAvailableOnContext(OElement element, SecurityContext securityContext) {
|
||||||
try {
|
try {
|
||||||
return securityContext.isElementInContext(element);
|
return securityContext.isElementInContext(element);
|
||||||
|
|
|
@ -86,22 +86,22 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
public JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||||
return serializeAsJson(true, true);
|
return serializeAsJson(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonNode serializeAsJson(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
|
public JsonNode serializeAsJson(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
|
||||||
JsonNode relation = serializeSelfOnly();
|
JsonNode relation = serializeSelf().deepCopy();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(includeSource) {
|
if(includeSource) {
|
||||||
EntityElementManagement<? extends EntityElement> sourceEntityManagement = getSourceEntityManagement();
|
EntityElementManagement<? extends EntityElement> sourceEntityManagement = getSourceEntityManagement();
|
||||||
((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelfOnly());
|
((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelf());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(includeTarget) {
|
if(includeTarget) {
|
||||||
EntityElementManagement<? extends EntityElement> targetEntityManagement = getTargetEntityManagement();
|
EntityElementManagement<? extends EntityElement> targetEntityManagement = getTargetEntityManagement();
|
||||||
((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeAsJson());
|
((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
|
@ -159,8 +159,8 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.trace("Creating {} beetween {} -> {}", elementType, getSourceEntityManagement().serialize(),
|
logger.trace("Creating {} beetween {} -> {}", elementType, getSourceEntityManagement().serializeSelf().toString(),
|
||||||
getTargetEntityManagement().serialize());
|
getTargetEntityManagement().serializeSelf().toString());
|
||||||
|
|
||||||
OVertex source = (OVertex) getSourceEntityManagement().getElement();
|
OVertex source = (OVertex) getSourceEntityManagement().getElement();
|
||||||
OVertex target = (OVertex) getTargetEntityManagement().getElement();
|
OVertex target = (OVertex) getTargetEntityManagement().getElement();
|
||||||
|
|
|
@ -327,7 +327,7 @@ public abstract class EntityManagement<E extends Entity> extends EntityElementMa
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
element.save();
|
element.save();
|
||||||
}
|
}
|
||||||
affectedInstances.put(uuid, serializeSelfOnly());
|
affectedInstances.put(uuid, serializeSelf());
|
||||||
return affectedInstances;
|
return affectedInstances;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -384,7 +384,7 @@ public abstract class EntityManagement<E extends Entity> extends EntityElementMa
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
element.save();
|
element.save();
|
||||||
}
|
}
|
||||||
affectedInstances.put(uuid, serializeSelfOnly());
|
affectedInstances.put(uuid, serializeSelf());
|
||||||
return affectedInstances;
|
return affectedInstances;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -473,7 +473,7 @@ public abstract class EntityManagement<E extends Entity> extends EntityElementMa
|
||||||
EntityManagement<?> entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(),
|
EntityManagement<?> entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(),
|
||||||
oDatabaseDocument, (OVertex) vertex);
|
oDatabaseDocument, (OVertex) vertex);
|
||||||
try {
|
try {
|
||||||
JsonNode jsonNode = entityManagement.serializeAsJson();
|
JsonNode jsonNode = entityManagement.serializeComplete();
|
||||||
arrayNode.add(jsonNode);
|
arrayNode.add(jsonNode);
|
||||||
} 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. {}",
|
||||||
|
@ -647,9 +647,9 @@ public abstract class EntityManagement<E extends Entity> extends EntityElementMa
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
RelationManagement relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(),
|
RelationManagement relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(),
|
||||||
oDatabaseDocument, edge);
|
oDatabaseDocument, edge);
|
||||||
jsonNode = relationManagement.serializeAsJson();
|
jsonNode = relationManagement.createCompleteJsonNode();
|
||||||
}else {
|
}else {
|
||||||
jsonNode = entityManagement.serializeAsJson();
|
jsonNode = entityManagement.serializeComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
arrayNode.add(jsonNode);
|
arrayNode.add(jsonNode);
|
||||||
|
@ -760,7 +760,7 @@ public abstract class EntityManagement<E extends Entity> extends EntityElementMa
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JsonNode jsonNode = entityManagement.serializeAsJson();
|
JsonNode jsonNode = entityManagement.serializeComplete();
|
||||||
arrayNode.add(jsonNode);
|
arrayNode.add(jsonNode);
|
||||||
} 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. {}",
|
||||||
|
|
|
@ -38,14 +38,10 @@ public class FacetManagement extends EntityManagement<Facet> {
|
||||||
return new FacetAlreadyPresentException(message);
|
return new FacetAlreadyPresentException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String serialize() throws ResourceRegistryException {
|
|
||||||
return serializeSelfOnly().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
public JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||||
return serializeSelfOnly();
|
return serializeSelf().deepCopy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -69,9 +69,9 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
public JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||||
|
|
||||||
JsonNode sourceResource = serializeSelfOnly();
|
JsonNode sourceResource = serializeSelf().deepCopy();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cannot get ConsistsOf edge only because is not polymorphic for a
|
* Cannot get ConsistsOf edge only because is not polymorphic for a
|
||||||
|
|
|
@ -201,22 +201,22 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
public JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||||
return serializeAsJson(true, true);
|
return serializeAsJson(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonNode serializeAsJson(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
|
public JsonNode serializeAsJson(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
|
||||||
JsonNode relation = serializeSelfOnly();
|
JsonNode relation = serializeSelf();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(includeSource) {
|
if(includeSource) {
|
||||||
EntityManagement<? extends Resource> sourceEntityManagement = getSourceEntityManagement();
|
EntityManagement<? extends Resource> sourceEntityManagement = getSourceEntityManagement();
|
||||||
((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelfOnly());
|
((ObjectNode) relation).replace(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelf());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(includeTarget) {
|
if(includeTarget) {
|
||||||
EntityManagement<? extends Entity> targetEntityManagement = getTargetEntityManagement();
|
EntityManagement<? extends Entity> targetEntityManagement = getTargetEntityManagement();
|
||||||
((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeAsJson());
|
((ObjectNode) relation).replace(Relation.TARGET_PROPERTY, targetEntityManagement.serializeComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
|
@ -244,9 +244,9 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
resourceManagement = (ResourceManagement) ElementManagementUtility.getEntityManagement(getWorkingContext(),
|
resourceManagement = (ResourceManagement) ElementManagementUtility.getEntityManagement(getWorkingContext(),
|
||||||
oDatabaseDocument, source);
|
oDatabaseDocument, source);
|
||||||
if(this instanceof IsRelatedToManagement) {
|
if(this instanceof IsRelatedToManagement) {
|
||||||
sourceResource = resourceManagement.serializeAsJson();
|
sourceResource = resourceManagement.createCompleteJsonNode();
|
||||||
} else if(this instanceof ConsistsOfManagement) {
|
} else if(this instanceof ConsistsOfManagement) {
|
||||||
sourceResource = resourceManagement.serializeSelfOnly();
|
sourceResource = resourceManagement.serializeSelf();
|
||||||
} else {
|
} else {
|
||||||
String error = String.format("{%s is not a %s nor a %s. %s", this,
|
String error = String.format("{%s is not a %s nor a %s. %s", this,
|
||||||
IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName(),
|
IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName(),
|
||||||
|
@ -256,9 +256,9 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this instanceof IsRelatedToManagement) {
|
if(this instanceof IsRelatedToManagement) {
|
||||||
sourceResource = ResourceManagement.addIsRelatedTo(sourceResource, serializeAsJson());
|
sourceResource = ResourceManagement.addIsRelatedTo(sourceResource, createCompleteJsonNode());
|
||||||
} else if(this instanceof ConsistsOfManagement) {
|
} else if(this instanceof ConsistsOfManagement) {
|
||||||
sourceResource = ResourceManagement.addConsistsOf(sourceResource, serializeAsJson());
|
sourceResource = ResourceManagement.addConsistsOf(sourceResource, createCompleteJsonNode());
|
||||||
} else {
|
} else {
|
||||||
String error = String.format("{%s is not a %s nor a %s. %s", this,
|
String error = String.format("{%s is not a %s nor a %s. %s", this,
|
||||||
IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName(),
|
IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName(),
|
||||||
|
@ -443,7 +443,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
element.save();
|
element.save();
|
||||||
}
|
}
|
||||||
affectedInstances.put(uuid, serializeSelfOnly());
|
affectedInstances.put(uuid, serializeSelf());
|
||||||
}
|
}
|
||||||
return affectedInstances;
|
return affectedInstances;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
|
@ -475,7 +475,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
if(!dryRunContextSharing) {
|
if(!dryRunContextSharing) {
|
||||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||||
}
|
}
|
||||||
affectedInstances.put(uuid, serializeSelfOnly());
|
affectedInstances.put(uuid, serializeSelf());
|
||||||
|
|
||||||
return affectedInstances;
|
return affectedInstances;
|
||||||
}
|
}
|
||||||
|
@ -545,7 +545,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
if(!dryRunContextSharing) {
|
if(!dryRunContextSharing) {
|
||||||
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
||||||
}
|
}
|
||||||
affectedInstances.put(uuid, serializeSelfOnly());
|
affectedInstances.put(uuid, serializeSelf());
|
||||||
|
|
||||||
T targetEntityManagement = getTargetEntityManagement();
|
T targetEntityManagement = getTargetEntityManagement();
|
||||||
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
|
targetEntityManagement.setDryRunContextSharing(dryRunContextSharing);
|
||||||
|
@ -604,7 +604,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
element.save();
|
element.save();
|
||||||
}
|
}
|
||||||
affectedInstances.put(uuid, serializeSelfOnly());
|
affectedInstances.put(uuid, serializeSelf());
|
||||||
return affectedInstances;
|
return affectedInstances;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class QueryImpl implements Query {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
ElementManagement erManagement = ElementManagementUtility.getERManagement(securityContext, oDatabaseDocument,
|
ElementManagement erManagement = ElementManagementUtility.getERManagement(securityContext, oDatabaseDocument,
|
||||||
element);
|
element);
|
||||||
jsonNode = erManagement.serializeAsJson();
|
jsonNode = erManagement.createCompleteJsonNode();
|
||||||
}
|
}
|
||||||
arrayNode.add(jsonNode);
|
arrayNode.add(jsonNode);
|
||||||
|
|
||||||
|
|
|
@ -66,14 +66,8 @@ public abstract class EntityTypeDefinitionManagement<E extends EntityType> exten
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String serialize() throws ResourceRegistryException {
|
public JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||||
return serializeAsJson().toString();
|
return serializeSelf().deepCopy();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
|
||||||
return serializeSelfOnly();
|
|
||||||
// For Resources Definition include mandatory and suggested IsRelatedTo and ConsistsOf
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -73,13 +73,8 @@ public class PropertyTypeDefinitionManagement extends ElementManagement<OElement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String serialize() throws ResourceRegistryException {
|
public JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||||
return serializeAsJson().toString();
|
return serializeSelf().deepCopy();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonNode serializeAsJson() throws ResourceRegistryException {
|
|
||||||
return serializeSelfOnly();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -97,8 +97,8 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
||||||
targetEntityManagement.setJsonNode(jsonNode.get(Relation.TARGET_PROPERTY));
|
targetEntityManagement.setJsonNode(jsonNode.get(Relation.TARGET_PROPERTY));
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.trace("Creating {} beetween {} -> {}", elementType, getSourceEntityManagement().serialize(),
|
logger.trace("Creating {} beetween {} -> {}", elementType, getSourceEntityManagement().serializeSelf().toString(),
|
||||||
getTargetEntityManagement().serialize());
|
getTargetEntityManagement().serializeSelf().toString());
|
||||||
|
|
||||||
OVertex source = (OVertex) getSourceEntityManagement().getElement();
|
OVertex source = (OVertex) getSourceEntityManagement().getElement();
|
||||||
OVertex target = (OVertex) getTargetEntityManagement().getElement();
|
OVertex target = (OVertex) getTargetEntityManagement().getElement();
|
||||||
|
|
Loading…
Reference in New Issue