X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.interop.update%2Fsrc%2Forg%2Fsimantics%2Finterop%2Fupdate%2Fmodel%2FAddDeleteUpdateOp.java;h=a5058647379f65c182f7a97272a1bd27e3ad1ac4;hb=refs%2Fchanges%2F43%2F4643%2F1;hp=54e91b83d7da17724b9ebf51e5d7b6f7aab17259;hpb=c86f0b2bf8c58932738dba38b9ef6ee0dba30026;p=simantics%2Finterop.git diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/AddDeleteUpdateOp.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/AddDeleteUpdateOp.java index 54e91b8..a505864 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/AddDeleteUpdateOp.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/AddDeleteUpdateOp.java @@ -24,6 +24,11 @@ public abstract class AddDeleteUpdateOp extends UpdateOp { super(changes); } + public AddDeleteUpdateOp(boolean add, GraphChanges changes) { + super(changes); + this.add = add; + } + @Override public boolean isAdd() { return add; @@ -37,10 +42,10 @@ public abstract class AddDeleteUpdateOp extends UpdateOp { @Override public boolean requiresOp(UpdateOp op) { if (add) { - if (getParentOps().contains(op)) + if (getParentOps().contains(op) && op.isAdd()) return true; } else { - if (getSubOps().contains(op)) + if (getSubOps().contains(op) && op.isDelete()) return true; } return false; @@ -55,7 +60,7 @@ public abstract class AddDeleteUpdateOp extends UpdateOp { } } - protected static void copyProperties(WriteGraph g, Resource source, Resource destination) throws DatabaseException { + public static void copyProperties(WriteGraph g, Resource source, Resource destination) throws DatabaseException { Layer0 l0 = Layer0.getInstance(g); for (Statement s : g.getStatements(source, l0.HasProperty)) { if (s.isAsserted(source)) @@ -82,11 +87,36 @@ public abstract class AddDeleteUpdateOp extends UpdateOp { g.claim(destination, s.getPredicate(), valueResource); copyProperties(g, s.getObject(), valueResource); } else { - throw new DatabaseException("Expected to copy property resource " + s.getObject()); + Resource type = g.getPossibleType(s.getObject(), l0.Value); + if (type != null && g.hasStatement(type, l0.Enumeration, type)) { + g.deny(destination, s.getPredicate()); + g.claim(destination, s.getPredicate(), s.getObject()); + } else { + throw new DatabaseException("Expected to copy property resource " + s.getObject()); + } + } + } + } + + public static void copyTags(WriteGraph g, Resource source, Resource destination) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(g); + for (Statement s : g.getStatements(source, L0.IsWeaklyRelatedTo)) { + if (s.getObject().equals(source)) { + g.claim(destination, s.getPredicate(), destination); } } } + public static void copyTypes(WriteGraph g, Resource source, Resource destination) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(g); + for (Resource r : g.getObjects(source, L0.InstanceOf)) + g.claim(destination, L0.InstanceOf, r); + for (Resource r : g.getObjects(source, L0.Inherits)) + g.claim(destination, L0.Inherits, r); + for (Resource r : g.getObjects(source, L0.SubrelationOf)) + g.claim(destination, L0.SubrelationOf, r); + } + protected void copyIssues(WriteGraph g, Resource source, Resource destination) throws DatabaseException { Layer0 l0 = Layer0.getInstance(g); IssueResource ir = IssueResource.getInstance(g);