Skip to content

Commit 665ec18

Browse files
authored
Merge pull request #215 from bci-oss/bugfix/OMP-SDK-196-see-rendered-to-not-annotated-elements
Fix bug with rendering of the "bamm:see" attributes
2 parents a27a79f + 8a787d0 commit 665ec18

File tree

9 files changed

+158
-6
lines changed

9 files changed

+158
-6
lines changed

core/sds-aspect-model-document-generators/src/main/resources/diagram/bamm_1_0_0/enumeration2boxmodel.sparql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ construct {
107107

108108
optional {
109109
{
110-
select ( group_concat( ?seeValue; separator=", " ) as ?seeValues )
110+
select ?characteristic ( group_concat( ?seeValue; separator=", " ) as ?seeValues )
111111
where {
112112
?characteristic rdf:type/rdfs:subClassOf* bamm:Characteristic .
113113
filter( exists {

core/sds-aspect-model-document-generators/src/main/resources/diagram/bamm_1_0_0/property-characteristic-edges2boxmodel.sparql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ construct {
2424
#process Properties defined in the Aspect Model being processed
2525
{
2626
?property bamm:refines?/rdf:type bamm:Property .
27+
#exclude properties from our shared name-space
28+
filter ( ! strstarts( str( ?property ), str ( bamm-e: ) ) )
2729

2830
?property bamm:name ?propertyName .
2931
?property bamm:characteristic ?characteristic .

core/sds-aspect-model-document-generators/src/main/resources/diagram/bamm_2_0_0/enumeration2boxmodel.sparql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ construct {
109109

110110
optional {
111111
{
112-
select ( group_concat( ?seeValue; separator=", " ) as ?seeValues )
112+
select ?characteristic ( group_concat( ?seeValue; separator=", " ) as ?seeValues )
113113
where {
114114
?characteristic rdf:type/rdfs:subClassOf* bamm:Characteristic .
115115
filter( exists {

core/sds-aspect-model-document-generators/src/test/java/io/openmanufacturing/sds/aspectmodel/generator/diagram/Enumeration2BoxModelTest.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
import org.junit.jupiter.params.ParameterizedTest;
2525
import org.junit.jupiter.params.provider.MethodSource;
2626

27+
import io.openmanufacturing.sds.aspectmetamodel.KnownVersion;
2728
import io.openmanufacturing.sds.test.MetaModelVersions;
2829
import io.openmanufacturing.sds.test.TestAspect;
2930

30-
import io.openmanufacturing.sds.aspectmetamodel.KnownVersion;
31-
3231
public class Enumeration2BoxModelTest extends MetaModelVersions {
3332
private final String sparqlQueryFileName = "enumeration2boxmodel.sparql";
3433
private final int totalNumberOfExpectedEntries = 6;
@@ -52,7 +51,7 @@ public void testOnlyUsedEnumerationsAreProcessedExpectSuccess( final KnownVersio
5251
queryResult.listStatements( context.selector( ":UsedTestEnumerationCharacteristic a :Box" ) ).toList() )
5352
.hasSize( 1 );
5453
assertThat( queryResult.listStatements( context.selector( ":UnusedTestEnumerationCharacteristic a :Box" ) )
55-
.toList() )
54+
.toList() )
5655
.hasSize( 0 );
5756
assertThat( queryResult.listStatements( context.selector( "* :text *" ) ).toList() ).hasSize( 5 );
5857
}
@@ -94,11 +93,31 @@ public void testSeeAttributeIsNotPresentExpectSuccess( final KnownVersion metaMo
9493
totalNumberOfExpectedEntries, indexOfSeeValueEntry );
9594
}
9695

96+
@ParameterizedTest
97+
@MethodSource( value = "allVersions" )
98+
void testOnlyRightSeeAttributeIsSelected( final KnownVersion metaModelVersion ) {
99+
// See attribute was rendered also on elements on which it was not declared:
100+
// https://github.com/OpenManufacturingPlatform/sds-sdk/issues/196
101+
String characteristicIdentifier = "Enum1";
102+
String boxSelectorStatement = getBoxSelectorStatement( characteristicIdentifier );
103+
String entriesSelectorStatement = getEntriesSelectorStatement( characteristicIdentifier );
104+
final TestContext context = new TestContext( TestAspect.ASPECT_WITH_ENUM_ONLY_ONE_SEE, metaModelVersion );
105+
context.executeAttributeIsNotPresentTest( sparqlQueryFileName, boxSelectorStatement, entriesSelectorStatement,
106+
totalNumberOfExpectedEntries, indexOfSeeValueEntry );
107+
108+
characteristicIdentifier = "Enum2";
109+
boxSelectorStatement = getBoxSelectorStatement( characteristicIdentifier );
110+
entriesSelectorStatement = getEntriesSelectorStatement( characteristicIdentifier );
111+
context.executeAttributeIsPresentTest( sparqlQueryFileName, boxSelectorStatement, entriesSelectorStatement,
112+
totalNumberOfExpectedEntries, indexOfSeeValueEntry, expectedSeeEntryTitle, "https://test.com" );
113+
}
114+
97115
private String getBoxSelectorStatement( final String characteristicIdentifier ) {
98116
return String.format( ":%sCharacteristic a :Box", characteristicIdentifier );
99117
}
100118

101119
private String getEntriesSelectorStatement( final String characteristicIdentifier ) {
102120
return String.format( ":%sCharacteristic :entries *", characteristicIdentifier );
103121
}
122+
104123
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2022 Robert Bosch Manufacturing Solutions GmbH
3+
*
4+
* See the AUTHORS file(s) distributed with this work for additional
5+
* information regarding authorship.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
10+
*
11+
* SPDX-License-Identifier: MPL-2.0
12+
*/
13+
14+
package io.openmanufacturing.sds.aspectmodel.generator.diagram;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
18+
import org.apache.jena.query.Query;
19+
import org.apache.jena.query.QueryExecution;
20+
import org.apache.jena.query.QueryExecutionFactory;
21+
import org.apache.jena.query.QueryFactory;
22+
import org.apache.jena.rdf.model.Model;
23+
import org.apache.jena.rdf.model.ModelFactory;
24+
import org.junit.jupiter.params.ParameterizedTest;
25+
import org.junit.jupiter.params.provider.MethodSource;
26+
27+
import io.openmanufacturing.sds.aspectmetamodel.KnownVersion;
28+
import io.openmanufacturing.sds.test.MetaModelVersions;
29+
import io.openmanufacturing.sds.test.TestAspect;
30+
31+
public class PropertyCharacteristicEdges2BoxModelTest extends MetaModelVersions {
32+
33+
private final String sparqlQueryFileName = "property-characteristic-edges2boxmodel.sparql";
34+
35+
@ParameterizedTest
36+
@MethodSource( value = "versionsUpToIncluding1_0_0" )
37+
void testPropertyToCharacteristicEdgeFromSharedNamespaceNotPresent( final KnownVersion metaModelVersion ) {
38+
// v1.0 sparql queries were not properly filtering out some properties from shared bamm-e namespace
39+
// https://github.com/OpenManufacturingPlatform/sds-sdk/issues/196
40+
final TestContext context = new TestContext( TestAspect.ASPECT_WITH_ENUM_ONLY_ONE_SEE, metaModelVersion );
41+
final Query query = QueryFactory.create( context.getInputStreamAsString( sparqlQueryFileName ) );
42+
43+
final Model queryResult = ModelFactory.createDefaultModel();
44+
try ( final QueryExecution qexec = QueryExecutionFactory.create( query, context.model() ) ) {
45+
qexec.execConstruct( queryResult );
46+
}
47+
48+
assertThat( queryResult.listStatements( context.selector( ":timestampProperty_To_TimestampCharacteristic a :Edge" ) ).toList() ).isEmpty();
49+
}
50+
}

core/sds-aspect-model-serializer/src/test/java/io/openmanufacturing/sds/aspectmodel/serializer/RdfModelCreatorVisitorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public class RdfModelCreatorVisitorTest extends MetaModelVersions {
5353
"ASPECT_WITH_USED_AND_UNUSED_CONSTRAINT",
5454
"ASPECT_WITH_USED_AND_UNUSED_EITHER",
5555
"ASPECT_WITH_USED_AND_UNUSED_ENUMERATION",
56-
"ASPECT_WITHOUT_PROPERTIES_AND_OPERATIONS"
56+
"ASPECT_WITHOUT_PROPERTIES_AND_OPERATIONS",
57+
"ASPECT_WITH_ENUM_ONLY_ONE_SEE"
5758
} )
5859
public void testRdfModelCreatorVisitor( final TestAspect aspect ) {
5960
testRdfCreation( aspect, KnownVersion.getLatest() );

core/sds-test-aspect-models/src/main/java/io/openmanufacturing/sds/test/TestAspect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public enum TestAspect implements TestModel {
181181
ENTITY_INSTANCE_TEST2,
182182
ENTITY_INSTANCE_TEST3,
183183
ENTITY_INSTANCE_TEST4,
184+
ASPECT_WITH_ENUM_ONLY_ONE_SEE,
184185
MOVEMENT;
185186

186187
@Override
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2022 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
11+
12+
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:1.0.0#>.
13+
@prefix bamm-c: <urn:bamm:io.openmanufacturing:characteristic:1.0.0#>.
14+
@prefix bamm-e: <urn:bamm:io.openmanufacturing:entity:1.0.0#>.
15+
@prefix unit: <urn:bamm:io.openmanufacturing:unit:1.0.0#>.
16+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
17+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
18+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
19+
@prefix : <urn:bamm:io.openmanufacturing.test:1.0.0#>.
20+
21+
:AspectWithEnumOnlyOneSee a bamm:Aspect;
22+
bamm:name "Test";
23+
bamm:properties (:prop1 :prop2);
24+
bamm:operations ().
25+
26+
:prop1 a bamm:Property;
27+
bamm:name "prop1";
28+
bamm:characteristic :Enum1.
29+
:prop2 a bamm:Property;
30+
bamm:name "prop2";
31+
bamm:characteristic :Enum2.
32+
33+
:Enum1 a bamm-c:Enumeration;
34+
bamm:name "Enum1";
35+
bamm:dataType xsd:string;
36+
bamm-c:values ("a" "b").
37+
:Enum2 a bamm-c:Enumeration;
38+
bamm:name "Enum2";
39+
bamm:dataType xsd:string;
40+
bamm-c:values ("1" "2");
41+
bamm:see <https://test.com>.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) 2022 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
11+
12+
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:2.0.0#>.
13+
@prefix bamm-c: <urn:bamm:io.openmanufacturing:characteristic:2.0.0#>.
14+
@prefix bamm-e: <urn:bamm:io.openmanufacturing:entity:2.0.0#>.
15+
@prefix unit: <urn:bamm:io.openmanufacturing:unit:2.0.0#>.
16+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
17+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
18+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
19+
@prefix : <urn:bamm:io.openmanufacturing.test:1.0.0#>.
20+
21+
:AspectWithEnumOnlyOneSee a bamm:Aspect;
22+
bamm:properties (:prop1 :prop2);
23+
bamm:operations ().
24+
25+
:prop1 a bamm:Property;
26+
bamm:characteristic :Enum1.
27+
28+
:prop2 a bamm:Property;
29+
bamm:characteristic :Enum2.
30+
31+
:Enum1 a bamm-c:Enumeration;
32+
bamm:dataType xsd:string;
33+
bamm-c:values ("a" "b").
34+
35+
:Enum2 a bamm-c:Enumeration;
36+
bamm:dataType xsd:string;
37+
bamm-c:values ("1" "2");
38+
bamm:see <https://test.com>.

0 commit comments

Comments
 (0)