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 IConsoleSupport cs = Simantics.getSession().getService(IConsoleSupport.class);
38 Variable root = ProxyVariables.proxyVariableRoot(graph, var);
39 if(root == null) return Collections.emptyList();
40 Variable session = root.getParent(graph);
41 String guid = session.getName(graph);
42 IConsole console = cs.getConsole(guid);
43 SCLReportingHandler printer = (console != null) ? new ConsoleSCLReportingHandler(console)
44 : (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
45 SCLContext sclContext = SCLContext.getCurrent();
46 Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer);
50 ArrayList<JSONObject> result = new ArrayList<JSONObject>(graph.syncRequest(new DocumentRequest(var)));
51 Collections.sort(result, new Comparator<JSONObject>() {
54 public int compare(JSONObject o1, JSONObject o2) {
55 return o1.id.compareTo(o2.id);
63 sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);