From 81c28428c2dd5da159353f1ccf583413bd973cb2 Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 21 Mar 2013 09:31:40 +0000 Subject: [PATCH] Refactored import code to use MigrationUtils.importMigrated (fixes #4192) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27182 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../graph/Migration.pgraph | 38 ++++++++++--- .../sysdyn/ui/utils/imports/ImportUtils.java | 57 ++++++++++++------- 2 files changed, 66 insertions(+), 29 deletions(-) diff --git a/org.simantics.sysdyn.ontology/graph/Migration.pgraph b/org.simantics.sysdyn.ontology/graph/Migration.pgraph index 42345d31..7d135469 100644 --- a/org.simantics.sysdyn.ontology/graph/Migration.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Migration.pgraph @@ -8,14 +8,34 @@ move : L0.Template L0.NamespaceMigrationStep.Prefix.from %from L0.NamespaceMigrationStep.Prefix.to %to -MIGRATION = SYSDYN."from1.6to1.7" : L0.MigrationSequence +MIGRATION = SYSDYN.Migration : L0.Library + +MIGRATION.fromModel1 : L0.Migration + L0.Migration.format "sysdynModel" + L0.Migration.from 1 + L0.Migration.step FROM16TO17 + L0.Migration.priority 1.0 + +MIGRATION.fromModule1 : L0.Migration + L0.Migration.format "sysdynModule" + L0.Migration.from 1 + L0.Migration.step FROM16TO17 + L0.Migration.priority 1.0 + +MIGRATION.fromFunctionLibrary1 : L0.Migration + L0.Migration.format "sysdynFunctionLibrary" + L0.Migration.from 1 + L0.Migration.step FROM16TO17 + L0.Migration.priority 1.0 + +FROM16TO17 = MIGRATION."from1.6to1.7" : L0.MigrationSequence @L0.list - MIGRATION.Ontologies - MIGRATION.Spreadsheets - MIGRATION.SysdynChanges - MIGRATION.OrderedSetsToLists + FROM16TO17.Ontologies + FROM16TO17.Spreadsheets + FROM16TO17.SysdynChanges + FROM16TO17.OrderedSetsToLists -MIGRATION.Ontologies : L0.NamespaceMigrationStep +FROM16TO17.Ontologies : L0.NamespaceMigrationStep @L0.list _ @move "http://www.simantics.org/Layer0-" "1.0" "1.1" @@ -60,7 +80,7 @@ MIGRATION.Ontologies : L0.NamespaceMigrationStep _ @move"http://www.simantics.org/SelectionView-" "1.1" "1.2" -MIGRATION.Spreadsheets : L0.NamespaceMigrationStep +FROM16TO17.Spreadsheets : L0.NamespaceMigrationStep @L0.list _ @move "http://www.simantics.org/Spreadsheet-1.2/" "HasContent" "Cell/content" @@ -91,7 +111,7 @@ MIGRATION.Spreadsheets : L0.NamespaceMigrationStep _ @move "http://www.simantics.org/Spreadsheet-1.2/" "ColumnWidthsOf" "Headers/columnWidths/Inverse" -MIGRATION.SysdynChanges : L0.NamespaceMigrationStep +FROM16TO17.SysdynChanges : L0.NamespaceMigrationStep @L0.list _ @move "http://www.simantics.org/Sysdyn-1.1/" "HasTail" "Variable/HasTail" @@ -101,7 +121,7 @@ MIGRATION.SysdynChanges : L0.NamespaceMigrationStep @move "http://www.simantics.org/Sysdyn-1.1/" "SharedModuleOntolofgy" "SharedModuleOntology" -MIGRATION.OrderedSetsToLists : L0.OrderedSetToListMigrationStep +FROM16TO17.OrderedSetsToLists : L0.OrderedSetToListMigrationStep @L0.list _ : L0.OrderedSetToListMigrationStep.Change L0.OrderedSetToListMigrationStep.entityType "http://www.simantics.org/Sysdyn-1.1/Variable" diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java index d69272b1..c576dd7c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/imports/ImportUtils.java @@ -8,6 +8,7 @@ * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - Bug #4192 *******************************************************************************/ package org.simantics.sysdyn.ui.utils.imports; @@ -40,6 +41,10 @@ import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ResourceNotFoundException; +import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; +import org.simantics.db.layer0.migration.MigrationState; +import org.simantics.db.layer0.migration.MigrationStateKeys; +import org.simantics.db.layer0.migration.MigrationUtils; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.request.Read; import org.simantics.issues.common.AllBatchIssueSources; @@ -138,18 +143,22 @@ public class ImportUtils { Activator.getDefault().getPreferenceStore().setValue(IMPORTMODELTPATH, (new File(path)).getParent()); + MigrationState state = MigrationUtils.newState(); + state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration); + state.setProperty(MigrationStateKeys.UPDATE_DEPENDENCIES, Boolean.FALSE); - - HashMap> handlers = new HashMap>(); - handlers.put("sysdynModel:1", new SysdynImportFormatHandler(project, SysdynResource.URIs.from1$6to1$7, monitor)); - - Object result = ImportUtils.readFile(path, handlers); + Resource result = null; + try { + result = MigrationUtils.importMigrated(monitor, SimanticsUI.getSession(), new File(path), state, new DefaultPasteImportAdvisor(project), project); + } catch (Exception e1) { + e1.printStackTrace(); + } if(result == null || !(result instanceof Resource)) { return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: File could not be read.", null); } else { try { - final Resource ModelRoot = (Resource) result; + final Resource ModelRoot = result; IStatus status = SimanticsUI.getSession().syncRequest(new WriteResultRequest() { @Override @@ -352,18 +361,22 @@ public class ImportUtils { Activator.getDefault().getPreferenceStore().setValue(IMPORTMODULETPATH, (new File(path)).getParent()); - // Handler for importing modules - HashMap> handlers = new HashMap>(); - handlers.put("sysdynModule:1", new SysdynImportFormatHandler(model, SysdynResource.URIs.from1$6to1$7, monitor)); + MigrationState state = MigrationUtils.newState(); + state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration); + state.setProperty(MigrationStateKeys.UPDATE_DEPENDENCIES, Boolean.FALSE); - // Read module file - Object result = ImportUtils.readFile(path, handlers); + Resource result = null; + try { + result = MigrationUtils.importMigrated(monitor, SimanticsUI.getSession(), new File(path), state, new DefaultPasteImportAdvisor(model), model); + } catch (Exception e1) { + e1.printStackTrace(); + } - if(result == null || !(result instanceof Resource)) { + if(result == null) { return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import module failed: Module could not be imported.", null); } else { - final Resource ModuleRoot = (Resource) result; + final Resource ModuleRoot = result; // Check that the imported file actually was a module. Display error message otherwise. try { subTask(monitor, "Validate model"); @@ -415,15 +428,19 @@ public class ImportUtils { // Ensure that shared functions ontology exists ensureSharedOntologies(); + + MigrationState state = MigrationUtils.newState(); + state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration); + state.setProperty(MigrationStateKeys.UPDATE_DEPENDENCIES, Boolean.FALSE); - // Handler for importing function libraries - HashMap> handlers = new HashMap>(); - handlers.put("sysdynFunctionLibrary:1", new SysdynImportFormatHandler(functionLibrary, SysdynResource.URIs.from1$6to1$7, monitor, new SysdynFunctionLibraryImportAdvisor(functionLibrary))); - - // Read function library file - Object result = ImportUtils.readFile(path, handlers); + Resource result = null; + try { + result = MigrationUtils.importMigrated(monitor, SimanticsUI.getSession(), new File(path), state, new DefaultPasteImportAdvisor(functionLibrary), functionLibrary); + } catch (Exception e1) { + e1.printStackTrace(); + } - if(result == null || !(result instanceof Resource)) { + if(result == null) { return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import Function library failed: Function library not be imported.", null); } else { final Resource FunctionLibraryRoot = (Resource) result; -- 2.47.1