Substituted relation property with PropagationConstraint

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@141285 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-12-20 15:51:57 +00:00
parent a338ff3ef2
commit 30dc36d5bc
3 changed files with 236 additions and 196 deletions

View File

@ -12,8 +12,8 @@ import java.util.UUID;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.gcube.informationsystem.model.embedded.Header; import org.gcube.informationsystem.model.embedded.Header;
import org.gcube.informationsystem.model.embedded.RelationProperty; import org.gcube.informationsystem.model.embedded.PropagationConstraint;
import org.gcube.informationsystem.model.embedded.RelationProperty.ReferentialIntegrity; import org.gcube.informationsystem.model.embedded.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.entity.Entity; import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.entity.Facet; import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource; import org.gcube.informationsystem.model.entity.Resource;
@ -400,42 +400,44 @@ public abstract class RelationManagement<R extends Relation> {
ResourceRegistryException { ResourceRegistryException {
getEdge(); getEdge();
ReferentialIntegrity referentialIntegrity = ReferentialIntegrity.onDeleteKeep; RemoveConstraint removeConstraint = RemoveConstraint.keep;
try { try {
RelationProperty relationProperty = Utility.getEmbedded( PropagationConstraint propagationConstraint = Utility.getEmbedded(
RelationProperty.class, edge, Relation.RELATION_PROPERTY); PropagationConstraint.class, edge, Relation.PROPAGATION_CONSTRAINT);
referentialIntegrity = relationProperty.getReferentialIntegrity(); if(propagationConstraint.getRemoveConstraint()!=null){
removeConstraint = propagationConstraint.getRemoveConstraint();
}
} catch (Exception e) { } catch (Exception e) {
logger.warn("Error while getting {} from {}. Assuming {}. " logger.warn("Error while getting {} from {}. Assuming {}. "
+ "This is really strange ad should not occur. " + "This is really strange and should not occur. "
+ "Please Investigate it.", + "Please Investigate it.",
RelationProperty.REFERENTIAL_INTEGRITY, Relation.PROPAGATION_CONSTRAINT,
Utility.toJsonString(edge, true), Utility.toJsonString(edge, true),
ReferentialIntegrity.onDeleteKeep); RemoveConstraint.keep);
} }
Vertex target = edge.getVertex(Direction.IN); Vertex target = edge.getVertex(Direction.IN);
edge.remove(); edge.remove();
switch (referentialIntegrity) { switch (removeConstraint) {
case onDeleteCascade: case cascade:
deleteTargetVertex(target); deleteTargetVertex(target);
break; break;
case onDeleteCascadeWhenOrphan: case cascadeWhenOrphan:
Iterable<Edge> iterable = target.getEdges(Direction.IN); Iterable<Edge> iterable = target.getEdges(Direction.IN);
Iterator<Edge> iterator = iterable.iterator(); Iterator<Edge> iterator = iterable.iterator();
if (iterator.hasNext()) { if (iterator.hasNext()) {
logger.trace( logger.trace(
"{} point to {} which is not orphan. Giving {} directive, it will be keep.", "{} point to {} which is not orphan. Giving {} directive, it will be keep.",
edge, target, referentialIntegrity); edge, target, removeConstraint);
} else { } else {
deleteTargetVertex(target); deleteTargetVertex(target);
} }
break; break;
case onDeleteKeep: case keep:
break; break;
default: default:

View File

@ -10,7 +10,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.gcube.informationsystem.impl.embedded.RelationPropertyImpl; import org.gcube.informationsystem.impl.embedded.PropagationConstraintImpl;
import org.gcube.informationsystem.impl.entity.facet.AccessPointFacetImpl; import org.gcube.informationsystem.impl.entity.facet.AccessPointFacetImpl;
import org.gcube.informationsystem.impl.entity.facet.CPUFacetImpl; import org.gcube.informationsystem.impl.entity.facet.CPUFacetImpl;
import org.gcube.informationsystem.impl.entity.facet.EventFacetImpl; import org.gcube.informationsystem.impl.entity.facet.EventFacetImpl;
@ -24,8 +24,8 @@ import org.gcube.informationsystem.impl.relation.IsIdentifiedByImpl;
import org.gcube.informationsystem.impl.relation.isrelatedto.HostsImpl; import org.gcube.informationsystem.impl.relation.isrelatedto.HostsImpl;
import org.gcube.informationsystem.impl.utils.Entities; import org.gcube.informationsystem.impl.utils.Entities;
import org.gcube.informationsystem.impl.utils.Utility; import org.gcube.informationsystem.impl.utils.Utility;
import org.gcube.informationsystem.model.embedded.RelationProperty; import org.gcube.informationsystem.model.embedded.PropagationConstraint;
import org.gcube.informationsystem.model.embedded.RelationProperty.ReferentialIntegrity; import org.gcube.informationsystem.model.embedded.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.entity.Facet; import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource; import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.entity.facet.AccessPointFacet; import org.gcube.informationsystem.model.entity.facet.AccessPointFacet;
@ -274,10 +274,11 @@ public class ERManagementTest extends ScopedTest {
hostingNode.attachFacet(isIdentifiedBy); hostingNode.attachFacet(isIdentifiedBy);
RelationProperty relationProperty = new RelationPropertyImpl(); PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
relationProperty.setReferentialIntegrity(ReferentialIntegrity.onDeleteCascade); propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
Hosts<HostingNode, EService> hosts = new HostsImpl<HostingNode, EService>( Hosts<HostingNode, EService> hosts = new HostsImpl<HostingNode, EService>(
hostingNode, eService, relationProperty); hostingNode, eService, propagationConstraint);
hostingNode.attachResource(hosts); hostingNode.attachResource(hosts);
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();