X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.graph%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Frefactoring%2FFixExportedOntology.java;h=ffe174eb943b236be72e4d1a8f26808070828608;hb=8ede4cc47cef9f74682972f88bcf7730a64e7fcd;hp=ea449417d305ee7eac034af76e3ceadec07e7b79;hpb=0dc7c37151328c8ed5c4720379f5b99b62525dc1;p=simantics%2Fplatform.git
diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java
index ea449417d..ffe174eb9 100644
--- a/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java
+++ b/bundles/org.simantics.graph/src/org/simantics/graph/refactoring/FixExportedOntology.java
@@ -1,7 +1,6 @@
package org.simantics.graph.refactoring;
import java.io.BufferedInputStream;
-import java.io.DataInput;
import java.io.DataInputStream;
import java.io.InputStream;
import java.nio.file.Files;
@@ -10,7 +9,6 @@ import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import org.simantics.databoard.binding.Binding;
-import org.simantics.databoard.binding.mutable.Variant;
import org.simantics.databoard.container.DataContainer;
import org.simantics.databoard.container.DataContainers;
import org.simantics.graph.representation.PrettyPrintTG;
@@ -25,32 +23,44 @@ public class FixExportedOntology {
static TransferableGraph1 convertExportedSharedOntologyIntoBundleOntology(Path input, Path output) throws Exception {
System.out.format("Converting exported shared ontology%n\t" + input.toString() + "%nto bundle-compatible ontology%n\t" + output.toString());
try (InputStream is = new BufferedInputStream(Files.newInputStream(input), 128*1024)) {
- DataInput dis = new DataInputStream(is);
- org.simantics.databoard.container.DataContainer container =
- DataContainers.readFile(dis);
- Binding binding = TransferableGraph1.BINDING;
- TransferableGraph1 graph = (TransferableGraph1)container.content.getValue(binding);
+ Binding tgBinding = TransferableGraph1.BINDING;
+ DataContainer container = DataContainers.readFile(new DataInputStream(is), tgBinding);
+ TransferableGraph1 graph = (TransferableGraph1) container.content.getValue(tgBinding);
+
GraphRefactoringUtils.fixOntologyExport(graph);
+ container = TransferableGraphHasher.addHashToTG(container, graph);
- DataContainers.writeFile(output.toFile(), new DataContainer(
- container.format, container.version,
- container.metadata, new Variant(TransferableGraph1.BINDING, graph)));
-
+ DataContainers.writeFile(output.toFile(), container);
return graph;
-
}
}
+
+ public static void createTg(Path input) throws Exception {
+ Path output = input.getParent().resolve("graph.tg");
+ createTg(input, output);
+ }
+
+ private static void createTg(Path input, Path output) throws Exception {
+ convertExportedSharedOntologyIntoBundleOntology(input, output);
+ }
+
+ public static void createTGAndPGraph(Path input) throws Exception {
+ Path output1 = input.getParent().resolve("graph.tg");
+ TransferableGraph1 tg = convertExportedSharedOntologyIntoBundleOntology(input, output1);
+ String listing = PrettyPrintTG.print(tg, false);
+ String newName = input.getFileName().toString();
+ if (newName.contains("."))
+ newName = newName.split("\\.")[0];
+ Path output2 = input.getParent().resolve(newName + ".pgraph");
+ Files.write(output2, listing.getBytes(),StandardOpenOption.CREATE);
+ }
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("Required arguments: [