]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Handling property change from Literal to SCLValue 28/3728/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 19 Dec 2019 11:36:21 +0000 (13:36 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 19 Dec 2019 11:36:21 +0000 (13:36 +0200)
gitlab #20

Change-Id: I223b01159ad872ede440b1c194f68915ec18a0f1

org.simantics.interop.update/src/org/simantics/interop/update/model/AddDeleteUpdateOp.java
org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java

index 54e91b83d7da17724b9ebf51e5d7b6f7aab17259..f270d46e87df8f169e47c2dd4339063cdcc54ae1 100644 (file)
@@ -55,7 +55,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))
index 54d2f76f55fe083f1af1f54a904cf0cc79709dd6..9a95984ed76986707b4991d18f2301d451c7f647 100644 (file)
@@ -5,6 +5,7 @@ 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;
 import org.simantics.utils.datastructures.Pair;
 
 public class PropertyChange {
@@ -90,19 +91,29 @@ public class PropertyChange {
                        graph.deny(leftSubject, pair.first.getPredicate(),pair.first.getObject());
                        return;
                } 
+               Layer0 L0 = Layer0.getInstance(graph);
                Resource s = leftSubject;
-               Object value = null;
-               if (customValue != null)
-                       value = customValue;
-               else if (graph.hasValue(pair.second.getObject())) {
-                       value = graph.getValue(pair.second.getObject());
-               }
-               Resource pred = pair.second.getPredicate();
-               if (value != null) {
+               if (graph.isInstanceOf(pair.second.getObject(), L0.Literal)) {
+                       Object value = null;
+                       if (customValue != null)
+                               value = customValue;
+                       else if (graph.hasValue(pair.second.getObject())) {
+                               value = graph.getValue(pair.second.getObject());
+                       }
+                       Resource pred = pair.second.getPredicate();
+                       if (value != null) {
+                               graph.deny(s, pred);
+                               graph.claimLiteral(s, pred, value);
+                       } else {
+                               graph.deny(s,pred);
+                       }
+               } else if (graph.isInstanceOf(pair.second.getObject(), L0.SCLValue)) {
+                       Resource pred = pair.second.getPredicate();
                        graph.deny(s, pred);
-                       graph.claimLiteral(s, pred, value);
-               } else {
-                       graph.deny(s,pred);
+                       Resource valueResource = graph.newResource();
+                       graph.claim(valueResource, L0.InstanceOf, graph.getSingleObject(pair.second.getObject(), L0.InstanceOf));
+                       AddDeleteUpdateOp.copyProperties(graph, pair.second.getObject(), valueResource);
+                       graph.claim(s, pred, valueResource);
                }
                applied = true;
        }