X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2FFunctions.java;h=aabe7b29ffd04dbcdff684dc899f11f2bde8c19f;hp=13444fdba944701e2454fea1174283d89045f8ca;hb=0d9b90834ce56b292c00b1a39850ed842c3e4d42;hpb=59e011d8d6e88ddebb7300cb60109c6bd43f5de8 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..aabe7b29f 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; @@ -67,13 +68,15 @@ import org.simantics.document.server.request.ServerSCLHandlerValueRequest; import org.simantics.document.server.request.ServerSCLValueRequest; import org.simantics.document.server.serverResponse.ServerResponse; import org.simantics.document.server.serverResponse.SuccessResponse; +import org.simantics.document.server.state.StateNodeManager; +import org.simantics.document.server.state.StateRealm; +import org.simantics.document.server.state.StateSessionManager; import org.simantics.modeling.ModelingResources; -import org.simantics.modeling.scl.SCLRealm; -import org.simantics.modeling.scl.SCLSessionManager; import org.simantics.modeling.services.CaseInsensitiveComponentFunctionNamingStrategy; 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 +99,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; @@ -196,11 +202,11 @@ public class Functions { } DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class); - PrimitivePropertyStatementsProcedure foo = new PrimitivePropertyStatementsProcedure(); + //PrimitivePropertyStatementsProcedure foo = new PrimitivePropertyStatementsProcedure(); - dqs.forEachDirectPersistentStatement(graph, parentRes, foo); + DirectStatements ds = dqs.getDirectPersistentStatements(graph, parentRes); - for(Statement stm : foo.result) { + for(Statement stm : ds) { Resource predicate = stm.getPredicate(); PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate)); @@ -578,6 +584,7 @@ public class Functions { } } + @Deprecated public static AbstractEventHandler emptyOnClick(ReadGraph graph) throws DatabaseException { return new EventHandler() { @Override @@ -587,6 +594,7 @@ public class Functions { }; } + @Deprecated public static AbstractEventHandler writeEventHandler(ReadGraph graph, final Variable variable, final Function fn) { final Session session = graph.getSession(); @@ -619,15 +627,11 @@ public class Functions { return (String)response; } return null; - } catch (Throwable t) { - t.printStackTrace(); } finally { sclContext.put("graph", oldGraph); sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); } - return null; - } }); @@ -644,6 +648,7 @@ public class Functions { }; } + @Deprecated public static AbstractEventHandler readEventHandler(ReadGraph graph, final Variable variable, final Function fn) { final Session session = graph.getSession(); @@ -676,15 +681,11 @@ public class Functions { return (String)response; } return null; - } catch (Throwable t) { - t.printStackTrace(); } finally { sclContext.put("graph", oldGraph); sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); } - return null; - } }); @@ -701,6 +702,7 @@ public class Functions { }; } + @Deprecated public static AbstractEventHandler readEventHandler2(ReadGraph graph, final Function fn) { final Session session = graph.getSession(); @@ -727,15 +729,11 @@ public class Functions { return (CommandResult)response; } return null; - } catch (Throwable t) { - t.printStackTrace(); } finally { sclContext.put("graph", oldGraph); sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); } - return null; - } }); @@ -759,12 +757,12 @@ public class Functions { final List effects = ServerSCLHandlerValueRequest.getEffects(graph, anyFunction); - final Function1 fn = anyFunction.getValue(graph); - String expression = anyFunction.getPropertyValue(graph, "expression"); + Function1 fn = anyFunction.getValue(graph); + //String expression = anyFunction.getPropertyValue(graph, "expression"); final Session session = graph.getSession(); - return new AbstractResponseHandler(expression) { + return new AbstractResponseHandler(fn) { private String formatError(RequestProcessor proc, Throwable t) { @@ -825,10 +823,7 @@ public class Functions { Object oldGraph = sclContext.put("graph", graph); Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer); try { - Object response = fn.apply(parameters); - return response; - } catch (Throwable t) { - return new org.simantics.document.server.serverResponse.Error(formatError(graph, t)); + return fn.apply(parameters); } finally { sclContext.put("graph", oldGraph); sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); @@ -849,10 +844,7 @@ public class Functions { Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer); try { - Object response = fn.apply(parameters); - return response; - } catch (Throwable t) { - return new org.simantics.document.server.serverResponse.Error(formatError(graph, t)); + return fn.apply(parameters); } finally { sclContext.put("graph", oldGraph); sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); @@ -894,6 +886,7 @@ public class Functions { }; } + @Deprecated public static AbstractEventHandler writeEventHandler2(ReadGraph graph, final Function fn) { final Session session = graph.getSession(); @@ -920,15 +913,11 @@ public class Functions { return (CommandResult)response; } return null; - } catch (Throwable t) { - t.printStackTrace(); } finally { sclContext.put("graph", oldGraph); sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); } - return null; - } }); @@ -945,6 +934,8 @@ public class Functions { }; } + + @Deprecated public static AbstractEventHandler eventHandler2(ReadGraph graph, final Function fn) { return new AbstractEventHandler() { @@ -964,14 +955,10 @@ public class Functions { return (CommandResult)response; } return null; - } catch (Throwable t) { - t.printStackTrace(); } finally { sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); } - return null; - } catch (Throwable e) { Logger.defaultLogError(e); return new org.simantics.document.server.serverResponse.Error(e.getMessage()); @@ -982,6 +969,7 @@ public class Functions { }; } + @Deprecated public static AbstractEventHandler eventHandler(ReadGraph graph, final Function fn) { return new AbstractEventHandler() { @@ -1008,8 +996,6 @@ public class Functions { if(response instanceof String) { result = (String)response; } - } catch (Throwable t) { - t.printStackTrace(); } finally { sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); } @@ -1162,11 +1148,6 @@ public class Functions { } else { - String id = sclStateKey(graph, base, self, ref); - - SCLRealm realm = SCLSessionManager.getOrCreateSCLRealm(base.getURI(graph) + "/__scl__"); - realm.getConnection().setVariable(id, getSCLType(defaultValue), defaultValue); - return defaultValue; } @@ -1176,9 +1157,9 @@ public class Functions { String id = sclStateKey(graph, base, self, ref); - SCLRealm realm = SCLSessionManager.getOrCreateSCLRealm(base.getURI(graph)+"/__scl__"); - realm.getConnection().setVariable(id, getSCLType(value), value); - realm.refreshVariablesSync(); + StateRealm realm = (StateRealm) StateSessionManager.getInstance().getOrCreateRealm(graph, base.getURI(graph)+"/__scl__"); + StateNodeManager nodeManager = (StateNodeManager) realm.getNodeManager(); + nodeManager.setState(id, value); } @@ -1305,4 +1286,27 @@ public class Functions { return graph.syncRequest(new PathExistsRequest(context)); } + public static String compileDocumentSCLValueExpression(ReadGraph graph, Variable context) { + try { + ServerSCLValueRequest.validate(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