From: Antti Villberg Date: Mon, 20 Mar 2017 05:46:49 +0000 (+0200) Subject: Predicate by label request into Layer0Utils X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=cff26560449d62073ae14a9c1bb5442532f34de2;p=simantics%2Fplatform.git Predicate by label request into Layer0Utils refs #7035 Change-Id: I322dbcb8f51fd16e39d4408a6a5043713ddd8530 --- diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java index 538f22478..adc51c16d 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java @@ -1349,6 +1349,18 @@ public class Layer0Utils { return null; } + public static Resource getPossiblePredicateByLabel(ReadGraph graph, Resource instance, String predicateName) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + for(Resource type : graph.getPrincipalTypes(instance)) { + Map domainOf = getDomainOf(graph, type); + for(Resource r : domainOf.values()) { + String label = graph.getPossibleRelatedValue(r, L0.HasLabel, Bindings.STRING); + if(predicateName.equals(label)) + return r; + } + } + return null; + } public static void claimLiteralDataboard(WriteGraph graph, Resource container, Resource property, String valueText) throws DatabaseException {