Added remove in propagation constraint

This commit is contained in:
Luca Frosini 2023-02-02 19:34:47 +01:00
parent 7307eefeab
commit af4de28ebb
7 changed files with 90 additions and 26 deletions

View File

@ -2,7 +2,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Information System Model # Changelog for Information System Model
## [v5.0.1-SNAPSHOT] ## [v5.1.0-SNAPSHOT]
- Added class Discovery to make new model discovery easier - Added class Discovery to make new model discovery easier
- Added the possibility to exclude IS Model package in discovery - Added the possibility to exclude IS Model package in discovery

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.information-system</groupId> <groupId>org.gcube.information-system</groupId>
<artifactId>information-system-model</artifactId> <artifactId>information-system-model</artifactId>
<version>5.0.1-SNAPSHOT</version> <version>5.1.0-SNAPSHOT</version>
<name>Information System Model</name> <name>Information System Model</name>
<description>Information System Model is the reference model of the gCube Information System</description> <description>Information System Model is the reference model of the gCube Information System</description>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -19,6 +19,10 @@ public final class PropagationConstraintImpl extends PropertyImpl implements Pro
*/ */
private static final long serialVersionUID = -4708881022038107688L; private static final long serialVersionUID = -4708881022038107688L;
@JsonFormat(shape=JsonFormat.Shape.STRING)
@JsonProperty(value=DELETE_PROPERTY)
protected DeleteConstraint deleteConstraint;
@JsonFormat(shape=JsonFormat.Shape.STRING) @JsonFormat(shape=JsonFormat.Shape.STRING)
@JsonProperty(value=REMOVE_PROPERTY) @JsonProperty(value=REMOVE_PROPERTY)
protected RemoveConstraint removeConstraint; protected RemoveConstraint removeConstraint;
@ -31,6 +35,16 @@ public final class PropagationConstraintImpl extends PropertyImpl implements Pro
super(); super();
} }
@Override
public DeleteConstraint getDeleteConstraint() {
return this.deleteConstraint;
}
@Override
public void setDeleteConstraint(DeleteConstraint deleteConstraint) {
this.deleteConstraint = deleteConstraint;
}
@Override @Override
public RemoveConstraint getRemoveConstraint() { public RemoveConstraint getRemoveConstraint() {
return this.removeConstraint; return this.removeConstraint;

View File

@ -9,6 +9,7 @@ import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; 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.DeleteConstraint;
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.ConsistsOf;
@ -29,10 +30,7 @@ public class ConsistsOfImpl<S extends Resource, T extends Facet> extends
} }
public ConsistsOfImpl(S source, T target) { public ConsistsOfImpl(S source, T target) {
super(source, target, null); this(source, target, null);
propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setAddConstraint(AddConstraint.propagate);
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan);
} }
public ConsistsOfImpl(S source, T target, public ConsistsOfImpl(S source, T target,
@ -41,7 +39,8 @@ public class ConsistsOfImpl<S extends Resource, T extends Facet> extends
if(this.propagationConstraint==null) { if(this.propagationConstraint==null) {
this.propagationConstraint = new PropagationConstraintImpl(); this.propagationConstraint = new PropagationConstraintImpl();
this.propagationConstraint.setAddConstraint(AddConstraint.propagate); this.propagationConstraint.setAddConstraint(AddConstraint.propagate);
this.propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan); this.propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
this.propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);
} }
} }

View File

@ -8,6 +8,7 @@ import org.gcube.informationsystem.model.impl.properties.PropagationConstraintIm
import org.gcube.informationsystem.model.reference.entities.Resource; 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.DeleteConstraint;
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.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
@ -28,10 +29,7 @@ public abstract class IsRelatedToImpl<S extends Resource, T extends Resource> ex
} }
public IsRelatedToImpl(S source, T target) { public IsRelatedToImpl(S source, T target) {
super(source, target, null); this(source, target, null);
propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
propagationConstraint.setRemoveConstraint(RemoveConstraint.keep);
} }
public IsRelatedToImpl(S source, T target, public IsRelatedToImpl(S source, T target,
@ -41,6 +39,7 @@ public abstract class IsRelatedToImpl<S extends Resource, T extends Resource> ex
this.propagationConstraint = new PropagationConstraintImpl(); this.propagationConstraint = new PropagationConstraintImpl();
this.propagationConstraint.setAddConstraint(AddConstraint.unpropagate); this.propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
this.propagationConstraint.setRemoveConstraint(RemoveConstraint.keep); this.propagationConstraint.setRemoveConstraint(RemoveConstraint.keep);
this.propagationConstraint.setDeleteConstraint(DeleteConstraint.keep);
} }
} }

