From 6afde17b0f2b821a1e7a35cd5f9643dd57992e70 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 5 Mar 2021 17:22:01 +0100 Subject: [PATCH] Fixing corner cases --- .../instances/base/ElementManagement.java | 8 ++++---- .../model/entities/ResourceManagement.java | 17 +++++++++++++++-- .../model/relations/RelationManagement.java | 5 ++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java index 2f687d5..38d7aa9 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java @@ -108,11 +108,11 @@ public abstract class ElementManagement { * An operation can affects multiple instances (e.g. create, update) * We need to know if the instance is the entry point of the operation * or if it is just a subordinated operation. - * This is required for example in addTocontext to trigger sanity check - * in the Resource when the action is performed directly on the Facet, - * or the Resource sanity check is not required to be triggered + * This is required for example in delete to trigger sanity check + * in the Resource when the action is performed directly on the Facet. + * Resource sanity check is not required to be triggered by the Facet * because the entry point of the action already take care - * of triggering this action (e.g. the update was invoked on the Resource and + * of triggering this action (e.g. the delete was invoked on the Resource and * each describing Facets must not trigger multiple time the sanityCheck). */ protected boolean entryPoint; 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 d9a976d..0fe1b11 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 @@ -45,8 +45,19 @@ import com.orientechnologies.orient.core.record.OVertex; */ public class ResourceManagement extends EntityManagement { + /* + * In case of a resource is deleted due to cascade effect the sanity check is not required. + * The Resource and all its facets are deleted. + */ + private boolean sanityCheckNotRequired; + public ResourceManagement() { super(AccessType.RESOURCE); + this.sanityCheckNotRequired = false; + } + + public void setSanityCheckNotRequired() { + this.sanityCheckNotRequired = true; } @Override @@ -229,7 +240,6 @@ public class ResourceManagement extends EntityManagement relationManagement.setElement(edge); relationManagement.internalDelete(); affectedInstances.putAll(relationManagement.getAffectedInstances()); - addToRelationManagements(relationManagement); } } @@ -392,7 +402,10 @@ public class ResourceManagement extends EntityManagement */ @Override public void sanityCheck() throws SchemaViolationException, ResourceRegistryException { - if(operation == Operation.DELETE) { + + // In case of a resource is deleted due to cascade effect is look like is the entry point + // of the operation and the sanity check is not required. The Resource and all its facets are deleted. + if(sanityCheckNotRequired || (entryPoint && operation == Operation.DELETE)) { return; } 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 a79ac2d..71b19c6 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 @@ -717,6 +717,9 @@ public abstract class RelationManagement iterable = t.getElement().getEdges(ODirection.IN); + Iterable iterable = target.getEdges(ODirection.IN); Iterator iterator = iterable.iterator(); if(iterator.hasNext()) { logger.trace("{} point to {} which is not orphan. Giving {} directive, it will be keep.", element,