]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
SCL API for GraphFile plug-in. 83/1883/2
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 28 Jun 2018 14:40:26 +0000 (17:40 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 28 Jun 2018 14:40:26 +0000 (17:40 +0300)
gitlab #34

Change-Id: I81b9d41cfa392545df629bf9e7a6197c21effa58

bundles/org.simantics.graphfile/build.properties
bundles/org.simantics.graphfile/scl/Simantics/GraphFile.scl [new file with mode: 0644]
bundles/org.simantics.graphfile/src/org/simantics/graphfile/util/GraphFileUtil.java

index ff239f985f883566e7e84e34e7600c5a53e334fa..fe68d79aea262d63e87d030da80b94e8c3f93a67 100644 (file)
@@ -14,4 +14,5 @@ output.. = bin/
 bin.includes = META-INF/,\
                .,\
                plugin.xml,\
-               adapters.xml
+               adapters.xml,\
+               scl/
diff --git a/bundles/org.simantics.graphfile/scl/Simantics/GraphFile.scl b/bundles/org.simantics.graphfile/scl/Simantics/GraphFile.scl
new file mode 100644 (file)
index 0000000..dd28870
--- /dev/null
@@ -0,0 +1,41 @@
+import "Simantics/DB"
+import "File"
+
+    
+importJava "org.simantics.graphfile.util.GraphFileUtil" where
+    "Writes contents of a file to DB, including the timestamp"
+    @JavaName writeDataToGraphSCLhack
+    writeDataToGraph:: File -> Resource -> <WriteGraph>()
+    
+    "Writes contents of a byte array to DB"
+    @JavaName writeDataToGraph
+    writeDataToGraphBytes:: ByteArray -> Resource -> <WriteGraph>()
+    
+    "Creates a temp file of a GraphFile resource"
+    @JavaName toTempFileSCLhack
+    toTempFile :: Resource -> <ReadGraph> File
+    
+    "Writes contents of a GraphFile into a regular File"
+    @JavaName writeDataToFileSCLhack
+    writeDataToFile :: Resource -> File -> <ReadGraph>()
+    
+    "Writes contents of a file to DB, including the filename and timestamp"
+    @JavaName toGraphSCLhack
+    toGraphWithPath :: String -> Resource -> <WriteGraph>()
+    
+    "Writes contents of a file to DB, including the filename and timestamp"
+    @JavaName toGraph
+    toGraph :: File -> Resource -> <WriteGraph>()
+    
+    "Returns contents of a GraphFile as a byte array"
+    @JavaName getData
+    getData :: Resource -> <ReadGraph> ByteArray
+    
+    "Returns contents of a GraphFile as a String"
+    @JavaName getDataAsString
+    getDataAsString :: Resource -> <ReadGraph> String
+    
+    
+    
+    
+    
\ No newline at end of file
index fbfcc3a146e9c39a63853cec2faf3c6d52eaa29b..637a5d0ae3a1976f05a002d9a9096b530018fb55 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.graphfile.util;
 
 import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -34,6 +35,7 @@ import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.request.WriteResultRequest;
 import org.simantics.db.common.utils.LiteralFileUtil;
+import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.DoesNotContainValueException;
 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
@@ -41,6 +43,7 @@ import org.simantics.db.exception.NoSingleResultException;
 import org.simantics.db.exception.ServiceException;
 import org.simantics.db.request.Read;
 import org.simantics.db.service.ClusteringSupport;
+import org.simantics.db.service.TransferableGraphSupport;
 import org.simantics.graphfile.ontology.GraphFileResource;
 import org.simantics.layer0.Layer0;
 
@@ -578,4 +581,52 @@ public class GraphFileUtil {
             }
         });
     }
+    
+    /**
+     * SCL java binding cannot make difference between methods that have two versions, one with Read/WriteGraph, and one without.
+     * Hence we have to introduce a set of methods which have no alternate versions. 
+     */
+    
+    
+    public static void writeDataToGraphSCLhack(WriteGraph graph, File file, Resource graphFile) throws IOException, DatabaseException{
+       writeDataToGraph(graph, file, graphFile);
+       
+    }
+    
+    public static File toTempFileSCLhack(ReadGraph graph, Resource res)throws DatabaseException {
+       return toTempFile(graph, res);
+    }
+    
+    public static void writeDataToFileSCLhack(ReadGraph graph, Resource res, File file) throws DatabaseException, IOException {
+       writeDataToFile(graph, res, file);
+    }
+    
+    public static void toGraphSCLhack(WriteGraph graph, String filename, Resource graphFile) throws DatabaseException, IOException {
+       toGraph(graph, filename, graphFile);
+    }
+    
+    
+    public static byte[] getData(ReadGraph graph, Resource graphFile) throws DatabaseException{
+       GraphFileResource GF = GraphFileResource.getInstance(graph);
+       Resource fileData = graph.getSingleObject(graphFile, GF.HasFiledata);
+       TransferableGraphSupport tgs = graph.getService(TransferableGraphSupport.class);
+               InputStream input = tgs.getValueStream(graph, fileData);
+               DataInputStream di = new DataInputStream(input);
+               try {
+                       int length = di.readInt();
+                       byte[] content = new byte[length];
+                       di.read(content);
+                       return content;
+               } catch (IOException e) {
+                       Logger.defaultLogError(e);
+               }
+               return null;
+    }
+    
+    public static String getDataAsString(ReadGraph graph, Resource graphFile) throws DatabaseException{
+       byte[] content = getData(graph, graphFile);
+               String s =  new String(content);
+               return s;
+    }
+
 }