X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvalidation%2FValidationUtils.java;h=47c829cd86443ae0d04bfaf5803da028dabbc5d7;hb=refs%2Fheads%2Fprivate%2Fantin_tyomaa;hp=b5ea24686b4daeb7f2c7111bc14b748d348dfee9;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/validation/ValidationUtils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/validation/ValidationUtils.java
index b5ea24686..47c829cd8 100644
--- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/validation/ValidationUtils.java
+++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/validation/ValidationUtils.java
@@ -1,81 +1,82 @@
-package org.simantics.db.layer0.validation;
-
-import gnu.trove.set.hash.THashSet;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.simantics.db.Issue;
-import org.simantics.db.ReadGraph;
-import org.simantics.db.Resource;
-import org.simantics.db.common.utils.Functions;
-import org.simantics.db.common.utils.Logger;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;
-import org.simantics.db.layer0.util.DomainProcessor3;
-import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;
-import org.simantics.layer0.Layer0;
-
-public class ValidationUtils {
-
- /**
- * Performs L0.Constraint validations for the specified resource and puts
- * the resulting issues in the specified {@link Issue} set. If the specified
- * issue set is null
, a new set will be created and returned.
- * Otherwise the method function will return the same set as its return
- * value.
- *
- * @param graph
- * database read access handle
- * @param r
- * resource to validate against ontology-defined constraints
- * @param result
- * a set for the resulting issues or null
to
- * allocate a new set if necessary
- * @return the discovered set of issues in r
- * @throws DatabaseException
- */
- public static Set validateConstraints(ReadGraph graph, Resource r, Set result) throws DatabaseException {
- Layer0 L0 = Layer0.getInstance(graph);
-
- for (Resource constraint : graph.syncRequest(new GetConstraints(r))) {
- try {
- Resource function = graph.getSingleObject(constraint, L0.Constraint_Validator);
- @SuppressWarnings("unchecked")
- List issues = (List)Functions.exec(graph, function, graph, r);
- if (issues != null && !issues.isEmpty()) {
- if (result == null)
- result = new THashSet();
- result.addAll(issues);
- }
- } catch (Throwable t) {
- Logger.defaultLogError(t);
- }
- }
-
- return result != null ? result : Collections.emptySet();
- }
-
- public static Set validateConstraints(ReadGraph graph, Resource r) throws DatabaseException {
- return validateConstraints(graph, r, null);
- }
-
- public static Set validateConstraintsForDomain(ReadGraph graph, Resource r) throws DatabaseException {
- Set result = null;
-
- DomainProcessor3 dp = ModelTransferableGraphSourceRequest.getDomainOnly(graph, null, r);
- for(Map.Entry status : dp.getStatus().entrySet()) {
- if(ExtentStatus.INTERNAL.equals(status.getValue())) {
- Resource rr = status.getKey();
- Set issues = validateConstraints(graph, rr, result);
- if (!issues.isEmpty())
- result = issues;
- }
- }
-
- return result != null ? result : Collections.emptySet();
- }
-
-}
+package org.simantics.db.layer0.validation;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.simantics.db.Issue;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.utils.Functions;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;
+import org.simantics.db.layer0.util.DomainProcessor3;
+import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;
+import org.simantics.layer0.Layer0;
+
+import gnu.trove.set.hash.THashSet;
+
+public class ValidationUtils {
+
+ /**
+ * Performs L0.Constraint validations for the specified resource and puts
+ * the resulting issues in the specified {@link Issue} set. If the specified
+ * issue set is null
, a new set will be created and returned.
+ * Otherwise the method function will return the same set as its return
+ * value.
+ *
+ * @param graph
+ * database read access handle
+ * @param r
+ * resource to validate against ontology-defined constraints
+ * @param result
+ * a set for the resulting issues or null
to
+ * allocate a new set if necessary
+ * @return the discovered set of issues in r
+ * @throws DatabaseException
+ */
+ public static Set validateConstraints(ReadGraph graph, Resource r, Set result) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+
+ for (Resource constraint : graph.syncRequest(new GetConstraints(r))) {
+ try {
+ Resource function = graph.getSingleObject(constraint, L0.Constraint_Validator);
+ @SuppressWarnings("unchecked")
+ List issues = (List)Functions.exec(graph, function, graph, r);
+ if (issues != null && !issues.isEmpty()) {
+ if (result == null)
+ result = new THashSet();
+ result.addAll(issues);
+ }
+ } catch (Throwable t) {
+ Logger.defaultLogError(t);
+ }
+ }
+
+ return result != null ? result : Collections.emptySet();
+ }
+
+ public static Set validateConstraints(ReadGraph graph, Resource r) throws DatabaseException {
+ return validateConstraints(graph, r, null);
+ }
+
+ public static List validateConstraintsForDomain(ReadGraph graph, Resource r) throws DatabaseException {
+ Set result = null;
+
+ DomainProcessor3 dp = ModelTransferableGraphSourceRequest.getDomainOnly(graph, null, r);
+ for(Map.Entry status : dp.getStatus().entrySet()) {
+ if(ExtentStatus.INTERNAL.equals(status.getValue())) {
+ Resource rr = status.getKey();
+ Set issues = validateConstraints(graph, rr, result);
+ if (!issues.isEmpty())
+ result = issues;
+ }
+ }
+
+ return result != null ? new ArrayList(result) : Collections.emptyList();
+ }
+
+}