]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Allow batch issue validation to remove issues with disconnected context 99/2899/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 16 May 2019 12:30:48 +0000 (15:30 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 16 May 2019 12:43:38 +0000 (15:43 +0300)
gitlab #295

Change-Id: I0ebfc37013c9c3e9636efab3ddbd68692b2a7056

bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/RunActiveValidations.java
bundles/org.simantics.modeling/src/org/simantics/modeling/utils/BatchValidations.java

index e46be60d4805e47c5b7c240fc1aa46f5a8e16a08..0ab0ef98cb75b824978d0ca3743ecd2cad225f7e 100644 (file)
@@ -152,7 +152,7 @@ public class RunActiveValidations extends AbstractHandler {
                                             List<Resource> 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);
                                             }
                                         }
index 91d85aed2593b00097f75f29a5dc0cc6240bf484..0ce852403f3b888fa1a94a7fd2aca20f33c7e439 100644 (file)
@@ -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 <code>resourceToCheckForLinks</code> is linked to
+        * anything else besides itself and <code>excludeLinksTo</code>.
+        * 
+        * <p>
+        * 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 <code>true</code> if there are links, <code>false</code> 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;
+       }
+
 }