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=0a7e004f7dcab5e75740d176100c78d59c3dfb47;hp=13444fdba944701e2454fea1174283d89045f8ca;hb=8a609b2a6559fef3d2f21224253d87c414473187;hpb=6f11a60dee43d620d500c0cf5af34a1d91c80a8b 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..0a7e004f7 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; @@ -578,6 +583,7 @@ public class Functions { } } + @Deprecated public static AbstractEventHandler emptyOnClick(ReadGraph graph) throws DatabaseException { return new EventHandler() { @Override @@ -587,6 +593,7 @@ public class Functions { }; } + @Deprecated public static AbstractEventHandler writeEventHandler(ReadGraph graph, final Variable variable, final Function fn) { final Session session = graph.getSession(); @@ -619,15 +626,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 +647,7 @@ public class Functions { }; } + @Deprecated public static AbstractEventHandler readEventHandler(ReadGraph graph, final Variable variable, final Function fn) { final Session session = graph.getSession(); @@ -676,15 +680,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 +701,7 @@ public class Functions { }; } + @Deprecated public static AbstractEventHandler readEventHandler2(ReadGraph graph, final Function fn) { final Session session = graph.getSession(); @@ -727,15 +728,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; - } }); @@ -825,10 +822,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 +843,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 +885,7 @@ public class Functions { }; } + @Deprecated public static AbstractEventHandler writeEventHandler2(ReadGraph graph, final Function fn) { final Session session = graph.getSession(); @@ -920,15 +912,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 +933,8 @@ public class Functions { }; } + + @Deprecated public static AbstractEventHandler eventHandler2(ReadGraph graph, final Function fn) { return new AbstractEventHandler() { @@ -964,14 +954,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 +968,7 @@ public class Functions { }; } + @Deprecated public static AbstractEventHandler eventHandler(ReadGraph graph, final Function fn) { return new AbstractEventHandler() { @@ -1008,8 +995,6 @@ public class Functions { if(response instanceof String) { result = (String)response; } - } catch (Throwable t) { - t.printStackTrace(); } finally { sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); } @@ -1305,4 +1290,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