]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Copying SCLValues 23/3723/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 18 Dec 2019 18:49:03 +0000 (20:49 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 18 Dec 2019 18:49:03 +0000 (20:49 +0200)
gitlab #20

Change-Id: I2e46e71ba0c5df147bd1362eb23af082950fa455

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

index 854ad543a9f19f7d42f3e5eabdec96acdd9bacca..54e91b83d7da17724b9ebf51e5d7b6f7aab17259 100644 (file)
@@ -60,20 +60,29 @@ public abstract class AddDeleteUpdateOp extends UpdateOp {
                for (Statement s : g.getStatements(source, l0.HasProperty)) {
                        if (s.isAsserted(source))
                                continue;
-                       Object value = g.getPossibleValue(s.getObject());
-                       System.out.println(NameUtils.getSafeName(g, s.getSubject()) + " " + NameUtils.getSafeName(g, s.getPredicate()) + " " + NameUtils.getSafeName(g, s.getObject()) + " " + value);
-                       if (value != null) {
-                               Statement valueStm = g.getPossibleStatement(destination, s.getPredicate());
-                               Resource valueResource = null;
-                               if (valueStm != null && !valueStm.isAsserted(destination))
-                                       valueResource = valueStm.getObject();
-                               if (valueResource == null) {
-                                       valueResource = g.newResource();
-                                       g.claim(valueResource, l0.InstanceOf, g.getSingleObject(s.getObject(), l0.InstanceOf));
-                                       g.claim(destination, s.getPredicate(), valueResource);
+                       if (g.isInstanceOf(s.getObject(), l0.Literal)) {
+                               Object value = g.getPossibleValue(s.getObject());
+                               System.out.println(NameUtils.getSafeName(g, s.getSubject()) + " " + NameUtils.getSafeName(g, s.getPredicate()) + " " + NameUtils.getSafeName(g, s.getObject()) + " " + value);
+                               if (value != null) {
+                                       Statement valueStm = g.getPossibleStatement(destination, s.getPredicate());
+                                       Resource valueResource = null;
+                                       if (valueStm != null && !valueStm.isAsserted(destination))
+                                               valueResource = valueStm.getObject();
+                                       if (valueResource == null) {
+                                               valueResource = g.newResource();
+                                               g.claim(valueResource, l0.InstanceOf, g.getSingleObject(s.getObject(), l0.InstanceOf));
+                                               g.claim(destination, s.getPredicate(), valueResource);
+                                       }
+                                       g.claimValue(valueResource, value);
+                                       //g.claimLiteral(destination, s.getPredicate(), value);
                                }
-                               g.claimValue(valueResource, value);
-                               //g.claimLiteral(destination, s.getPredicate(), value);
+                       } else if (g.isInstanceOf(s.getObject(), l0.SCLValue)) {
+                               Resource valueResource = g.newResource();
+                               g.claim(valueResource, l0.InstanceOf, g.getSingleObject(s.getObject(), l0.InstanceOf));
+                               g.claim(destination, s.getPredicate(), valueResource);
+                               copyProperties(g, s.getObject(), valueResource);
+                       } else {
+                               throw new DatabaseException("Expected to copy property resource " + s.getObject());
                        }
                }
        }