diff --git a/CHANGELOG.md b/CHANGELOG.md index f0b6726..e34417e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for Information System Model -## [v5.0.1-SNAPSHOT] +## [v5.1.0-SNAPSHOT] - Added class Discovery to make new model discovery easier - Added the possibility to exclude IS Model package in discovery diff --git a/pom.xml b/pom.xml index d74e18c..474c79a 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.information-system information-system-model - 5.0.1-SNAPSHOT + 5.1.0-SNAPSHOT Information System Model Information System Model is the reference model of the gCube Information System jar diff --git a/src/main/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintImpl.java b/src/main/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintImpl.java index 401754d..0a0296a 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintImpl.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintImpl.java @@ -19,6 +19,10 @@ public final class PropagationConstraintImpl extends PropertyImpl implements Pro */ private static final long serialVersionUID = -4708881022038107688L; + @JsonFormat(shape=JsonFormat.Shape.STRING) + @JsonProperty(value=DELETE_PROPERTY) + protected DeleteConstraint deleteConstraint; + @JsonFormat(shape=JsonFormat.Shape.STRING) @JsonProperty(value=REMOVE_PROPERTY) protected RemoveConstraint removeConstraint; @@ -31,6 +35,16 @@ public final class PropagationConstraintImpl extends PropertyImpl implements Pro super(); } + @Override + public DeleteConstraint getDeleteConstraint() { + return this.deleteConstraint; + } + + @Override + public void setDeleteConstraint(DeleteConstraint deleteConstraint) { + this.deleteConstraint = deleteConstraint; + } + @Override public RemoveConstraint getRemoveConstraint() { return this.removeConstraint; diff --git a/src/main/java/org/gcube/informationsystem/model/impl/relations/ConsistsOfImpl.java b/src/main/java/org/gcube/informationsystem/model/impl/relations/ConsistsOfImpl.java index 315c188..14dfa32 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/relations/ConsistsOfImpl.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/relations/ConsistsOfImpl.java @@ -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.properties.PropagationConstraint; 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.relations.ConsistsOf; @@ -29,10 +30,7 @@ public class ConsistsOfImpl extends } public ConsistsOfImpl(S source, T target) { - super(source, target, null); - propagationConstraint = new PropagationConstraintImpl(); - propagationConstraint.setAddConstraint(AddConstraint.propagate); - propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan); + this(source, target, null); } public ConsistsOfImpl(S source, T target, @@ -41,7 +39,8 @@ public class ConsistsOfImpl extends if(this.propagationConstraint==null) { this.propagationConstraint = new PropagationConstraintImpl(); this.propagationConstraint.setAddConstraint(AddConstraint.propagate); - this.propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan); + this.propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade); + this.propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade); } } diff --git a/src/main/java/org/gcube/informationsystem/model/impl/relations/IsRelatedToImpl.java b/src/main/java/org/gcube/informationsystem/model/impl/relations/IsRelatedToImpl.java index 819ade1..41ed4ec 100644 --- a/src/main/java/org/gcube/informationsystem/model/impl/relations/IsRelatedToImpl.java +++ b/src/main/java/org/gcube/informationsystem/model/impl/relations/IsRelatedToImpl.java @@ -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.properties.PropagationConstraint; 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.relations.IsRelatedTo; @@ -28,10 +29,7 @@ public abstract class IsRelatedToImpl ex } public IsRelatedToImpl(S source, T target) { - super(source, target, null); - propagationConstraint = new PropagationConstraintImpl(); - propagationConstraint.setAddConstraint(AddConstraint.unpropagate); - propagationConstraint.setRemoveConstraint(RemoveConstraint.keep); + this(source, target, null); } public IsRelatedToImpl(S source, T target, @@ -41,6 +39,7 @@ public abstract class IsRelatedToImpl ex this.propagationConstraint = new PropagationConstraintImpl(); this.propagationConstraint.setAddConstraint(AddConstraint.unpropagate); this.propagationConstraint.setRemoveConstraint(RemoveConstraint.keep); + this.propagationConstraint.setDeleteConstraint(DeleteConstraint.keep); } } diff --git a/src/main/java/org/gcube/informationsystem/model/reference/properties/PropagationConstraint.java b/src/main/java/org/gcube/informationsystem/model/reference/properties/PropagationConstraint.java index 4752983..a8a6479 100644 --- a/src/main/java/org/gcube/informationsystem/model/reference/properties/PropagationConstraint.java +++ b/src/main/java/org/gcube/informationsystem/model/reference/properties/PropagationConstraint.java @@ -19,8 +19,8 @@ import org.gcube.informationsystem.utils.Version; * or directly to the relation. * * The default values of propagation constraints are: - * - IsRelatedTo: remove=keep, add=unpropagate; - * - ConsistsOf : remove=cascade, add=propagate. + * - IsRelatedTo: delete=keep, remove=keep, add=unpropagate; + * - ConsistsOf : delete=cascade, remove=cascade, add=propagate. * * 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 DELETE_PROPERTY = "delete"; public static final String REMOVE_PROPERTY = "remove"; 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, - * or directly on the relation, then the same remove action apart on + * When a 'delete' action is performed on the source Entity of the relation, + * 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 */ 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 + * When a 'delete' action is performed on the source Entity of the relation, + * or directly on the relation, then the same 'delete' 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 + * When a 'delete' action is performed on the source Entity of the relation, + * 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. */ keep @@ -66,7 +93,7 @@ public interface PropagationConstraint extends Property { /** * 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. */ 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 void setRemoveConstraint(RemoveConstraint removeConstraint); @@ -91,6 +124,4 @@ public interface PropagationConstraint extends Property { public void setAddConstraint(AddConstraint addConstraint); - - } diff --git a/src/test/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintTest.java b/src/test/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintTest.java index f0050b5..8918717 100644 --- a/src/test/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintTest.java +++ b/src/test/java/org/gcube/informationsystem/model/impl/properties/PropagationConstraintTest.java @@ -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.properties.PropagationConstraint; 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.Property; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; @@ -29,6 +30,7 @@ public class PropagationConstraintTest { PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); propagationConstraint.setAddConstraint(AddConstraint.propagate); propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan); + propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade); String pg = ElementMapper.marshal(propagationConstraint); Property property = ElementMapper.unmarshal(Property.class, pg); @@ -44,9 +46,12 @@ public class PropagationConstraintTest { public void testPropagationConstraintByString() throws Exception { AddConstraint addConstraint = AddConstraint.propagate; RemoveConstraint removeConstraint = RemoveConstraint.cascade; + DeleteConstraint deleteConstraint = DeleteConstraint.keep; + PropagationConstraint pc = new PropagationConstraintImpl(); pc.setAddConstraint(addConstraint); pc.setRemoveConstraint(removeConstraint); + pc.setDeleteConstraint(deleteConstraint); String json = ElementMapper.marshal(pc); logger.debug(json); @@ -55,12 +60,14 @@ public class PropagationConstraintTest { Assert.assertTrue(property instanceof PropagationConstraint); Assert.assertTrue(((PropagationConstraint) property).getAddConstraint().compareTo(addConstraint)==0); Assert.assertTrue(((PropagationConstraint) property).getRemoveConstraint().compareTo(removeConstraint)==0); + Assert.assertTrue(((PropagationConstraint) property).getDeleteConstraint().compareTo(deleteConstraint)==0); logger.debug(ElementMapper.marshal(property)); PropagationConstraint propagationConstraint = ElementMapper.unmarshal(PropagationConstraint.class, json); Assert.assertTrue(propagationConstraint instanceof PropagationConstraint); Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0); Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0); + Assert.assertTrue(propagationConstraint.getDeleteConstraint().compareTo(deleteConstraint)==0); logger.debug(ElementMapper.marshal(property)); } @@ -68,19 +75,29 @@ public class PropagationConstraintTest { public void testPropagationConstraintSpecilization() throws Exception { AddConstraint addConstraint = AddConstraint.propagate; 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); Property property = ElementMapper.unmarshal(Property.class, marshalled); Assert.assertTrue(property instanceof PropagationConstraint); Assert.assertTrue(((PropagationConstraint) property).getAddConstraint().compareTo(addConstraint)==0); Assert.assertTrue(((PropagationConstraint) property).getRemoveConstraint().compareTo(removeConstraint)==0); + Assert.assertTrue(((PropagationConstraint) property).getDeleteConstraint().compareTo(deleteConstraint)==0); + logger.debug(ElementMapper.marshal(property)); PropagationConstraint propagationConstraint = ElementMapper.unmarshal(PropagationConstraint.class, marshalled); Assert.assertTrue(propagationConstraint instanceof PropagationConstraint); Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0); Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0); + Assert.assertTrue(propagationConstraint.getDeleteConstraint().compareTo(deleteConstraint)==0); logger.debug(ElementMapper.marshal(property)); } @@ -88,11 +105,14 @@ public class PropagationConstraintTest { public void testPropagationConstraintSpecilizationInside() throws Exception { AddConstraint addConstraint = AddConstraint.propagate; RemoveConstraint removeConstraint = RemoveConstraint.cascade; + DeleteConstraint deleteConstraint = DeleteConstraint.keep; + String pcString = "{" + "\"" + Element.CLASS_PROPERTY + "\":\"My" + PropagationConstraint.NAME + "\"," + "\"" + Element.SUPERCLASSES_PROPERTY + "\":[\"" + PropagationConstraint.NAME + "\", \"" + Property.NAME + "\"],\"" + PropagationConstraint.ADD_PROPERTY + "\":\""+ addConstraint + "\",\"" + - PropagationConstraint.REMOVE_PROPERTY + "\":\"" + removeConstraint + "\"" + + PropagationConstraint.REMOVE_PROPERTY + "\":\"" + removeConstraint + "\",\"" + + PropagationConstraint.DELETE_PROPERTY + "\":\"" + deleteConstraint + "\"" + "}"; logger.debug(pcString); @@ -147,6 +167,7 @@ public class PropagationConstraintTest { Assert.assertTrue(propagationConstraint instanceof PropagationConstraint); Assert.assertTrue(propagationConstraint.getAddConstraint().compareTo(addConstraint)==0); Assert.assertTrue(propagationConstraint.getRemoveConstraint().compareTo(removeConstraint)==0); + Assert.assertTrue(propagationConstraint.getDeleteConstraint().compareTo(deleteConstraint)==0); logger.debug(ElementMapper.marshal(propagationConstraint));