X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.fileimport%2Fsrc%2Forg%2Fsimantics%2Ffileimport%2Fscl%2FDropinsSCL.java;h=50fd584466bedd5849d950b9c778f80b16441fa3;hb=fa107b33201040a66ef237f3705395d74b22bb97;hp=d3fa3d0f9b6b14302e37ee4bef804d174a57e06e;hpb=8e4e41fa135641b23f68e205832e0696951c5f63;p=simantics%2Fplatform.git
diff --git a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/scl/DropinsSCL.java b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/scl/DropinsSCL.java
index d3fa3d0f9..50fd58446 100644
--- a/bundles/org.simantics.fileimport/src/org/simantics/fileimport/scl/DropinsSCL.java
+++ b/bundles/org.simantics.fileimport/src/org/simantics/fileimport/scl/DropinsSCL.java
@@ -1,107 +1,112 @@
-package org.simantics.fileimport.scl;
-
-import java.io.IOException;
-import java.nio.file.DirectoryStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Optional;
-
-import org.simantics.Simantics;
-import org.simantics.databoard.util.Base64;
-import org.simantics.db.ReadGraph;
-import org.simantics.db.Resource;
-import org.simantics.db.common.request.UniqueRead;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.service.SerialisationSupport;
-import org.simantics.fileimport.Activator;
-import org.simantics.fileimport.FileImportService;
-import org.simantics.fileimport.dropins.FileImportDropins;
-import org.simantics.layer0.Layer0;
-import org.simantics.utils.FileUtils;
-
-/**
- * SCL interface for Simantics File Import Functionality
- * See "Dropins/Core"
SCL module for more
- *
- * @author Jani Simomaa
- *
- */
-public class DropinsSCL {
-
- public static void watchDropinsFolder() {
- FileImportDropins.watchDropinsFolder();
- }
-
- public static void unwatchDropinsFolder() {
- FileImportDropins.unwatchDropinsFolder();
- }
-
- public static void uploadToDropinsBase64(String base64, String fileName) {
- // ensure that watcher is awake
- FileImportDropins.watchDropinsFolder();
- try {
- Path rootFolder = Activator.getDropinsFolder();
- Path newFile = rootFolder.resolve(fileName);
- if (Files.exists(newFile)) {
- newFile = findFreshFileName(rootFolder, fileName);
- }
- byte[] bytes = Base64.decode(base64);
- FileUtils.writeFile(newFile.toFile(), bytes);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- private static Path findFreshFileName(Path root, String fileName) throws IOException {
- int ending = fileName.lastIndexOf('.');
- String glob = fileName;
- String suffix = "";
- if (ending > -1) {
- glob = fileName.substring(0, ending);
- suffix = fileName.substring(ending);
- }
- int i = 0;
- try (DirectoryStream stream = Files.newDirectoryStream(root, glob)) {
- Iterator iter = stream.iterator();
- while (iter.hasNext()) {
- iter.next();
- i++;
- }
- }
- String newFileName = glob + "_" + i + suffix;
- return root.resolve(newFileName);
- }
-
- public static Map getUploadedFiles() throws DatabaseException {
- Map results = FileImportService.getPathsAndResources();
- Map result = Simantics.getSession().syncRequest(new UniqueRead