]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Support DB images in url requests"
authorJani Simomaa <jani.simomaa@semantum.fi>
Mon, 22 May 2017 08:09:13 +0000 (11:09 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Mon, 22 May 2017 08:09:13 +0000 (11:09 +0300)
bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/IConsoleSupport.java [new file with mode: 0644]
bundles/org.simantics.document.server/src/org/simantics/document/server/ConsoleSCLReportingHandler.java [new file with mode: 0644]
bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java
bundles/org.simantics.document.server/src/org/simantics/document/server/request/URIDocumentRequest.java

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 (file)
index 0000000..facc7b4
--- /dev/null
@@ -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<IConsole> 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 (file)
index 0000000..e227a89
--- /dev/null
@@ -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
index 20fa2a71b7b272cec574e351c715a17c25479f04..d0ec54557353555349b5e66f222002b8c86f15ed 100644 (file)
@@ -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
index 7c79e639ef98445bde2ff53b651e1550004a1aca..c4d64b68608533d5cf6429662017147ffd8ea9e5 100644 (file)
@@ -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<String, List<JSONObject>> {
 
@@ -27,16 +34,34 @@ public class URIDocumentRequest extends UnaryRead<String, List<JSONObject>> {
                        return Collections.emptyList();
                }
                
-               ArrayList<JSONObject> result = new ArrayList<JSONObject>(graph.syncRequest(new DocumentRequest(var)));
-               Collections.sort(result, new Comparator<JSONObject>() {
+       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<JSONObject> result = new ArrayList<JSONObject>(graph.syncRequest(new DocumentRequest(var)));
+                       Collections.sort(result, new Comparator<JSONObject>() {
+       
+                               @Override
+                               public int compare(JSONObject o1, JSONObject o2) {
+                                       return o1.id.compareTo(o2.id);
+                               }
+                               
+                       });
+
+                       return result;
+                       
+               } finally {
+                       sclContext.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);
+               }
                                
        }