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;
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;
import org.simantics.modeling.ModelingUtils.LibraryInfo;
+import org.simantics.modeling.utils.DumpOntologyStructure;
import org.simantics.utils.ui.dialogs.ShowMessage;
+import org.slf4j.LoggerFactory;
/**
* @author Antti Villberg
*/
public class SharedOntologyExporter implements IRunnableWithProgress {
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(SharedOntologyExporter.class);
ExportPlan exportModel;
public SharedOntologyExporter(ExportPlan exportModel) {
void exportModel(SubMonitor mon) throws IOException, DatabaseException, SerializationException, BindingException{
try {
- doExport(mon, exportModel.exportLocation, exportModel.model);
+ doExport(mon, exportModel.exportLocation, exportModel.model, exportModel.tgAndPgraph);
} catch (DatabaseException e) {
e.printStackTrace();
}
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, 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<DumpOntologyStructure>() {
+
+ @Override
+ public DumpOntologyStructure perform(ReadGraph graph) throws DatabaseException {
+ DumpOntologyStructure result = new DumpOntologyStructure();
+ result.read(graph, info.library.getResource());
+ return result;
+ }
+
+ });
+ data.write(new File(new File(location.getParent(), location.getName() + ".dump"), info.library.getName()));
+ } catch (Exception e) {
+ LOGGER.error("Could not generate TG and Pgraph", e);
+ }
+ }
}
}