]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed MigrationUtils.importTo root activation to use virtual graph 59/1359/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 8 Jan 2018 09:06:28 +0000 (11:06 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 8 Jan 2018 09:07:48 +0000 (11:07 +0200)
Also made the activation optional based on the new migration state key
MigrationKeys.ACTIVATE_ROOT_IF_NONE_ACTIVE.

refs #7686

Change-Id: I8b7c5868231c3b258bb1ad7f63fa96ba42390f24

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationKeys.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationUtils.java

index 2ac95e7f43e6f6c4f73a0576af77f9dc79ea138f..79f91dff9ee480828ab03e317c7ecd706c76873b 100644 (file)
 package org.simantics.db.layer0.migration;
 
 public class MigrationKeys {
-    
-    final public static String TG = "TransferableGraph";
-    final public static String STEP_RESOURCE = "StepResource";
-    final public static String IMPORTED_RESOURCE = "ImportedResource";
+
+    public static final String TG = "TransferableGraph";
+    public static final String STEP_RESOURCE = "StepResource";
+    public static final String IMPORTED_RESOURCE = "ImportedResource";
+    public static final String ACTIVATE_ROOT_IF_NONE_ACTIVE = "ActivateRootIfNoneActive";
 
 }
index 58197619a7a25f8c002ac6460e166ff299b1919d..e1421df90a89054f23d0a4625665f90ccf8be527 100644 (file)
@@ -50,9 +50,11 @@ import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;
 import org.simantics.db.layer0.adapter.impl.SharedOntologyImportAdvisor;
 import org.simantics.db.layer0.adapter.impl.TrashBinRemover;
 import org.simantics.db.layer0.internal.SimanticsInternal;
+import org.simantics.db.layer0.request.ActivateModel;
 import org.simantics.db.layer0.util.ExternalDownloadBean;
 import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.db.layer0.util.TGTransferableGraphSource;
+import org.simantics.db.request.Write;
 import org.simantics.db.service.XSupport;
 import org.simantics.graph.db.IImportAdvisor;
 import org.simantics.graph.db.ImportResult;
@@ -92,13 +94,9 @@ public class MigrationUtils {
 //        return getTG(session, state, true, false);
 //    }
     
-    public static void clearTempResource(Session session, final Resource resource) {
-        session.asyncRequest(new WriteRequest() {
-
-            @Override
-            public void perform(WriteGraph graph) throws DatabaseException {
-                graph.deny(resource, Layer0.getInstance(graph).PartOf);
-            }
+    public static void clearTempResource(Session session, Resource resource) {
+        session.asyncRequest((Write) graph -> {
+            graph.deny(resource, Layer0.getInstance(graph).PartOf);
         });
     }
 
@@ -108,13 +106,14 @@ public class MigrationUtils {
     private static void activateIfNoActiveModel(WriteGraph graph, Resource root, Resource parent) throws DatabaseException {
         Layer0X L0X = Layer0X.getInstance(graph);
         SimulationResource SIMU = SimulationResource.getInstance(graph);
-        if(!graph.hasStatement(parent, L0X.Activates) && graph.isInstanceOf(root, SIMU.Model))
-            graph.claim(parent, L0X.Activates, root);
+        if (!graph.hasStatement(parent, L0X.Activates) && graph.isInstanceOf(root, SIMU.Model)) {
+            new ActivateModel(parent, root).perform(graph);
+        }
     }
 
     public static Collection<Resource> importTo(IProgressMonitor monitor, Session session, MigrationState state, final Resource parent, final IImportAdvisor advisor) throws DatabaseException, TransferableGraphException {
         final Resource resource = getResource(monitor, session, state);
-        final ArrayList<Resource> result = new ArrayList<Resource>();
+        final ArrayList<Resource> result = new ArrayList<>();
         if(resource != null) {
             session.syncRequest(new WriteRequest() {
                 
@@ -130,11 +129,11 @@ public class MigrationUtils {
                            if(version != null) {
                                        VersionMap map = graph.syncRequest(new VersionMapRequest(parent));
                                        if(map.contains(baseName, version)) {
-                                   String newName = graph.syncRequest(new FreshEscapedName(parent, Layer0.getInstance(graph).ConsistsOf, baseName));
+                                   String newName = graph.syncRequest(new FreshEscapedName(parent, L0.ConsistsOf, baseName));
                                        graph.claimLiteral(root, L0.HasName, newName + "@1", Bindings.STRING);
                                        }
                            } else {
-                           String newName = graph.syncRequest(new FreshEscapedName(parent, Layer0.getInstance(graph).ConsistsOf, baseName));
+                           String newName = graph.syncRequest(new FreshEscapedName(parent, L0.ConsistsOf, baseName));
                            if(!newName.equals(baseName)) {
                                graph.claimLiteral(root, L0.HasName, newName, Bindings.STRING);
                            }
@@ -142,10 +141,10 @@ public class MigrationUtils {
 
                            graph.deny(root, L0.PartOf);
                            graph.claim(root, L0.PartOf, parent);
-                           
-                           // FIXME : Model activation must be done in "activations" virtual graph.
-                           // FIXME : This step should be optional, not all the products use active models.
-                           //activateIfNoActiveModel(graph, root, parent);
+
+                           if (Boolean.TRUE.equals( state.getProperty(MigrationKeys.ACTIVATE_ROOT_IF_NONE_ACTIVE) )) {
+                               activateIfNoActiveModel(graph, root, parent);
+                           }
 
                            CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
                            graph.addMetadata(cm.add("Imported " + graph.getURI(root) + ", resource " + root));
@@ -189,9 +188,9 @@ public class MigrationUtils {
                        public Collection<MigrationStep> perform(ReadGraph graph) throws DatabaseException {
                                
                                Layer0 L0 = Layer0.getInstance(graph);
-                               ArrayList<Pair<Double,MigrationStep>> steps = new ArrayList<Pair<Double,MigrationStep>>();
+                               ArrayList<Pair<Double,MigrationStep>> steps = new ArrayList<>();
                        Instances query = graph.adapt(L0.Migration, Instances.class);
-                       Set<Resource> migrations = new HashSet<Resource>();
+                       Set<Resource> migrations = new HashSet<>();
                                for(Resource ontology : Layer0Utils.listOntologies(graph)) {
                                        migrations.addAll(Layer0Utils.sortByCluster(graph, query.find(graph, ontology)));
                                }