X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Fsharedontology%2Fwizard%2FSharedOntologyExporter.java;h=5813ff673fd4eb22363d1d2e2ae6674f22f78b85;hp=eae7695747153fdc45ddeb66eda859f49775a7da;hb=9214a600c9401b06057fc2c10ea86a0ce0218d87;hpb=bb61be97905f72c01fd99e21c263546c88edc5f7 diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExporter.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExporter.java index eae769574..5813ff673 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExporter.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sharedontology/wizard/SharedOntologyExporter.java @@ -15,7 +15,6 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.nio.file.Path; -import java.nio.file.Paths; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.SubMonitor; @@ -24,8 +23,6 @@ import org.simantics.Simantics; import org.simantics.databoard.binding.error.BindingException; import org.simantics.databoard.serialization.SerializationException; import org.simantics.db.ReadGraph; -import org.simantics.db.common.request.UniqueRead; -import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; import org.simantics.graph.refactoring.FixExportedOntology; import org.simantics.modeling.ModelingUtils; @@ -40,6 +37,7 @@ import org.slf4j.LoggerFactory; public class SharedOntologyExporter implements IRunnableWithProgress { private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(SharedOntologyExporter.class); + ExportPlan exportModel; public SharedOntologyExporter(ExportPlan exportModel) { @@ -64,43 +62,49 @@ public class SharedOntologyExporter implements IRunnableWithProgress { void exportModel(SubMonitor mon) throws IOException, DatabaseException, SerializationException, BindingException{ try { - doExport(mon, exportModel.exportLocation, exportModel.model, exportModel.tgAndPgraph); - + doExport(mon, exportModel.exportLocation, exportModel.model, exportModel.writeTransferableGraph, exportModel.dumpStructure); } catch (DatabaseException e) { - e.printStackTrace(); - Logger.defaultLogError(e); + LOGGER.error("Failed to export shared ontology", e); mon.setCanceled(true); ShowMessage.showError("Export failed.", "Internal application error in export. See log for details."); } finally { mon.setWorkRemaining(0); } } - - public static void doExport(IProgressMonitor monitor, File location, final LibraryInfo info) throws DatabaseException, IOException { - doExport(monitor, location, info, false); + + public static void doExport(IProgressMonitor monitor, File location, LibraryInfo info) throws DatabaseException, IOException { + doExport(monitor, location, info, false, false); } - - public static void doExport(IProgressMonitor monitor, File location, final LibraryInfo info, boolean pgraphAndTg) throws DatabaseException, IOException { - ModelingUtils.exportSharedOntology(monitor, Simantics.getSession(), location,Constants.SHARED_LIBRARY_FORMAT, Constants.SHARED_LIBRARY_CURRENT_VERSION, info); - if (pgraphAndTg) { - try { - Path input = Paths.get(location.toURI()); - FixExportedOntology.createTGAndPGraph(input); - DumpOntologyStructure data = Simantics.sync(new UniqueRead() { - @Override - public DumpOntologyStructure perform(ReadGraph graph) throws DatabaseException { - DumpOntologyStructure result = new DumpOntologyStructure(); - result.read(graph, info.library.getResource()); - return result; - } - + public static void doExport(IProgressMonitor monitor, File location, LibraryInfo info, boolean writeTg, boolean dumpStructure) throws DatabaseException, IOException { + int work = 1 + (writeTg ? 1 : 0) + (dumpStructure ? 1 : 0); + SubMonitor mon = SubMonitor.convert(monitor, work); + + ModelingUtils.exportSharedOntology(mon.split(1, SubMonitor.SUPPRESS_NONE), Simantics.getSession(), location, Constants.SHARED_LIBRARY_FORMAT, Constants.SHARED_LIBRARY_CURRENT_VERSION, info); + + Path input = location.toPath(); + + if (writeTg) { + try { + mon.subTask("Writing transferable graph"); + FixExportedOntology.createTGAndPGraph(input, false); + mon.worked(1); + } catch (Exception e) { + LOGGER.error("Could not generate Transferable Graph", e); + } + } + if (dumpStructure) { + try { + monitor.subTask("Dumping library structure"); + DumpOntologyStructure data = Simantics.getSession().syncRequest((ReadGraph graph) -> { + return new DumpOntologyStructure().read(graph, info.library.getResource()); }); data.write(new File(new File(location.getParent(), location.getName() + ".dump"), info.library.getName())); + mon.worked(1); } catch (Exception e) { - LOGGER.error("Could not generate TG and Pgraph", e); + LOGGER.error("Could not generate shared library structure dump", e); } - } + } } - + }