Not including source in consistsOf when serialising Resource #22001

This commit is contained in:
Luca Frosini 2021-09-13 16:48:29 +02:00
parent 61107110b1
commit 113c3ceb9e
5 changed files with 28 additions and 12 deletions

View File

@ -181,7 +181,9 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
try {
IsParentOfManagement isParentOfManagement = new IsParentOfManagement(oDatabaseDocument);
isParentOfManagement.setElement(edge);
JsonNode isParentOf = isParentOfManagement.createCompleteJsonNode(true, false);
isParentOfManagement.includeSource(true);
isParentOfManagement.includeTarget(false);
JsonNode isParentOf = isParentOfManagement.createCompleteJsonNode();
if (isParentOf != null) {
((ObjectNode) context).replace(Context.PARENT_PROPERTY, isParentOf);
}

View File

@ -39,6 +39,8 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
this();
this.oDatabaseDocument = oDatabaseDocument;
getWorkingContext();
includeSource = false;
includeTarget = true;
}
@Override
@ -66,12 +68,7 @@ public class IsParentOfManagement extends RelationElementManagement<ContextManag
}
@Override
protected JsonNode createCompleteJsonNode() throws ResourceRegistryException {
return createCompleteJsonNode(false, true);
}
@Override
public JsonNode createCompleteJsonNode(boolean includeSource, boolean includeTarget)
public JsonNode createCompleteJsonNode()
throws ResourceRegistryException {
JsonNode relation = serializeSelfAsJsonNode();

View File

@ -40,6 +40,9 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
protected SEM sourceEntityManagement;
protected TEM targetEntityManagement;
protected boolean includeSource;
protected boolean includeTarget;
protected RelationElementManagement(AccessType accessType, Class<? extends EntityElement> sourceEntityClass, Class<? extends EntityElement> targetEntityClass) {
super(accessType);
@ -57,6 +60,17 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
this.sourceEntityManagement = null;
this.targetEntityManagement = null;
this.includeSource = true;
this.includeTarget = true;
}
public void includeSource(boolean includeSource) {
this.includeSource = includeSource;
}
public void includeTarget(boolean includeTarget) {
this.includeTarget = includeTarget;
}
protected RelationElementManagement(AccessType accessType, Class<? extends EntityElement> sourceEntityClass, Class<? extends EntityElement> targetEntityClass, SecurityContext workingContext, ODatabaseDocument orientGraph) {
@ -95,10 +109,6 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
@Override
protected JsonNode createCompleteJsonNode() throws ResourceRegistryException {
return createCompleteJsonNode(true, true);
}
protected JsonNode createCompleteJsonNode(boolean includeSource, boolean includeTarget) throws ResourceRegistryException {
JsonNode relation = serializeSelfAsJsonNode();
try {

View File

@ -108,6 +108,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
if(relationManagement instanceof ConsistsOfManagement) {
try {
relationManagement.includeSource(false);
JsonNode consistsOf = relationManagement.serializeAsJsonNode();
sourceResource = addConsistsOf(sourceResource, consistsOf);
} catch(ResourceRegistryException e) {

View File

@ -149,10 +149,12 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
* so this variable is initialised as true.
*/
this.honourPropagationConstraintsInContextSharing = true;
}
protected PropagationConstraint propagationConstraint;
@Override
public OEdge getElement() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
try {
@ -229,7 +231,9 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
if(this instanceof IsRelatedToManagement) {
sourceResource = resourceManagement.createCompleteJsonNode();
} else if(this instanceof ConsistsOfManagement) {
sourceResource = resourceManagement.serializeSelfAsJsonNode();
if(includeSource) {
sourceResource = resourceManagement.serializeSelfAsJsonNode();
}
} else {
String error = String.format("{%s is not a %s nor a %s. %s", this,
IsRelatedToManagement.class.getSimpleName(), ConsistsOfManagement.class.getSimpleName(),
@ -794,4 +798,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
return serializeJsonNodeCollectionAsString(collection);
}
}