From: Jani Simomaa Date: Mon, 22 May 2017 08:09:13 +0000 (+0300) Subject: Merge "Support DB images in url requests" X-Git-Tag: v1.29.0~38 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=bd1e84d0abcb2cc4c8324a8881f29fa1eb3751fc;hp=03279d65d445ff24515b7de8c7a5cfc69b18dfba Merge "Support DB images in url requests" --- diff --git a/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/IConsoleSupport.java b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/IConsoleSupport.java new file mode 100644 index 000000000..facc7b403 --- /dev/null +++ b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/IConsoleSupport.java @@ -0,0 +1,10 @@ +package org.simantics.document.server.io; + +import java.util.Collection; + +public interface IConsoleSupport { + void registerConsole(String sessionGUID, IConsole console); + IConsole getConsole(String sessionGUID); + IConsole findConsole(String consoleGUID); + Collection getConsoles(); +} diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/ConsoleSCLReportingHandler.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/ConsoleSCLReportingHandler.java new file mode 100644 index 000000000..e227a89ca --- /dev/null +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/ConsoleSCLReportingHandler.java @@ -0,0 +1,34 @@ +package org.simantics.document.server; + +import org.simantics.document.server.io.IConsole; +import org.simantics.scl.runtime.reporting.SCLReportingHandler; + +public class ConsoleSCLReportingHandler implements SCLReportingHandler { + + private final IConsole console; + + public ConsoleSCLReportingHandler(IConsole console) { + this.console = console; + } + + @Override + public void print(String text) { + console.addMessage(text); + } + + @Override + public void printError(String error) { + console.addMessage(error); + } + + @Override + public void printCommand(String command) { + console.addMessage(command); + } + + @Override + public void didWork(double amount) { + console.addMessage("didWork " + amount); + } + +} \ No newline at end of file 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 20fa2a71b..d0ec54557 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 @@ -1173,35 +1173,5 @@ public class Functions { return graph.syncRequest(new PathExistsRequest(context)); } - static class ConsoleSCLReportingHandler implements SCLReportingHandler { - - private final IConsole console; - - ConsoleSCLReportingHandler(IConsole console) { - this.console = console; - } - - @Override - public void print(String text) { - console.addMessage(text); - } - - @Override - public void printError(String error) { - console.addMessage(error); - } - - @Override - public void printCommand(String command) { - console.addMessage(command); - } - - @Override - public void didWork(double amount) { - console.addMessage("didWork " + amount); - } - - } - } \ No newline at end of file diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java index 7c79e639e..c4d64b686 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java @@ -5,12 +5,19 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.ProxyVariables; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; +import org.simantics.document.server.ConsoleSCLReportingHandler; import org.simantics.document.server.JSONObject; +import org.simantics.document.server.io.IConsole; +import org.simantics.document.server.io.IConsoleSupport; +import org.simantics.scl.runtime.SCLContext; +import org.simantics.scl.runtime.reporting.SCLReportingHandler; public class URIDocumentRequest extends UnaryRead> { @@ -27,16 +34,34 @@ public class URIDocumentRequest extends UnaryRead> { return Collections.emptyList(); } - ArrayList result = new ArrayList(graph.syncRequest(new DocumentRequest(var))); - Collections.sort(result, new Comparator() { + IConsoleSupport cs = Simantics.getSession().getService(IConsoleSupport.class); + Variable root = ProxyVariables.proxyVariableRoot(graph, var); + if(root == null) return Collections.emptyList(); + Variable session = root.getParent(graph); + String guid = session.getName(graph); + IConsole console = cs.getConsole(guid); + SCLReportingHandler printer = (console != null) ? new ConsoleSCLReportingHandler(console) + : (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER); + SCLContext sclContext = SCLContext.getCurrent(); + Object oldPrinter = sclContext.put(SCLReportingHandler.REPORTING_HANDLER, printer); - @Override - public int compare(JSONObject o1, JSONObject o2) { - return o1.id.compareTo(o2.id); - } + try { - }); - return result; + ArrayList result = new ArrayList(graph.syncRequest(new DocumentRequest(var))); + Collections.sort(result, new Comparator() { + + @Override + public int compare(JSONObject o1, JSONObject o2) { + return o1.id.compareTo(o2.id); + } + + }); + + return result; + + } finally { + sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter); + } }