--- /dev/null
+package org.simantics.interop.update.model;
+
+import java.util.Collection;
+
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.interop.test.GraphChanges;
+import org.simantics.layer0.Layer0;
+
+/**
+ * Simple update operation, where
+ * addition is based on copying L0.InstanceOf and L0.HasProperty relations.
+ * deletion is deny.
+ *
+ * @author luukkainen
+ *
+ */
+public class SimpleObjectUpdateOp extends AddDeleteUpdateOp {
+
+ private Statement r;
+ protected Resource copyObj;
+
+ public SimpleObjectUpdateOp(Statement r, boolean add, GraphChanges changes) {
+ super(changes);
+ this.r = r;
+ this.add = add;
+ }
+
+ @Override
+ protected void _apply(WriteGraph g) throws DatabaseException {
+ if (add) {
+ Resource parent = null;
+ if (getChanges().getComparable().containsRight(r.getSubject()))
+ parent = getChanges().getComparable().getLeft(r.getSubject());
+ else {
+ Collection<UpdateOp> parentOps = getParentOps();
+ if (parentOps.size() != 1)
+ throw new RuntimeException("Parent not found.");
+ parent = parentOps.iterator().next().getCreatedResource();
+ }
+ if (parent == null)
+ throw new RuntimeException("Parent not found.");
+
+ Layer0 L0 = Layer0.getInstance(g);
+
+ Resource sourceObj = r.getObject();
+
+ copyObj = g.newResource();
+ for (Resource t : g.getObjects(sourceObj, L0.InstanceOf)) {
+ g.claim(copyObj, L0.InstanceOf, t);
+ }
+ copyProperties(g, sourceObj, copyObj);
+ g.claim(parent, r.getPredicate(), copyObj);
+
+ } else {
+
+ Resource sourceObj= r.getObject();
+ g.deny(sourceObj);
+
+ }
+
+ }
+
+ @Override
+ public Statement getStatement() {
+ return r;
+ }
+
+ @Override
+ public Resource getResource() {
+ return r.getObject();
+ }
+
+ @Override
+ public Resource getCreatedResource() {
+ return copyObj;
+ }
+
+
+}