View File

@ -19,8 +19,8 @@ import org.gcube.informationsystem.utils.Version;
* or directly to the relation. * or directly to the relation.
* *
* The default values of propagation constraints are: * The default values of propagation constraints are:
* - IsRelatedTo: remove=keep, add=unpropagate; * - IsRelatedTo: delete=keep, remove=keep, add=unpropagate;
* - ConsistsOf : remove=cascade, add=propagate. * - ConsistsOf : delete=cascade, remove=cascade, add=propagate.
* *
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Propagation_Constraint * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Propagation_Constraint
* *
@ -34,28 +34,55 @@ public interface PropagationConstraint extends Property {
public static final String NAME = "PropagationConstraint"; // PropagationConstraint.class.getSimpleName(); public static final String NAME = "PropagationConstraint"; // PropagationConstraint.class.getSimpleName();
public static final String DELETE_PROPERTY = "delete";
public static final String REMOVE_PROPERTY = "remove"; public static final String REMOVE_PROPERTY = "remove";
public static final String ADD_PROPERTY = "add"; public static final String ADD_PROPERTY = "add";
public enum RemoveConstraint { public enum DeleteConstraint {
/** /**
* When a remove action is performed on the source Entity of the relation, * When a 'delete' action is performed on the source Entity of the relation,
* or directly on the relation, then the same remove action apart on * or directly on the relation, then the same 'delete' action apart on
* the relation is performed to the target entity if it has no other incoming relations * the relation is performed to the target entity if it has no other incoming relations
*/ */
cascadeWhenOrphan, cascadeWhenOrphan,
/** /**
* When a remove action is performed on the source Entity of the relation, * When a 'delete' action is performed on the source Entity of the relation,
* or directly on the relation, then the same remove action is performed on * or directly on the relation, then the same 'delete' action is performed on
* the relation and its target entity; * the relation and its target entity;
*/ */
cascade, cascade,
/** /**
* When a remove action is performed on the source Entity of the relation, * When a 'delete' action is performed on the source Entity of the relation,
* or directly on the relation, then the same remove action is performed on * or directly on the relation, then the same 'delete' action is performed on
* relation but never to the target entity.
*/
keep
}
public enum RemoveConstraint {
/**
* When a 'remove' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'remove' action apart on
* the relation is performed to the target entity if it has no other incoming relations
*/
cascadeWhenOrphan,
/**
* When a 'remove' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'remove' action is performed on
* the relation and its target entity;
*/
cascade,
/**
* When a 'remove' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'remove' action is performed on
* relation but never to the target entity. * relation but never to the target entity.
*/ */
keep keep
@ -66,7 +93,7 @@ public interface PropagationConstraint extends Property {
/** /**
* When an 'add' action is performed on the source Entity of the relation, * When an 'add' action is performed on the source Entity of the relation,
* or directly on the relation, then the same add action is performed on * or directly on the relation, then the same 'add' action is performed on
* the relation and its target Entity. * the relation and its target Entity.
*/ */
propagate, propagate,
@ -80,7 +107,13 @@ public interface PropagationConstraint extends Property {
} }
@ISProperty(name=REMOVE_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when a 'remove' action is performed on the source Resource. Remove actions are: (i) the operation of removing an instance from a context; (ii) the operation of deleting an instance (it has an impact on all contexts).", mandatory = true, nullable = false) @ISProperty(name=DELETE_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when a 'delete' action is performed on the source Resource. Delet action is the operation of deleting an instance (it has an impact on all contexts).", mandatory = true, nullable = false)
public DeleteConstraint getDeleteConstraint();
public void setDeleteConstraint(DeleteConstraint deleteConstraint);
@ISProperty(name=REMOVE_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when a 'remove' action is performed on the source Resource. Remove actions is the operation of removing an instance from a context.", mandatory = true, nullable = false)
public RemoveConstraint getRemoveConstraint(); public RemoveConstraint getRemoveConstraint();
public void setRemoveConstraint(RemoveConstraint removeConstraint); public void setRemoveConstraint(RemoveConstraint removeConstraint);
@ -91,6 +124,4 @@ public interface PropagationConstraint extends Property {
public void setAddConstraint(AddConstraint addConstraint); public void setAddConstraint(AddConstraint addConstraint);
} }

View File

@ -8,6 +8,7 @@ import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; 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.DeleteConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.properties.Property; import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
@ -29,6 +30,7 @@ public class PropagationConstraintTest {
PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setAddConstraint(AddConstraint.propagate); propagationConstraint.setAddConstraint(AddConstraint.propagate);
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan); propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan);
propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);
String pg = ElementMapper.marshal(propagationConstraint); String pg = ElementMapper.marshal(propagationConstraint);
Property property = ElementMapper.unmarshal(Property.class, pg); Property property = ElementMapper.unmarshal(Property.class, pg);
@ -44,9 +46,12 @@ public class PropagationConstraintTest {
public void testPropagationConstraintByString() throws Exception { public void testPropagationConstraintByString() throws Exception {
AddConstraint addConstraint = AddConstraint.propagate; AddConstraint addConstraint = AddConstraint.propagate;
RemoveConstraint removeConstraint = RemoveConstraint.cascade; RemoveConstraint removeConstraint = RemoveConstraint.cascade;
DeleteConstraint deleteConstraint = DeleteConstraint.keep;
PropagationConstraint pc = new PropagationConstraintImpl(); PropagationConstraint pc = new PropagationConstraintImpl();
pc.setAddConstraint(addConstraint); pc.setAddConstraint(addConstraint);
pc.setRemoveConstraint(removeConstraint); pc.setRemoveConstraint(removeConstraint);
pc.setDeleteConstraint(deleteConstraint);
String json = ElementMapper.marshal(pc); String json = ElementMapper.marshal(pc);
logger.debug(json); logger.debug(json);
@ -55,12 +60,14 @@ public class PropagationConstraintTest {
Assert.assertTrue(property instanceof PropagationConstraint); Assert.assertTrue(property instanceof PropagationConstraint);
Assert.assertTrue(((PropagationConstraint) property).getAddConstraint().compareTo(addConstraint)==0); Assert.assertTrue(((PropagationConstraint) property).getAddConstraint().compareTo(addConstraint)==0);
Assert.assertTrue(((PropagationConstraint) property).getRemoveConstraint().compareTo(removeConstraint)==0); Assert.assertTrue(((PropagationConstraint) property).getRemoveConstraint().compareTo(removeConstraint)==0);
Assert.assertTrue(((PropagationConstraint) property).getDeleteConstraint().compareTo(deleteConstraint)==0);
logger.debug(ElementMapper.marshal(property)); logger.debug(ElementMapper.marshal(property));
PropagationConstraint propagationConstraint = ElementMapper.unmarshal(PropagationConstraint.class, json); PropagationConstraint propagationConstraint = ElementMapper.unmarshal(PropagationConstraint.class, json);
Assert.assertTrue(propagationConstraint instanceof PropagationConstraint); Assert.assertTrue(propagationConstraint instanceof PropagationConstraint);
Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0); Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0);
Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0); Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0);
Assert.assertTrue(propagationConstraint.getDeleteConstraint().compareTo(deleteConstraint)==0);
logger.debug(ElementMapper.marshal(property)); logger.debug(ElementMapper.marshal(property));
} }
@ -68,19 +75,29 @@ public class PropagationConstraintTest {
public void testPropagationConstraintSpecilization() throws Exception { public void testPropagationConstraintSpecilization() throws Exception {
AddConstraint addConstraint = AddConstraint.propagate; AddConstraint addConstraint = AddConstraint.propagate;
RemoveConstraint removeConstraint = RemoveConstraint.cascade; RemoveConstraint removeConstraint = RemoveConstraint.cascade;
String marshalled = "{\"" + Element.CLASS_PROPERTY + "\":\"MyPropagationConstraint\",\"" + Element.SUPERCLASSES_PROPERTY + "\":[\"" + PropagationConstraint.NAME + "\", \"" + Property.NAME + "\"],\"" + PropagationConstraint.ADD_PROPERTY + "\":\""+ addConstraint + "\",\""+ PropagationConstraint.REMOVE_PROPERTY + "\":\"" + removeConstraint + "\"}"; DeleteConstraint deleteConstraint = DeleteConstraint.keep;
String marshalled = "{\"" +
Element.CLASS_PROPERTY + "\":\"MyPropagationConstraint\",\"" +
Element.SUPERCLASSES_PROPERTY + "\":[\"" + PropagationConstraint.NAME + "\", \"" + Property.NAME + "\"],\"" +
PropagationConstraint.ADD_PROPERTY + "\":\""+ addConstraint + "\",\""+
PropagationConstraint.REMOVE_PROPERTY + "\":\"" + removeConstraint + "\",\""+
PropagationConstraint.DELETE_PROPERTY + "\":\"" + deleteConstraint +
"\"}";
logger.debug(marshalled); logger.debug(marshalled);
Property property = ElementMapper.unmarshal(Property.class, marshalled); Property property = ElementMapper.unmarshal(Property.class, marshalled);
Assert.assertTrue(property instanceof PropagationConstraint); Assert.assertTrue(property instanceof PropagationConstraint);
Assert.assertTrue(((PropagationConstraint) property).getAddConstraint().compareTo(addConstraint)==0); Assert.assertTrue(((PropagationConstraint) property).getAddConstraint().compareTo(addConstraint)==0);
Assert.assertTrue(((PropagationConstraint) property).getRemoveConstraint().compareTo(removeConstraint)==0); Assert.assertTrue(((PropagationConstraint) property).getRemoveConstraint().compareTo(removeConstraint)==0);
Assert.assertTrue(((PropagationConstraint) property).getDeleteConstraint().compareTo(deleteConstraint)==0);
logger.debug(ElementMapper.marshal(property)); logger.debug(ElementMapper.marshal(property));
PropagationConstraint propagationConstraint = ElementMapper.unmarshal(PropagationConstraint.class, marshalled); PropagationConstraint propagationConstraint = ElementMapper.unmarshal(PropagationConstraint.class, marshalled);
Assert.assertTrue(propagationConstraint instanceof PropagationConstraint); Assert.assertTrue(propagationConstraint instanceof PropagationConstraint);
Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0); Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0);
Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0); Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0);
Assert.assertTrue(propagationConstraint.getDeleteConstraint().compareTo(deleteConstraint)==0);
logger.debug(ElementMapper.marshal(property)); logger.debug(ElementMapper.marshal(property));
} }
@ -88,11 +105,14 @@ public class PropagationConstraintTest {
public void testPropagationConstraintSpecilizationInside() throws Exception { public void testPropagationConstraintSpecilizationInside() throws Exception {
AddConstraint addConstraint = AddConstraint.propagate; AddConstraint addConstraint = AddConstraint.propagate;
RemoveConstraint removeConstraint = RemoveConstraint.cascade; RemoveConstraint removeConstraint = RemoveConstraint.cascade;
DeleteConstraint deleteConstraint = DeleteConstraint.keep;
String pcString = "{" + String pcString = "{" +
"\"" + Element.CLASS_PROPERTY + "\":\"My" + PropagationConstraint.NAME + "\"," + "\"" + Element.CLASS_PROPERTY + "\":\"My" + PropagationConstraint.NAME + "\"," +
"\"" + Element.SUPERCLASSES_PROPERTY + "\":[\"" + PropagationConstraint.NAME + "\", \"" + Property.NAME + "\"],\"" + "\"" + Element.SUPERCLASSES_PROPERTY + "\":[\"" + PropagationConstraint.NAME + "\", \"" + Property.NAME + "\"],\"" +
PropagationConstraint.ADD_PROPERTY + "\":\""+ addConstraint + "\",\"" + PropagationConstraint.ADD_PROPERTY + "\":\""+ addConstraint + "\",\"" +
PropagationConstraint.REMOVE_PROPERTY + "\":\"" + removeConstraint + "\"" + PropagationConstraint.REMOVE_PROPERTY + "\":\"" + removeConstraint + "\",\"" +
PropagationConstraint.DELETE_PROPERTY + "\":\"" + deleteConstraint + "\"" +
"}"; "}";
logger.debug(pcString); logger.debug(pcString);
@ -147,6 +167,7 @@ public class PropagationConstraintTest {
Assert.assertTrue(propagationConstraint instanceof PropagationConstraint); Assert.assertTrue(propagationConstraint instanceof PropagationConstraint);
Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0); Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0);
Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0); Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0);
Assert.assertTrue(propagationConstraint.getDeleteConstraint().compareTo(deleteConstraint)==0);
logger.debug(ElementMapper.marshal(propagationConstraint)); logger.debug(ElementMapper.marshal(propagationConstraint));