From: lempinen Date: Tue, 16 Oct 2012 11:48:51 +0000 (+0000) Subject: Added batch validation to import process. The imported model is validated after impor... X-Git-Tag: simantics-1.10.1~122 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=f96698ccc1c7eceed58d8a78d06243da0ad41713;p=simantics%2Fsysdyn.git Added batch validation to import process. The imported model is validated after import. Other issue-issues were fixed when import was not allowed to write to immutable resources #3785 (fixes #3017) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26025 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java index 82770549..9057470f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportModelHandler.java @@ -15,24 +15,31 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; +import java.util.Map; +import java.util.Set; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.SubMonitor; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.Simantics; import org.simantics.databoard.binding.Binding; import org.simantics.databoard.container.DataContainer; import org.simantics.databoard.container.DataContainers; import org.simantics.databoard.container.DataFormatException; import org.simantics.databoard.container.FormatHandler; +import org.simantics.db.Issue; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.Session; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.request.WriteRequest; @@ -41,7 +48,10 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; import org.simantics.db.layer0.util.RemoverUtil; +import org.simantics.db.request.Read; import org.simantics.graph.representation.TransferableGraph1; +import org.simantics.issues.common.AllBatchIssueSources; +import org.simantics.issues.common.BatchIssueSource; import org.simantics.issues.ontology.IssueResource; import org.simantics.layer0.Layer0; import org.simantics.layer0.utils.direct.GraphUtils; @@ -171,9 +181,35 @@ public class ImportModelHandler extends AbstractHandler { }); + + Collection confs = SimanticsUI.getSession().syncRequest(new Read>() { + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + return findAllConfigurations(graph, ModelRoot); + } + + }); + + // Batch validate all issue sources after import try { - BatchValidations.runAll(null, ModelRoot); + for(Resource conf : confs) { + /* + * This section is copied from BatchValidations.runAll. runAll did + * not find module types to validate. + */ +// BatchValidations.runAll(null, mod); + + final Session session = Simantics.getSession(); + final Collection validations = session.sync( new AllBatchIssueSources(ModelRoot) ); + SubMonitor progress = SubMonitor.convert(null, "Validate Model", 100); + Collection contexts = Collections.singletonList(conf); + for(BatchIssueSource bis : validations) { + Map> is = BatchValidations.validate(progress.newChild(90, SubMonitor.SUPPRESS_NONE), bis, contexts); + BatchValidations.store(progress.newChild(10, SubMonitor.SUPPRESS_NONE), bis.getResource(), is); + } + } } catch(Throwable t) { t.printStackTrace(); }