Sync git svn branch with SVN repository r33189.
[simantics/platform.git] / bundles / org.simantics.fileimport / src / org / simantics / fileimport / scl / DropinsSCL.java
index 0758d3e784ef735ad98471e0b5e34cafde33f748..cad45187721a8caef5345cea807c426d4a9c9f1a 100644 (file)
@@ -2,17 +2,40 @@ package org.simantics.fileimport.scl;
 \r
 import java.io.IOException;\r
 import java.nio.file.Path;\r
+import java.util.HashMap;\r
 import java.util.Map;\r
 import java.util.Optional;\r
 \r
+import org.simantics.Simantics;\r
 import org.simantics.databoard.util.Base64;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.UniqueRead;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.service.SerialisationSupport;\r
 import org.simantics.fileimport.Activator;\r
 import org.simantics.fileimport.FileImportService;\r
 import org.simantics.fileimport.dropins.FileImportDropins;\r
+import org.simantics.layer0.Layer0;\r
 import org.simantics.utils.FileUtils;\r
 \r
+/**\r
+ * SCL interface for Simantics File Import Functionality\r
+ * See <code>"Dropins/Core"</code> SCL module for more\r
+ * \r
+ * @author Jani Simomaa\r
+ *\r
+ */\r
 public class DropinsSCL {\r
 \r
+    public static void watchDropinsFolder() {\r
+        FileImportDropins.watchDropinsFolder();\r
+    }\r
+    \r
+    public static void unwatchDropinsFolder() {\r
+        FileImportDropins.unwatchDropinsFolder();\r
+    }\r
+    \r
     public static void uploadToDropinsBase64(String base64, String fileName) {\r
         // ensure that watcher is awake\r
         FileImportDropins.watchDropinsFolder();\r
@@ -26,8 +49,29 @@ public class DropinsSCL {
         }\r
     }\r
     \r
-    public static Map<String, Long> getUploadedFiles() {\r
-        return FileImportService.getPathsAndResources();\r
+    public static Map<String, Long> getUploadedFiles() throws DatabaseException {\r
+        Map<String, String> results = FileImportService.getPathsAndResources();\r
+        Map<String, Long> result = Simantics.getSession().syncRequest(new UniqueRead<Map<String, Long>>() {\r
+\r
+            @Override\r
+            public Map<String, Long> perform(ReadGraph graph) throws DatabaseException {\r
+                Map<String, Long> map = new HashMap<>();\r
+                for (Map.Entry<String, String> entry : results.entrySet()) {\r
+                    String value = (String) entry.getValue();\r
+                    Long id = Long.valueOf(value);\r
+                    SerialisationSupport ss = graph.getService(SerialisationSupport.class);\r
+                    try {\r
+                        Resource r = ss.getResource(id);\r
+                        String name = graph.getRelatedValue(r, Layer0.getInstance(graph).HasName);\r
+                        map.put(name, id);\r
+                    } catch (DatabaseException e) {\r
+                        e.printStackTrace();\r
+                    }\r
+                }\r
+                return map;\r
+            }\r
+        });\r
+        return result;\r
     }\r
     \r
     public static void removeFileForId(long id) {\r