Fixed RemoveFromContext operation and forced ConsistsOf RemoveConstraint

This commit is contained in:
Luca Frosini 2021-03-09 12:46:56 +01:00
parent d68c3ba564
commit abd1584901
3 changed files with 12 additions and 2 deletions

View File

@ -405,7 +405,9 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
// In case of a resource is deleted due to cascade effect is look like is the entry point // 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. // of the operation and the sanity check is not required. The Resource and all its facets are deleted.
if(sanityCheckNotRequired || (entryPoint && operation == Operation.DELETE)) { if( sanityCheckNotRequired ||
(entryPoint &&
(operation == Operation.DELETE || operation == Operation.REMOVE_FROM_CONTEXT) ) ) {
return; return;
} }

View File

@ -35,7 +35,7 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement, Fa
static { static {
DEFAULT_CONSISTS_OF_PC = new PropagationConstraintImpl(); DEFAULT_CONSISTS_OF_PC = new PropagationConstraintImpl();
DEFAULT_CONSISTS_OF_PC.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan); DEFAULT_CONSISTS_OF_PC.setRemoveConstraint(RemoveConstraint.cascade);
DEFAULT_CONSISTS_OF_PC.setAddConstraint(AddConstraint.propagate); DEFAULT_CONSISTS_OF_PC.setAddConstraint(AddConstraint.propagate);
} }

View File

@ -17,6 +17,7 @@ import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
@ -286,6 +287,13 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
removeConstraint = defaultPropagationConstraint.getRemoveConstraint(); removeConstraint = defaultPropagationConstraint.getRemoveConstraint();
logger.warn("Unable to get {}. Default value ({}) will be used", RemoveConstraint.class.getSimpleName(), logger.warn("Unable to get {}. Default value ({}) will be used", RemoveConstraint.class.getSimpleName(),
removeConstraint); removeConstraint);
}else {
if (this instanceof ConsistsOfManagement && removeConstraint == RemoveConstraint.keep) {
removeConstraint = defaultPropagationConstraint.getRemoveConstraint();
logger.warn("A {} cannot use {}.{}. Default value ({}) will be used", ConsistsOf.NAME,
RemoveConstraint.class.getSimpleName(), RemoveConstraint.keep, removeConstraint);
}
} }
propagationConstraintOrient.setRemoveConstraint(removeConstraint); propagationConstraintOrient.setRemoveConstraint(removeConstraint);