From: jsimomaa Date: Tue, 19 Mar 2019 08:27:17 +0000 (+0200) Subject: Fix server SCL handler value request for procedural user components X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F12%2F2812%2F1;p=simantics%2Fplatform.git Fix server SCL handler value request for procedural user components gitlab #277 Change-Id: Iedfbcec6411f98a197eff947673c0400fcd0d4b8 (cherry picked from commit 050e5b0c7c58b6c65f89789f3e551e6bea622ecf) --- diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java index ab5e7a8e4..8ca55eaa5 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLHandlerValueRequest.java @@ -1,5 +1,6 @@ package org.simantics.document.server.request; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -65,7 +66,7 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR } public ServerSCLHandlerValueRequest(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 { @@ -83,7 +84,7 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR 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) { @@ -95,8 +96,15 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR Resource root = graph.syncRequest(new IndexRoot(doc)); return Pair.make(componentType, root); } + // 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"); } - throw new IllegalStateException(); + //throw new IllegalStateException(); } public static List getEffects(ReadGraph graph, Variable context) throws DatabaseException { @@ -158,9 +166,19 @@ public class ServerSCLHandlerValueRequest extends AbstractExpressionCompilationR @Override public CompilationContext perform(ReadGraph graph) throws DatabaseException { RuntimeEnvironment runtimeEnvironment = graph.syncRequest(getRuntimeEnvironmentRequest(parameter.first, parameter.second)); - Map propertyMap = - graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()), - TransientCacheListener.>instance()); + 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(); + } +// Map propertyMap = +// graph.syncRequest(new ReadComponentTypeInterfaceRequest(parameter.first, runtimeEnvironment.getEnvironment()), +// TransientCacheListener.>instance()); return new CompilationContext(runtimeEnvironment, propertyMap); } });