From 8959bb33806d2252cdf09e42386afd242919630a Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Tue, 31 Oct 2017 07:44:32 +0200 Subject: [PATCH] ValueType modifications to satisfy compilation of SCL-expressions Also adding a validator for plain ServerSCLValueRequest (DOC.SCLValue) refs #7575 Change-Id: Ib34fbd9c53ec2003680b9546e7344506100a01b0 --- .../graph/Components.pgraph | 12 ++++---- .../graph/Properties.pgraph | 8 +++--- .../scl/Document/All.scl | 2 ++ .../simantics/document/server/Functions.java | 28 +++++++++++++++++++ .../server/request/ServerSCLValueRequest.java | 7 +++-- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/bundles/org.simantics.document.base.ontology/graph/Components.pgraph b/bundles/org.simantics.document.base.ontology/graph/Components.pgraph index 5fa11e906..8c03f41c5 100644 --- a/bundles/org.simantics.document.base.ontology/graph/Components.pgraph +++ b/bundles/org.simantics.document.base.ontology/graph/Components.pgraph @@ -21,13 +21,13 @@ connectionPoint = COMPONENTS.connectionPoint : L0.Template >-- %relation sclAttribute = COMPONENTS.sclAttribute : L0.Template - @template %subject %relation %command + @template %subject %relation %command %valueType %subject >-- %relation L0.Asserts _ : L0.Assertion L0.HasPredicate %relation L0.HasObject _ : DOC.SCLValue - L0.HasValueType "String" + L0.HasValueType %valueType L0.SCLValue.expression %command L0.default false @@ -49,6 +49,7 @@ DOC.sclValue : L0.Template L0.HasValueType %valueType DOC.SCLValue compileDocumentSCLValueExpression self""" "Variable -> String" @L0.assert L0.ConvertsToValueWith DOC.Functions.sclValue : L0.ExternalValue @@ -59,13 +60,12 @@ COMPONENTS.Component Variable + compileDocumentSCLValueExpression :: Variable -> String + propertyValueCached :: Serializable a => Typeable a => Variable -> String -> a propertyValueCached var prop = propertyValueCached_ var prop binding diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java index 13444fdba..a6e9d6ab6 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java @@ -38,6 +38,7 @@ import org.simantics.db.layer0.request.PropertyInfoRequest; import org.simantics.db.layer0.request.VariableProperty; import org.simantics.db.layer0.request.VariableRead; import org.simantics.db.layer0.request.VariableValueWithBinding; +import org.simantics.db.layer0.scl.SCLDatabaseException; import org.simantics.db.layer0.variable.ConstantPropertyVariable; import org.simantics.db.layer0.variable.ProxyChildVariable; import org.simantics.db.layer0.variable.ProxySessionRequest; @@ -74,6 +75,7 @@ import org.simantics.modeling.services.CaseInsensitiveComponentFunctionNamingStr import org.simantics.modeling.services.ComponentNamingStrategy; import org.simantics.operation.Layer0X; import org.simantics.project.IProject; +import org.simantics.scl.compiler.module.repository.ImportFailureException; import org.simantics.scl.compiler.types.TCon; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; @@ -96,11 +98,14 @@ import org.simantics.simulation.project.IExperimentManager; import org.simantics.structural2.variables.Connection; import org.simantics.structural2.variables.StandardProceduralChildVariable; import org.simantics.structural2.variables.VariableConnectionPointDescriptor; +import org.slf4j.LoggerFactory; import gnu.trove.map.hash.THashMap; public class Functions { + private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Functions.class); + private static class PrimitivePropertyStatementsProcedure implements AsyncProcedure { public DirectStatements result; @@ -1305,4 +1310,27 @@ public class Functions { return graph.syncRequest(new PathExistsRequest(context)); } + public static String compileDocumentSCLValueExpression(ReadGraph graph, Variable context) { + try { + ServerSCLValueRequest.compile(graph, context); + return ""; + } catch (Exception e) { + return resolveIssueMessage(e); + } + } + + private static String resolveIssueMessage(Exception e) { + if (e instanceof ImportFailureException) + return ""; + if (e.getCause() != null && e.getCause() instanceof ImportFailureException) + return ""; + if (e instanceof SCLDatabaseException) { + SCLDatabaseException ee = (SCLDatabaseException) e; + return ee.getMessage(); + } + if (LOGGER.isDebugEnabled()) + LOGGER.debug("", e); + return e.getMessage(); + } + } \ No newline at end of file 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 e6cdf6ff5..68602de69 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 @@ -91,8 +91,7 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< SCLContext sclContext = SCLContext.getCurrent(); Object oldGraph = sclContext.get("graph"); try { - Function1 exp = graph.syncRequest(new ServerSCLValueRequest(graph, context), - TransientCacheListener.>instance()); + Function1 exp = compile(graph, context); sclContext.put("graph", graph); return exp.apply(context); } catch (DatabaseException e) { @@ -103,6 +102,10 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< sclContext.put("graph", oldGraph); } } + + public static Function1 compile(ReadGraph graph, Variable context) throws DatabaseException { + return graph.syncRequest(new ServerSCLValueRequest(graph, context), TransientCacheListener.>instance()); + } @Override protected String getExpressionText(ReadGraph graph) -- 2.47.1