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;
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.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;
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<DirectStatements> {
public DirectStatements result;
}
}
+ @Deprecated
public static AbstractEventHandler emptyOnClick(ReadGraph graph) throws DatabaseException {
return new EventHandler() {
@Override
};
}
+ @Deprecated
public static AbstractEventHandler writeEventHandler(ReadGraph graph, final Variable variable, final Function fn) {
final Session session = graph.getSession();
return (String)response;
}
return null;
- } catch (Throwable t) {
- t.printStackTrace();
} finally {
sclContext.put("graph", oldGraph);
sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
}
- return null;
-
}
});
};
}
+ @Deprecated
public static AbstractEventHandler readEventHandler(ReadGraph graph, final Variable variable, final Function fn) {
final Session session = graph.getSession();
return (String)response;
}
return null;
- } catch (Throwable t) {
- t.printStackTrace();
} finally {
sclContext.put("graph", oldGraph);
sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
}
- return null;
-
}
});
};
}
+ @Deprecated
public static AbstractEventHandler readEventHandler2(ReadGraph graph, final Function fn) {
final Session session = graph.getSession();
return (CommandResult)response;
}
return null;
- } catch (Throwable t) {
- t.printStackTrace();
} finally {
sclContext.put("graph", oldGraph);
sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
}
- return null;
-
}
});
final List<TCon> effects = ServerSCLHandlerValueRequest.getEffects(graph, anyFunction);
- final Function1<CommandContext, CommandResult> fn = anyFunction.getValue(graph);
- String expression = anyFunction.getPropertyValue(graph, "expression");
+ Function1<CommandContext, CommandResult> 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) {
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);
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);
};
}
+ @Deprecated
public static AbstractEventHandler writeEventHandler2(ReadGraph graph, final Function fn) {
final Session session = graph.getSession();
return (CommandResult)response;
}
return null;
- } catch (Throwable t) {
- t.printStackTrace();
} finally {
sclContext.put("graph", oldGraph);
sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
}
- return null;
-
}
});
};
}
+
+ @Deprecated
public static AbstractEventHandler eventHandler2(ReadGraph graph, final Function fn) {
return new AbstractEventHandler() {
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());
};
}
+ @Deprecated
public static AbstractEventHandler eventHandler(ReadGraph graph, final Function fn) {
return new AbstractEventHandler() {
if(response instanceof String) {
result = (String)response;
}
- } catch (Throwable t) {
- t.printStackTrace();
} finally {
sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
}
} 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;
}
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);
}
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