Added remove in propagation constraint

feature/26102
Luca Frosini 1 year ago
parent 7307eefeab
commit af4de28ebb

@ -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

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

@ -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;

@ -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<S extends Resource, T extends Facet> 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<S extends Resource, T extends Facet> 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);
}
}

@ -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<S extends Resource, T extends Resource> 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<S extends Resource, T extends Resource> ex
this.propagationConstraint = new PropagationConstraintImpl();
this.propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
this.propagationConstraint.setRemoveConstraint(RemoveConstraint.keep);
this.propagationConstraint.setDeleteConstraint(DeleteConstraint.keep);
}
}

@ -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 DeleteConstraint {
/**
* 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 '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 '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
* 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
* 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
* 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);
}

@ -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));

Loading…
Cancel
Save