From: Marko Luukkainen Date: Fri, 20 Nov 2020 16:05:25 +0000 (+0200) Subject: Allow changing failOnMissing behaviour for migrated TG import. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=e969d0489ce09f8e8414cdcf7db5f8f01a5bebcf;p=simantics%2Fplatform.git Allow changing failOnMissing behaviour for migrated TG import. MigrationStateKeys.FAIL_ON_MISSING parameter now overrides system wide "failOnMissingEntities" property. gitlab #643 Change-Id: Ia5977d806ab590e64834b82c128e474e6c7a51a6 --- diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateImpl.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateImpl.java index fdd6f9132..fb8f8c9e7 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateImpl.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateImpl.java @@ -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); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateKeys.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateKeys.java index 9a5ac6fda..261e2123f 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateKeys.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/MigrationStateKeys.java @@ -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"; } diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java index e61937fc9..ce3f07510 100644 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java +++ b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/StreamingTransferableGraphImportProcess.java @@ -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", diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java index 2b93df74d..7b1a17704 100644 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java +++ b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java @@ -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 {