From c201a20a77db051116870d6c7eece50374293824 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Thu, 19 Dec 2019 13:36:21 +0200 Subject: [PATCH] Handling property change from Literal to SCLValue gitlab #20 Change-Id: I223b01159ad872ede440b1c194f68915ec18a0f1 --- .../update/model/AddDeleteUpdateOp.java | 2 +- .../interop/update/model/PropertyChange.java | 33 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) 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..f270d46 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 @@ -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)) diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java index 54d2f76..9a95984 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/PropertyChange.java @@ -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; } -- 2.47.1