Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit 6e5eb68

Browse files
committed
Correcting the AASd-020 Constraint Query and Unit Test.
1 parent 7f26694 commit 6e5eb68

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

validator/src/main/resources/constraint_shapes.ttl

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,33 @@ aas:AASd-020Shape a sh:NodeShape ;
222222
a sh:SPARQLConstraint ;
223223
sh:message "(AASd-020Shape) - The value of Qualifier/value shall be consistent to the data type as defined in Qualifier/valueType." ;
224224
sh:select """
225-
SELECT ?this ?value WHERE {
225+
SELECT ?this ?value ?claimedValueType WHERE {
226226
?this <https://admin-shell.io/aas/3/0/RC01/Qualifier/value> ?value .
227-
?this <https://admin-shell.io/aas/3/0/RC01/Qualifier/valueType> ?valueType .
228-
FILTER (DATATYPE(?value) != URI(?valueType) ) # TODO only works with complete URIs, for instance ?valueType:='http://www.w3.org/2001/XMLSchema#string' works but ?valueType:='string' fails.
229-
}
227+
?this <https://admin-shell.io/aas/3/0/RC01/Qualifier/valueType> ?claimedValueType .
228+
229+
# reference for the constructor functions: https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#FunctionMapping
230+
BIND(IF( <http://www.w3.org/2001/XMLSchema#dateTime>(?value), true, false) AS ?isDateTime)
231+
BIND(IF( <http://www.w3.org/2001/XMLSchema#boolean>(?value), true, false) AS ?isBoolean)
232+
BIND(IF( <http://www.w3.org/2001/XMLSchema#integer>(?value), true, false) AS ?isInteger)
233+
BIND(IF( <http://www.w3.org/2001/XMLSchema#double>(?value), true, false) AS ?isDouble)
234+
BIND(IF( <http://www.w3.org/2001/XMLSchema#long>(?value), true, false) AS ?isLong)
235+
BIND(IF( <http://www.w3.org/2001/XMLSchema#float>(?value), true, false) AS ?isFloat)
236+
BIND( isURI(?value) AS ?isUri)
237+
BIND( isIRI(?value) AS ?isIri)
238+
BIND(IF( <http://www.w3.org/2001/XMLSchema#string>(?value), true, false) AS ?isString)
239+
240+
FILTER( ?claimedValueType = "integer" || ?claimedValueType = "int" || ?claimedValueType = "boolean" || ?claimedValueType = "dateTime" || ?claimedValueType = "double" || ?claimedValueType = "long" || ?claimedValueType = "float" || ?claimedValueType = "uri" || ?claimedValueType = "iri" || ?claimedValueType = "string" )
241+
242+
FILTER( IF( ?claimedValueType = "dateTime", IF(BOUND(?isDateTime), false, true), true ) )
243+
FILTER( IF( ?claimedValueType = "boolean", IF(BOUND(?isBoolean), false, true), true ) )
244+
FILTER( IF( ?claimedValueType = "long", IF(BOUND(?isLong), false, true), true ) )
245+
FILTER( IF( ?claimedValueType = "float", IF(BOUND(?isFloat), false, true), true ) )
246+
FILTER( IF( ?claimedValueType = "integer" || ?claimedValueType = "int", IF(BOUND(?isInteger), false, true), true ) )
247+
FILTER( IF( ?claimedValueType = "double", IF(BOUND(?isDouble), false, true), true ) )
248+
FILTER( IF( ?claimedValueType = "string", IF(BOUND(?isString), false, true), true ) )
249+
FILTER( IF( ?claimedValueType = "uri", IF(?isUri, false, true), true ) )
250+
FILTER( IF( ?claimedValueType = "iri", IF(?isIri, false, true), true ) )
251+
}
230252
"""
231253
]
232254
];

validator/src/test/java/io/adminshell/aas/v3/model/validator/TestAASd_020.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class TestAASd_020 {
4040
public void wrongIntegerValue() throws ValidationException {
4141

4242
Qualifier wrongQualifier = new DefaultQualifier.Builder()
43-
.valueType("http://www.w3.org/2001/XMLSchema#int")
43+
.valueType("int")
4444
.value("test")
4545
.type("integer")
4646
.build();
@@ -54,13 +54,11 @@ public void wrongIntegerValue() throws ValidationException {
5454
}
5555
}
5656

57-
// TODO: non-strings can not be passed as Qualifier.value --> Strings will always pass, others are not recognized.
5857
@Test
59-
@Ignore
60-
public void wrongStringValue() throws ValidationException {
58+
public void wrongUriValue() throws ValidationException {
6159

6260
Qualifier wrongQualifier = new DefaultQualifier.Builder()
63-
.valueType("http://www.w3.org/2001/XMLSchema#string")
61+
.valueType("uri")
6462
.value("1")
6563
.type("integer")
6664
.build();
@@ -79,7 +77,7 @@ public void wrongStringValue() throws ValidationException {
7977
public void correctString() throws ValidationException {
8078

8179
Qualifier qualifier = new DefaultQualifier.Builder()
82-
.valueType("http://www.w3.org/2001/XMLSchema#string")
80+
.valueType("string")
8381
.value("a string")
8482
.type("string")
8583
.build();

0 commit comments

Comments
 (0)