X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Futils%2FDumpOntologyStructure.java;fp=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Futils%2FDumpOntologyStructure.java;h=5bb3d9ca21c95d30bb5d96200d41caade8bf59df;hp=79622f15e5839bf1cae00c32dc228e75967eb427;hb=9214a600c9401b06057fc2c10ea86a0ce0218d87;hpb=7bc4de702166fe57dd45b7f161847e6d21d83bb4 diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/DumpOntologyStructure.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/DumpOntologyStructure.java index 79622f15e..5bb3d9ca2 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/DumpOntologyStructure.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/DumpOntologyStructure.java @@ -30,7 +30,7 @@ public class DumpOntologyStructure { private static final Logger LOGGER = LoggerFactory.getLogger(DumpOntologyStructure.class); private Resource ontology; - + private Map names = new HashMap<>(); private Map parents = new HashMap<>(); private Map libraryFolders = new HashMap<>(); @@ -40,11 +40,11 @@ public class DumpOntologyStructure { parents.put(r, container); names.put(r, NameUtils.getSafeName(graph, r)); } - + private Collection containers() { return parents.values(); } - + private void readHierarchy(ReadGraph graph, Resource container) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); for(Resource r : CommonDBUtils.objectsWithType(graph, container, L0.ConsistsOf, L0.Entity)) { @@ -94,30 +94,27 @@ public class DumpOntologyStructure { } } - public void read(ReadGraph graph, Resource ontology) throws DatabaseException { + public DumpOntologyStructure read(ReadGraph graph, Resource ontology) throws DatabaseException { this.ontology = ontology; readHierarchy(graph, ontology); readGeneric(graph); + return this; } - - private File escapeFile(File file) { + private File escapeFile(File file) { if(file.exists()) return file; - return new File(escapeFile(file.getParentFile()), FileUtils.escapeFileName(file.getName())); - } - + public void write(File unsafeFolder) throws IOException { File folder = escapeFile(unsafeFolder); - if(folder.exists()) - FileUtils.deleteAll(folder); + FileUtils.delete(folder.toPath()); folder.mkdirs(); writeDirectories(folder); writeResources(folder); } - + private File getFolder(File root, Resource library) { if(ontology.equals(library)) return root; @@ -147,11 +144,11 @@ public class DumpOntologyStructure { writeResource(rootFolder, r); } } - + private boolean isParent(Resource r) { return parents.values().contains(r); } - + private void writeResource(File rootFolder, Resource resource) throws IOException { byte[] dump = contentDumps.get(resource); if(dump == null) @@ -168,4 +165,4 @@ public class DumpOntologyStructure { FileUtils.writeFile(getFile(rootFolder, resource), bytes); } -} +} \ No newline at end of file