1 package org.simantics.document.server.request;
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.Comparator;
8 import org.simantics.Simantics;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.common.request.UnaryRead;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.variable.ProxyVariables;
13 import org.simantics.db.layer0.variable.Variable;
14 import org.simantics.db.layer0.variable.Variables;
15 import org.simantics.document.server.ConsoleSCLReportingHandler;
16 import org.simantics.document.server.JSONObject;
17 import org.simantics.document.server.io.IConsole;
18 import org.simantics.document.server.io.IConsoleSupport;
19 import org.simantics.scl.runtime.SCLContext;
20 import org.simantics.scl.runtime.reporting.SCLReportingHandler;
22 public class URIDocumentRequest extends UnaryRead<String, List<JSONObject>> {
24 public URIDocumentRequest(String var) {
29 public List<JSONObject> perform(ReadGraph graph) throws DatabaseException {
31 Variable var = Variables.getPossibleVariable(graph, parameter);
33 Variables.getPossibleVariable(graph, parameter);
34 return Collections.emptyList();
37 IConsole console = null;
38 IConsoleSupport cs = Simantics.getSession().peekService(IConsoleSupport.class);
40 Variable root = ProxyVariables.proxyVariableRoot(graph, var);
42 return Collections.emptyList();
43 Variable session = root.getParent(graph);
44 String guid = session.getName(graph);
45 console = cs.getConsole(guid);
48 SCLContext sclContext = SCLContext.getCurrent();
49 SCLReportingHandler printer = (console != null) ? new ConsoleSCLReportingHandler(console)
50 : (SCLReportingHandler) sclContext.get(SCLReportingHandler.REPORTING_HANDLER);
51 Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer);
54 List<JSONObject> result = new ArrayList<>(graph.syncRequest(new DocumentRequest(var)));
55 Collections.sort(result, COMPARATOR);
58 sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
63 private static final Comparator<JSONObject> COMPARATOR = (o1, o2) -> o1.id.compareTo(o2.id);