From: jsimomaa Date: Wed, 21 Nov 2018 08:31:37 +0000 (+0200) Subject: Fix errors with procedural user components for computational values X-Git-Tag: v1.43.0~136^2~256 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=e807368d0e75809e0797d9cea1063b046fabf352;p=simantics%2Fplatform.git Fix errors with procedural user components for computational values gitlab #169 Change-Id: I1d95429ea1c49ca2f8bd20d447500513a3e6f87a --- diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/SCLComputationalValue.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/SCLComputationalValue.java index 83382adb3..743f8e445 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/SCLComputationalValue.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/SCLComputationalValue.java @@ -24,11 +24,14 @@ import org.simantics.scl.runtime.function.Function1; */ public class SCLComputationalValue extends ContextualRelatedValue { + // TODO: unify and merge CompileValueRequest and CompileResourceValueRequest as one @Override public Function1 getFunction(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException { - if (s != null && p != null && o != null) { - return CompileValueRequest.compile(graph, s, o, p); + if (p != null && o != null) { + // we are now at Variable context + return CompileValueRequest.compile(graph, o, p); } else if (o != null) { + // we are now at Resource context return CompileResourceValueRequest.compile(graph, o); } else { throw new DatabaseException("Could not compile SCL expression: s=" + s + " p=" + p + " o=" + o); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/CompileValueRequest.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/CompileValueRequest.java index 1eb01aa39..11f3ad185 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/CompileValueRequest.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/scl/CompileValueRequest.java @@ -34,19 +34,15 @@ public class CompileValueRequest extends AbstractExpressionCompilationRequest compile(ReadGraph graph, Resource component, Resource literal, Resource predicate) throws DatabaseException { + public static Function1 compile(ReadGraph graph, Resource literal, Resource predicate) throws DatabaseException { SCLContext sclContext = SCLContext.getCurrent(); Object oldGraph = sclContext.get("graph"); try { - Function1 exp = graph.syncRequest(new CompileValueRequest(component, literal, predicate), - TransientCacheListener.instance()); + Function1 exp = graph.syncRequest(new CompileValueRequest(literal, predicate), TransientCacheListener.instance()); sclContext.put("graph", graph); return exp; } catch (DatabaseException e) { diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RuntimeEnvironmentRequest2.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RuntimeEnvironmentRequest2.java index ca8bc07cd..c51428f2f 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RuntimeEnvironmentRequest2.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RuntimeEnvironmentRequest2.java @@ -113,9 +113,14 @@ public class RuntimeEnvironmentRequest2 extends BinaryRead sclModules = graph.syncRequest(new ObjectsWithType(parameter, L0.ConsistsOf, L0.SCLModule)); - for (Resource sclModule : sclModules) - environmentSpecification.importModule(graph.getURI(sclModule), ""); + if (parameter != null) { + Collection sclModules = graph.syncRequest(new ObjectsWithType(parameter, L0.ConsistsOf, L0.SCLModule)); + for (Resource sclModule : sclModules) { + environmentSpecification.importModule(graph.getURI(sclModule), ""); + } + } else { + // `parameter` is optional and can be null for e.g. procedural user components + } Resource mainModule = Layer0Utils.getPossibleChild(graph, parameter2, "SCLMain"); if(mainModule != null) diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java index 09f1523a2..7d1af5f4c 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java @@ -1,5 +1,6 @@ package org.simantics.document.server.request; +import java.util.Collections; import java.util.Map; import org.simantics.databoard.Bindings; @@ -70,7 +71,7 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< } public ServerSCLValueRequest(ReadGraph graph, Resource s, Resource o, Resource p) throws DatabaseException { - this(getComponentTypeAndRoot(graph, s), o, resolveExpectedValueType(graph, p)); + this(getComponentTypeAndRoot(graph, s, o), o, resolveExpectedValueType(graph, p)); } private static Pair getComponentTypeAndRoot(ReadGraph graph, Variable property) throws DatabaseException { @@ -88,7 +89,7 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< return Pair.make(parent.getType(graph), root); } - private static Pair getComponentTypeAndRoot(ReadGraph graph, Resource component) throws DatabaseException { + private static Pair getComponentTypeAndRoot(ReadGraph graph, Resource component, Resource literal) throws DatabaseException { if(component != null) { Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component)); if(type != null) { @@ -108,8 +109,14 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< return Pair.make(null, root); } } - } - throw new IllegalStateException(); + // TODO: For Antti to consider and fix later + // Introduced to handle procedural user components where component == null + } else if (literal != null) { + Resource root = graph.syncRequest(new IndexRoot(literal)); + return Pair.make(null, root); + } else { + throw new DatabaseException("Couldn't resolve component type and root for component == null && literal == null"); + } } public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException { @@ -160,9 +167,16 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< public CompilationContext perform(ReadGraph graph) throws DatabaseException { RuntimeEnvironment runtimeEnvironment = graph.syncRequest(getRuntimeEnvironmentRequest(parameter.first, parameter.second)); - Map propertyMap = + Map propertyMap; + if (parameter.first != null) { + propertyMap = graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()), TransientCacheListener.>instance()); + } else { + // TODO: Antti to consider + // To handle procedural user components + propertyMap = Collections.emptyMap(); + } return new CompilationContext(runtimeEnvironment, propertyMap); } }); diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/ReadComponentTypeInterfaceRequest.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/ReadComponentTypeInterfaceRequest.java index a93cbe8d4..6ac607e4f 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/ReadComponentTypeInterfaceRequest.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/scl/ReadComponentTypeInterfaceRequest.java @@ -2,6 +2,7 @@ package org.simantics.structural2.scl; import gnu.trove.map.hash.THashMap; +import java.util.Collections; import java.util.Map; import org.simantics.databoard.Bindings; @@ -50,11 +51,16 @@ public class ReadComponentTypeInterfaceRequest extends ResourceRead perform(ReadGraph graph) throws DatabaseException { - + if (resource == null) + return Collections.emptyMap(); + THashMap result = new THashMap(); - collect(graph, resource, result); + // TODO: For Antti to consider + // resource == null with procedural user components + if (resource != null) + collect(graph, resource, result); //for(Resource t : graph.getSupertypes(resource)) collect(graph, t, result); return result; diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/FixedConnection.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/FixedConnection.java index 7257ca4c5..ecafac42f 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/FixedConnection.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/FixedConnection.java @@ -93,13 +93,14 @@ public class FixedConnection implements Connection, Connection2 { for (Pair cp : cps) { Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first); Variable cp2 = component.getPossibleProperty(graph, cp.second); - if (cp2 != null) + if (cp2 != null) { for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, component, cp.second, relationType)) { result.add(desc.getURI(graph)); } - else - LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph)); + } else { + logWarn(graph, cp, component, procedural); + } } return result; } @@ -107,14 +108,15 @@ public class FixedConnection implements Connection, Connection2 { @Override public Collection getConnectionPointDescriptors(ReadGraph graph, Resource relationType) throws DatabaseException { - Set result = new THashSet(); + Set result = new THashSet<>(); for (Pair cp : cps) { Variable component = cp.first == null ? procedural : procedural.getChild(graph, cp.first); Variable cp2 = component.getPossibleProperty(graph, cp.second); - if (cp2 != null) + if (cp2 != null) { result.addAll(ConnectionBrowser.flatten(graph, component, cp.second, relationType)); - else - LOGGER.warn("no cp " + cp.first + " for " + component.getURI(graph)); + } else { + logWarn(graph, cp, component, procedural); + } } return result; } @@ -153,14 +155,16 @@ public class FixedConnection implements Connection, Connection2 { @Override public Collection getConnectionPointDescriptors(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException { - Set result = new THashSet(); + Set result = new THashSet<>(); + Variable procedural = component.getParent(graph); for (Pair cp : cps) { - Variable base = cp.first == null ? component.getParent(graph) : component; + Variable base = cp.first == null ? procedural : procedural.getChild(graph, cp.first); Variable cp2 = base.getPossibleProperty(graph, cp.second); - if (cp2 != null) + if (cp2 != null) { result.addAll(ConnectionBrowser.flatten(graph, base, cp.second, relationType)); - else - LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph)); + } else { + logWarn(graph, cp, base, procedural); + } } return result; } @@ -168,17 +172,19 @@ public class FixedConnection implements Connection, Connection2 { @Override public Collection getConnectionPoints(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException { - Set result = new THashSet(); + Set result = new THashSet<>(); + Variable procedural = component.getParent(graph); for (Pair cp : cps) { - Variable base = cp.first == null ? component.getParent(graph) : component; + Variable base = cp.first == null ? procedural : procedural.getChild(graph, cp.first); Variable cp2 = base.getPossibleProperty(graph, cp.second); - if (cp2 != null) + if (cp2 != null) { for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, base, cp.second, relationType)) { result.add(desc.getVariable(graph)); } - else - LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph)); + } else { + logWarn(graph, cp, base, procedural); + } } return result; } @@ -186,17 +192,19 @@ public class FixedConnection implements Connection, Connection2 { @Override public Collection getConnectionPointURIs(ReadGraph graph, Variable component, Resource relationType) throws DatabaseException { - Set result = new THashSet(); + Set result = new THashSet<>(); + Variable procedural = component.getParent(graph); for (Pair cp : cps) { - Variable base = cp.first == null ? component.getParent(graph) : component; + Variable base = cp.first == null ? procedural : procedural.getChild(graph, cp.first); Variable cp2 = base.getPossibleProperty(graph, cp.second); - if (cp2 != null) + if (cp2 != null) { for (VariableConnectionPointDescriptor desc : ConnectionBrowser.flatten(graph, base, cp.second, relationType)) { result.add(desc.getURI(graph)); } - else - LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph)); + } else { + logWarn(graph, cp, base, procedural); + } } return result; } @@ -206,4 +214,11 @@ public class FixedConnection implements Connection, Connection2 { return this; } + private static void logWarn(ReadGraph graph, Pair cp, Variable base, Variable procedural) throws DatabaseException { + LOGGER.warn("no cp " + cp.first + " for " + base.getURI(graph)); + LOGGER.warn(" proc: " + procedural.getURI(graph)); + LOGGER.warn(" rel: " + graph.getURI(cp.second)); + LOGGER.warn(" base: " + base.getURI(graph)); + } + } \ No newline at end of file