X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Futils%2FBatchValidations.java;h=0ce852403f3b888fa1a94a7fd2aca20f33c7e439;hb=HEAD;hp=91d85aed2593b00097f75f29a5dc0cc6240bf484;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git
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;
+ }
+
}