- public static MigratedImportResult doImport(IProgressMonitor monitor, File modelFile, Session session, Resource target)
- throws Exception
- {
- SubMonitor mon = SubMonitor.convert(monitor);
- mon.beginTask("Loading model from disk", 1000);
-
- FormatHandler<MigratedImportResult> handler1 = new FormatHandler<MigratedImportResult>() {
- @Override
- public Binding getBinding() {
- return TransferableGraph1.BINDING;
- }
-
- @Override
- public MigratedImportResult process(DataContainer container) throws Exception {
- mon.worked(100);
- mon.setTaskName("Importing model into database");
-
- MigrationState state = MigrationUtils.newState();
- state.setProperty(MigrationStateKeys.UPDATE_DEPENDENCIES, false);
- state.setProperty(MigrationStateKeys.MODEL_FILE, modelFile);
- state.setProperty(MigrationStateKeys.SESSION, session);
- state.setProperty(MigrationStateKeys.PROGRESS_MONITOR, monitor);
-
- MigrationUtils.importMigrated(monitor, session, modelFile, state, new ModelImportAdvisor(Simantics.getProjectResource()), Simantics.getProjectResource());
-
- Collection<Resource> resultRoots = state.getProperty(MigrationStateKeys.CURRENT_ROOT_RESOURCES);
- ImportResult result = state.getProperty(MigrationStateKeys.IMPORT_RESULT);
- return new MigratedImportResult(resultRoots, result);
-
- }
- };
-
- Map<String, FormatHandler<MigratedImportResult>> handlers = new HashMap<>();
- handlers.put(":1", handler1);
- handlers.put(Constants.MODEL_FORMAT_V1, handler1);
-
- MigratedImportResult result = DataContainers.readFile(modelFile, handlers);
-
- mon.setTaskName("Postprocessing");
- mon.subTask("");
- mon.newChild(50).done();
-
- return result;
- }
-