]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Allow changing failOnMissing behaviour for migrated TG import. 17/4617/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 20 Nov 2020 16:05:25 +0000 (18:05 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 20 Nov 2020 16:05:25 +0000 (18:05 +0200)
MigrationStateKeys.FAIL_ON_MISSING parameter now overrides system wide
"failOnMissingEntities" property.

gitlab #643

Change-Id: Ia5977d806ab590e64834b82c128e474e6c7a51a6

bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateImpl.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateKeys.java
bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java
bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java

index fdd6f9132fe4b78d45d6874275778ccdc4481465..fb8f8c9e7aef04f1e93f1f087ed5c297fa9879f7 100644 (file)
@@ -307,7 +307,13 @@ public class MigrationStateImpl implements MigrationState {
 
                String task = "Importing model into database";
                monitor.subTask(task);
-               ImportResult ir = TransferableGraphs.importGraph1(session, tgs, advisor, new TGImportMonitor(monitor, task));
+               ImportResult ir; 
+               if (properties.containsKey(MigrationStateKeys.FAIL_ON_MISSING)) {
+                       ir = TransferableGraphs.importGraph1(session, null, tgs, advisor, new TGImportMonitor(monitor, task),(Boolean)properties.get(MigrationStateKeys.FAIL_ON_MISSING));
+               } else {
+                       ir = TransferableGraphs.importGraph1(session, tgs, advisor, new TGImportMonitor(monitor, task));        
+               }
+               
                monitor.subTask("");
 
                setProperty(MigrationStateKeys.IMPORT_RESULT, ir);
index 9a5ac6fdae23196e666ef9534cd95b7df0732754..261e2123f1a4a620bfe2ab10adb64fda27e1d9f4 100644 (file)
@@ -77,5 +77,12 @@ public interface MigrationStateKeys {
      * is asked for the first time.
      */
     public final static String DATABASE_REVISION_AFTER_TG_IMPORT = "revisionAfterTgImport";
+    
+    /**
+     * Allows setting behaviour for missing entities.
+     * Essentially the same thing as "org.simantics.tg.import.failOnMissingEntities" system property
+     * Note: using this will override system wide property.
+     */
+    public final static String FAIL_ON_MISSING = "failOnMissing";
 
 }
index e61937fc9e90aaf92d2dc57767d35c4545d6b91e..ce3f075109c1124355f47c86945c6304d5e399eb 100644 (file)
@@ -97,17 +97,24 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
        Resource ConsistsOf;
        Resource PartOf;
        Resource HasName;
-       Resource NameOf;        
+       Resource NameOf;
+       
+       boolean failOnMissing;
 
        public StreamingTransferableGraphImportProcess(Session session, VirtualGraph vg, TransferableGraphSource tg, IImportAdvisor2 advisor) {
                this(session, vg, tg, advisor, null);
        }
-
+       
        public StreamingTransferableGraphImportProcess(Session session, VirtualGraph vg, TransferableGraphSource tg, IImportAdvisor2 advisor, TGStatusMonitor monitor) {
+               this(session, vg, tg, advisor, monitor, failOnMissingEntities());
+       }
+
+       public StreamingTransferableGraphImportProcess(Session session, VirtualGraph vg, TransferableGraphSource tg, IImportAdvisor2 advisor, TGStatusMonitor monitor, boolean failOnMissing) {
                this.tg = tg;
                this.vg = vg;
                this.advisor = advisor;
                this.monitor = monitor;
+               this.failOnMissing = failOnMissing;
        }
 
        private int updatePercentage(int percentage, int done, int total) {
@@ -250,11 +257,11 @@ public class StreamingTransferableGraphImportProcess implements TransferableGrap
                        }
                }               
 
-               if (!missingExternals.isEmpty() && failOnMissingEntities())
+               if (!missingExternals.isEmpty() && failOnMissing)
                        throw new MissingDependencyException(this);
        }
 
-       private boolean failOnMissingEntities() {
+       private static boolean failOnMissingEntities() {
                return "true".equalsIgnoreCase(
                                System.getProperty(
                                                "org.simantics.tg.import.failOnMissingEntities",
index 2b93df74dceeb0fed0b3f0c871a62fe043968d8a..7b1a177045a0f4537299282f7a07c7e50fc8c32c 100644 (file)
@@ -182,10 +182,15 @@ public class TransferableGraphs {
     }
 
     public static ImportResult importGraph1(Session session, VirtualGraph vg, final TransferableGraphSource tg, IImportAdvisor advisor_, TGStatusMonitor monitor) throws DatabaseException {
+       return importGraph1(session, vg, tg, advisor_, monitor, null);
+    }
+    
+    public static ImportResult importGraph1(Session session, VirtualGraph vg, final TransferableGraphSource tg, IImportAdvisor advisor_, TGStatusMonitor monitor, Boolean failOnMissing) throws DatabaseException {
         
         final IImportAdvisor2 advisor = (advisor_ instanceof IImportAdvisor2) ? ((IImportAdvisor2)advisor_) : new WrapperAdvisor(advisor_);
 
-               final StreamingTransferableGraphImportProcess process = new StreamingTransferableGraphImportProcess(session, vg, tg, advisor, monitor);
+               final StreamingTransferableGraphImportProcess process = failOnMissing == null ? new StreamingTransferableGraphImportProcess(session, vg, tg, advisor, monitor)
+                                                                                                                                                                         : new StreamingTransferableGraphImportProcess(session, vg, tg, advisor, monitor, failOnMissing);
                session.syncRequest(new ReadRequest() {
                        @Override
                        public void run(ReadGraph graph) throws DatabaseException {