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:
parent
a338ff3ef2
commit
30dc36d5bc
|
@ -12,8 +12,8 @@ import java.util.UUID;
|
|||
import org.codehaus.jettison.json.JSONException;
|
||||
import org.codehaus.jettison.json.JSONObject;
|
||||
import org.gcube.informationsystem.model.embedded.Header;
|
||||
import org.gcube.informationsystem.model.embedded.RelationProperty;
|
||||
import org.gcube.informationsystem.model.embedded.RelationProperty.ReferentialIntegrity;
|
||||
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
||||
import org.gcube.informationsystem.model.embedded.PropagationConstraint.RemoveConstraint;
|
||||
import org.gcube.informationsystem.model.entity.Entity;
|
||||
import org.gcube.informationsystem.model.entity.Facet;
|
||||
import org.gcube.informationsystem.model.entity.Resource;
|
||||
|
@ -400,42 +400,44 @@ public abstract class RelationManagement<R extends Relation> {
|
|||
ResourceRegistryException {
|
||||
getEdge();
|
||||
|
||||
ReferentialIntegrity referentialIntegrity = ReferentialIntegrity.onDeleteKeep;
|
||||
RemoveConstraint removeConstraint = RemoveConstraint.keep;
|
||||
|
||||
try {
|
||||
RelationProperty relationProperty = Utility.getEmbedded(
|
||||
RelationProperty.class, edge, Relation.RELATION_PROPERTY);
|
||||
referentialIntegrity = relationProperty.getReferentialIntegrity();
|
||||
PropagationConstraint propagationConstraint = Utility.getEmbedded(
|
||||
PropagationConstraint.class, edge, Relation.PROPAGATION_CONSTRAINT);
|
||||
if(propagationConstraint.getRemoveConstraint()!=null){
|
||||
removeConstraint = propagationConstraint.getRemoveConstraint();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
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.",
|
||||
RelationProperty.REFERENTIAL_INTEGRITY,
|
||||
Relation.PROPAGATION_CONSTRAINT,
|
||||
Utility.toJsonString(edge, true),
|
||||
ReferentialIntegrity.onDeleteKeep);
|
||||
RemoveConstraint.keep);
|
||||
}
|
||||
|
||||
Vertex target = edge.getVertex(Direction.IN);
|
||||
edge.remove();
|
||||
|
||||
switch (referentialIntegrity) {
|
||||
case onDeleteCascade:
|
||||
switch (removeConstraint) {
|
||||
case cascade:
|
||||
deleteTargetVertex(target);
|
||||
break;
|
||||
|
||||
case onDeleteCascadeWhenOrphan:
|
||||
case cascadeWhenOrphan:
|
||||
Iterable<Edge> iterable = target.getEdges(Direction.IN);
|
||||
Iterator<Edge> iterator = iterable.iterator();
|
||||
if (iterator.hasNext()) {
|
||||
logger.trace(
|
||||
"{} point to {} which is not orphan. Giving {} directive, it will be keep.",
|
||||
edge, target, referentialIntegrity);
|
||||
edge, target, removeConstraint);
|
||||
} else {
|
||||
deleteTargetVertex(target);
|
||||
}
|
||||
break;
|
||||
|
||||
case onDeleteKeep:
|
||||
case keep:
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
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.CPUFacetImpl;
|
||||
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.utils.Entities;
|
||||
import org.gcube.informationsystem.impl.utils.Utility;
|
||||
import org.gcube.informationsystem.model.embedded.RelationProperty;
|
||||
import org.gcube.informationsystem.model.embedded.RelationProperty.ReferentialIntegrity;
|
||||
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
||||
import org.gcube.informationsystem.model.embedded.PropagationConstraint.RemoveConstraint;
|
||||
import org.gcube.informationsystem.model.entity.Facet;
|
||||
import org.gcube.informationsystem.model.entity.Resource;
|
||||
import org.gcube.informationsystem.model.entity.facet.AccessPointFacet;
|
||||
|
@ -274,10 +274,11 @@ public class ERManagementTest extends ScopedTest {
|
|||
hostingNode.attachFacet(isIdentifiedBy);
|
||||
|
||||
|
||||
RelationProperty relationProperty = new RelationPropertyImpl();
|
||||
relationProperty.setReferentialIntegrity(ReferentialIntegrity.onDeleteCascade);
|
||||
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
||||
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
||||
|
||||
Hosts<HostingNode, EService> hosts = new HostsImpl<HostingNode, EService>(
|
||||
hostingNode, eService, relationProperty);
|
||||
hostingNode, eService, propagationConstraint);
|
||||
hostingNode.attachResource(hosts);
|
||||
|
||||
resourceManagement = new ResourceManagement();
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue