X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Fvalidation%2FL0Validations.java;fp=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Fvalidation%2FL0Validations.java;h=4a8122956d8247dc900d92e0893b031da0881b11;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java new file mode 100644 index 000000000..4a8122956 --- /dev/null +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java @@ -0,0 +1,43 @@ +package org.simantics.db.common.validation; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; + +public class L0Validations { + + public static String checkValueType(ReadGraph graph, Resource subject, Resource predicate) throws DatabaseException { + if (subject == null) + return null; + if (predicate == null) + return null; + + Layer0 L0 = Layer0.getInstance(graph); + if(graph.isSubrelationOf(predicate, L0.HasProperty)) { + Resource object = graph.getPossibleObject(subject, predicate); + if(object == null) return null; + String valueType = graph.getPossibleRelatedValue(predicate, L0.RequiresValueType, Bindings.STRING); + if(valueType != null) { + String valueType2 = graph.getPossibleRelatedValue(object, L0.HasValueType, Bindings.STRING); + if(!valueType.equals(valueType2)) { + StringBuilder sb = new StringBuilder() + .append("The value type ") + .append(valueType) + .append(" of predicate ") + .append(NameUtils.getSafeName(graph, predicate, true)) + .append(" does not match the value type ") + .append(valueType2) + .append(" of object ") + .append(NameUtils.getSafeName(graph, object, true)) + .append("."); + return sb.toString(); + } + } + } + return null; + } + +}