]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/validation/L0Validations.java
Fixed invalid comparisons which were identified by Eclipse IDE 2018-09
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / validation / L0Validations.java
1 package org.simantics.db.common.validation;
2
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.NameUtils;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.layer0.Layer0;
9
10 public class L0Validations {
11
12         public static String checkValueType(ReadGraph graph, Resource subject, Resource predicate) throws DatabaseException {
13                 if (subject == null)
14                         return null;
15                 if (predicate == null)
16                         return null;
17
18                 Layer0 L0 = Layer0.getInstance(graph);
19             if(graph.isSubrelationOf(predicate, L0.HasProperty)) {
20                         Resource object = graph.getPossibleObject(subject, predicate);
21                         if(object == null) return null;
22                 String valueType = graph.getPossibleRelatedValue(predicate, L0.RequiresValueType, Bindings.STRING);
23                 if(valueType != null) {
24                         String valueType2 = graph.getPossibleRelatedValue(object, L0.HasValueType, Bindings.STRING);
25                         if(!valueType.equals(valueType2)) {
26                                         StringBuilder sb = new StringBuilder()
27                                         .append("The value type ")
28                                         .append(valueType)
29                                         .append(" of predicate ")
30                                         .append(NameUtils.getSafeName(graph, predicate, true))
31                                         .append(" does not match the value type ")
32                                         .append(valueType2)
33                                         .append(" of object ")
34                                         .append(NameUtils.getSafeName(graph, object, true))
35                                         .append(".");
36                                         return sb.toString();
37                         }
38                 }
39             }
40             return null;
41         }
42         
43 }