Fixing corner cases

This commit is contained in:
Luca Frosini 2021-03-05 17:22:01 +01:00
parent ada9439ab9
commit 6afde17b0f
3 changed files with 23 additions and 7 deletions

View File

@ -108,11 +108,11 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
* 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;

View File

@ -45,8 +45,19 @@ import com.orientechnologies.orient.core.record.OVertex;
*/
public class ResourceManagement extends EntityManagement<Resource, ResourceType> {
/*
* 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<Resource, ResourceType>
relationManagement.setElement(edge);
relationManagement.internalDelete();
affectedInstances.putAll(relationManagement.getAffectedInstances());
addToRelationManagements(relationManagement);
}
}
@ -392,7 +402,10 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
*/
@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;
}

View File

@ -717,6 +717,9 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
// pre-loading target entity because after deleting the relation we will not be able to get it
T t = getTargetEntityManagement();
if(targetEntityManagement instanceof ResourceManagement) {
((ResourceManagement) targetEntityManagement).setSanityCheckNotRequired();
}
affectedInstances.put(uuid, serializeSelfAsJsonNode());
element.delete();
@ -728,7 +731,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
case cascadeWhenOrphan:
OVertex target = t.getElement();
Iterable<OEdge> iterable = t.getElement().getEdges(ODirection.IN);
Iterable<OEdge> iterable = target.getEdges(ODirection.IN);
Iterator<OEdge> iterator = iterable.iterator();
if(iterator.hasNext()) {
logger.trace("{} point to {} which is not orphan. Giving {} directive, it will be keep.", element,