]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Refactored import code to use MigrationUtils.importMigrated (fixes #4192)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 21 Mar 2013 09:31:40 +0000 (09:31 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 21 Mar 2013 09:31:40 +0000 (09:31 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27182 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ontology/graph/Migration.pgraph
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java

index 42345d3128af4256110dcdff490573a2f37fa9fa..7d1354690328cb2e734050526bcb8575aea24ffe 100644 (file)
@@ -8,14 +8,34 @@ move : L0.Template
             L0.NamespaceMigrationStep.Prefix.from %from\r
             L0.NamespaceMigrationStep.Prefix.to %to\r
             \r
-MIGRATION = SYSDYN."from1.6to1.7" : L0.MigrationSequence\r
+MIGRATION = SYSDYN.Migration : L0.Library\r
+            \r
+MIGRATION.fromModel1 : L0.Migration\r
+  L0.Migration.format "sysdynModel"\r
+  L0.Migration.from 1\r
+  L0.Migration.step FROM16TO17\r
+  L0.Migration.priority 1.0\r
+  \r
+MIGRATION.fromModule1 : L0.Migration\r
+  L0.Migration.format "sysdynModule"\r
+  L0.Migration.from 1\r
+  L0.Migration.step FROM16TO17\r
+  L0.Migration.priority 1.0\r
+\r
+MIGRATION.fromFunctionLibrary1 : L0.Migration\r
+  L0.Migration.format "sysdynFunctionLibrary"\r
+  L0.Migration.from 1\r
+  L0.Migration.step FROM16TO17\r
+  L0.Migration.priority 1.0    \r
+              \r
+FROM16TO17 = MIGRATION."from1.6to1.7" : L0.MigrationSequence\r
     @L0.list\r
-        MIGRATION.Ontologies\r
-        MIGRATION.Spreadsheets\r
-        MIGRATION.SysdynChanges\r
-        MIGRATION.OrderedSetsToLists\r
+        FROM16TO17.Ontologies\r
+        FROM16TO17.Spreadsheets\r
+        FROM16TO17.SysdynChanges\r
+        FROM16TO17.OrderedSetsToLists\r
 \r
-MIGRATION.Ontologies : L0.NamespaceMigrationStep\r
+FROM16TO17.Ontologies : L0.NamespaceMigrationStep\r
   @L0.list\r
     _\r
       @move "http://www.simantics.org/Layer0-" "1.0" "1.1"\r
@@ -60,7 +80,7 @@ MIGRATION.Ontologies : L0.NamespaceMigrationStep
     _\r
       @move"http://www.simantics.org/SelectionView-" "1.1" "1.2"\r
       \r
-MIGRATION.Spreadsheets : L0.NamespaceMigrationStep\r
+FROM16TO17.Spreadsheets : L0.NamespaceMigrationStep\r
   @L0.list\r
     _\r
       @move "http://www.simantics.org/Spreadsheet-1.2/" "HasContent" "Cell/content"\r
@@ -91,7 +111,7 @@ MIGRATION.Spreadsheets : L0.NamespaceMigrationStep
     _\r
       @move "http://www.simantics.org/Spreadsheet-1.2/" "ColumnWidthsOf" "Headers/columnWidths/Inverse"        \r
 \r
-MIGRATION.SysdynChanges : L0.NamespaceMigrationStep\r
+FROM16TO17.SysdynChanges : L0.NamespaceMigrationStep\r
   @L0.list\r
     _\r
       @move "http://www.simantics.org/Sysdyn-1.1/" "HasTail" "Variable/HasTail"\r
@@ -101,7 +121,7 @@ MIGRATION.SysdynChanges : L0.NamespaceMigrationStep
       @move "http://www.simantics.org/Sysdyn-1.1/" "SharedModuleOntolofgy" "SharedModuleOntology"\r
       \r
                   \r
-MIGRATION.OrderedSetsToLists : L0.OrderedSetToListMigrationStep\r
+FROM16TO17.OrderedSetsToLists : L0.OrderedSetToListMigrationStep\r
     @L0.list\r
         _ : L0.OrderedSetToListMigrationStep.Change\r
             L0.OrderedSetToListMigrationStep.entityType "http://www.simantics.org/Sysdyn-1.1/Variable"\r
index d69272b1ffb986373292fcfd9a6461972a15574f..c576dd7c9244baeb843d0d3984594f340d0df096 100644 (file)
@@ -8,6 +8,7 @@
  *\r
  * Contributors:\r
  *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *     Semantum Oy - Bug #4192\r
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.utils.imports;\r
 \r
@@ -40,6 +41,10 @@ import org.simantics.db.common.request.WriteResultRequest;
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.exception.ResourceNotFoundException;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
+import org.simantics.db.layer0.migration.MigrationState;\r
+import org.simantics.db.layer0.migration.MigrationStateKeys;\r
+import org.simantics.db.layer0.migration.MigrationUtils;\r
 import org.simantics.db.layer0.util.RemoverUtil;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.issues.common.AllBatchIssueSources;\r
@@ -138,18 +143,22 @@ public class ImportUtils {
 \r
         Activator.getDefault().getPreferenceStore().setValue(IMPORTMODELTPATH, (new File(path)).getParent());\r
 \r
+        MigrationState state = MigrationUtils.newState();\r
+        state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration);\r
+        state.setProperty(MigrationStateKeys.UPDATE_DEPENDENCIES, Boolean.FALSE);\r
 \r
-\r
-        HashMap<String, FormatHandler<Object>> handlers = new HashMap<String, FormatHandler<Object>>();\r
-        handlers.put("sysdynModel:1", new SysdynImportFormatHandler(project, SysdynResource.URIs.from1$6to1$7, monitor));\r
-\r
-        Object result = ImportUtils.readFile(path, handlers);\r
+        Resource result = null;\r
+        try {\r
+            result = MigrationUtils.importMigrated(monitor, SimanticsUI.getSession(), new File(path), state, new DefaultPasteImportAdvisor(project), project);\r
+        } catch (Exception e1) {\r
+            e1.printStackTrace();\r
+        }\r
 \r
         if(result == null || !(result instanceof Resource)) {\r
             return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: File could not be read.", null);\r
         } else {\r
             try {\r
-                final Resource ModelRoot = (Resource) result;\r
+                final Resource ModelRoot = result;\r
                 IStatus status = SimanticsUI.getSession().syncRequest(new WriteResultRequest<IStatus>()  {\r
 \r
                     @Override\r
@@ -352,18 +361,22 @@ public class ImportUtils {
 \r
         Activator.getDefault().getPreferenceStore().setValue(IMPORTMODULETPATH, (new File(path)).getParent());\r
 \r
-        // Handler for importing modules\r
-        HashMap<String, FormatHandler<Object>> handlers = new HashMap<String, FormatHandler<Object>>();\r
-        handlers.put("sysdynModule:1", new SysdynImportFormatHandler(model, SysdynResource.URIs.from1$6to1$7, monitor));\r
+        MigrationState state = MigrationUtils.newState();\r
+        state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration);\r
+        state.setProperty(MigrationStateKeys.UPDATE_DEPENDENCIES, Boolean.FALSE);\r
 \r
-        // Read module file\r
-        Object result = ImportUtils.readFile(path, handlers);\r
+        Resource result = null;\r
+        try {\r
+            result = MigrationUtils.importMigrated(monitor, SimanticsUI.getSession(), new File(path), state, new DefaultPasteImportAdvisor(model), model);\r
+        } catch (Exception e1) {\r
+            e1.printStackTrace();\r
+        }\r
 \r
 \r
-        if(result == null || !(result instanceof Resource)) {\r
+        if(result == null) {\r
             return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import module failed: Module could not be imported.", null);\r
         } else {\r
-            final Resource ModuleRoot = (Resource) result;\r
+            final Resource ModuleRoot = result;\r
             // Check that the imported file actually was a module. Display error message otherwise.\r
             try {\r
                 subTask(monitor, "Validate model");\r
@@ -415,15 +428,19 @@ public class ImportUtils {
 \r
         // Ensure that shared functions ontology exists\r
         ensureSharedOntologies();\r
+        \r
+        MigrationState state = MigrationUtils.newState();\r
+        state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration);\r
+        state.setProperty(MigrationStateKeys.UPDATE_DEPENDENCIES, Boolean.FALSE);\r
 \r
-        // Handler for importing function libraries\r
-        HashMap<String, FormatHandler<Object>> handlers = new HashMap<String, FormatHandler<Object>>();\r
-        handlers.put("sysdynFunctionLibrary:1", new SysdynImportFormatHandler(functionLibrary, SysdynResource.URIs.from1$6to1$7, monitor, new SysdynFunctionLibraryImportAdvisor(functionLibrary)));\r
-\r
-        // Read function library file\r
-        Object result = ImportUtils.readFile(path, handlers);\r
+        Resource result = null;\r
+        try {\r
+            result = MigrationUtils.importMigrated(monitor, SimanticsUI.getSession(), new File(path), state, new DefaultPasteImportAdvisor(functionLibrary), functionLibrary);\r
+        } catch (Exception e1) {\r
+            e1.printStackTrace();\r
+        }\r
 \r
-        if(result == null || !(result instanceof Resource)) {\r
+        if(result == null) {\r
             return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import Function library failed: Function library not be imported.", null);\r
         } else {\r
             final Resource FunctionLibraryRoot = (Resource) result;\r