1 package org.simantics.db.common.validation;
3 import org.simantics.databoard.Bindings;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.common.utils.CommonDBUtils;
7 import org.simantics.db.common.utils.NameUtils;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.layer0.Layer0;
10 import org.simantics.scl.compiler.types.Type;
12 public class L0Validations {
14 public static String checkValueType(ReadGraph graph, Resource subject, Resource predicate) throws DatabaseException {
18 if (predicate == null)
21 Layer0 L0 = Layer0.getInstance(graph);
22 if(graph.isSubrelationOf(predicate, L0.HasProperty)) {
23 Resource object = graph.getPossibleObject(subject, predicate);
24 if(object == null) return null;
25 String valueTypeText = graph.getPossibleRelatedValue(predicate, L0.RequiresValueType, Bindings.STRING);
26 if(valueTypeText != null) {
27 Type valueType = CommonDBUtils.getSCLType(graph, subject, valueTypeText);
28 if(valueType == null) {
29 Resource range = graph.getPossibleObject(predicate, L0.HasRange);
33 StringBuilder sb = new StringBuilder()
34 .append("The value type ")
36 .append(" of predicate ")
37 .append(NameUtils.getSafeName(graph, predicate, true))
38 .append(" cannot be resolved.")
39 .append(NameUtils.getSafeName(graph, object, true))
44 String valueTypeText2 = graph.getPossibleRelatedValue(object, L0.HasValueType, Bindings.STRING);
45 if(valueTypeText2 != null) {
46 Type valueType2 = CommonDBUtils.getSCLType(graph, subject, valueTypeText2);
47 if(valueType2 == null) {
48 StringBuilder sb = new StringBuilder()
49 .append("The value type ")
51 .append(" of object ")
52 .append(NameUtils.getSafeName(graph, object, true))
53 .append(" cannot be resolved.");
56 if(!valueType.equals(valueType2)) {
57 StringBuilder sb = new StringBuilder()
58 .append("The value type ")
60 .append(" of predicate ")
61 .append(NameUtils.getSafeName(graph, predicate, true))
62 .append(" does not match the value type ")
64 .append(" of object ")
65 .append(NameUtils.getSafeName(graph, object, true))