From: Tuukka Lehtonen Date: Thu, 16 May 2019 12:30:48 +0000 (+0300) Subject: Allow batch issue validation to remove issues with disconnected context X-Git-Tag: v1.43.0~136^2~154 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F99%2F2899%2F1;p=simantics%2Fplatform.git Allow batch issue validation to remove issues with disconnected context gitlab #295 Change-Id: I0ebfc37013c9c3e9636efab3ddbd68692b2a7056 --- diff --git a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/RunActiveValidations.java b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/RunActiveValidations.java index e46be60d4..0ab0ef98c 100644 --- a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/RunActiveValidations.java +++ b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/RunActiveValidations.java @@ -152,7 +152,7 @@ public class RunActiveValidations extends AbstractHandler { List l = ListUtils.toList(graph, list); if (l.size() > 0) { Resource mainContext = l.get(0); - if (!graph.hasStatement(mainContext)) + if (!BatchValidations.isLinkedToOtherThan(graph, mainContext, issue)) result.add(mainContext); } } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/BatchValidations.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/BatchValidations.java index 91d85aed2..0ce852403 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/BatchValidations.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/BatchValidations.java @@ -14,8 +14,10 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.simantics.Simantics; import org.simantics.db.Issue; +import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; +import org.simantics.db.Statement; import org.simantics.db.VirtualGraph; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; @@ -213,4 +215,39 @@ public class BatchValidations { return result; } + /** + * Checks if the specified resourceToCheckForLinks is linked to + * anything else besides itself and excludeLinksTo. + * + *

+ * This is used to if an issue context is still valid. We consider any issue + * context that is not attached to something else besides its issue context to + * be an invalid issue. Assertions and L0.InstanceOf do not count as external + * links. + * + * @param graph database access handle + * @param resourceToCheckForLinks the resource to check for "external" links + * @param excludeLinksTo exclude links to this resource from evaluation + * @return true if there are links, false otherwise + * @throws DatabaseException + */ + public static boolean isLinkedToOtherThan(ReadGraph graph, Resource resourceToCheckForLinks, + Resource excludeLinksTo) + throws DatabaseException + { + Layer0 L0 = Layer0.getInstance(graph); + for (Statement stm : graph.getStatements(resourceToCheckForLinks, L0.IsWeaklyRelatedTo)) { + if (stm.isAsserted(resourceToCheckForLinks)) + continue; + if (stm.getPredicate().equals(L0.InstanceOf)) + continue; + Resource o = stm.getObject(); + if (o.equals(excludeLinksTo) || o.equals(resourceToCheckForLinks)) + continue; + + return true; + } + return false; + } + }