Skip to content

Commit 00bca90

Browse files
committed
Merge branch 'main' into 2.0.x
2 parents 8c1c008 + deb09f1 commit 00bca90

File tree

43 files changed

+802
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+802
-167
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-java-generator/src/main/resources/java-static-class-body-lib.vm

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,16 @@ static {
7777

7878
@Override
7979
public List<StaticProperty<?>> getAllProperties() {
80-
#if( $element.getExtends().isPresent() )
81-
#set( $extendedElement = $element.getExtends().get() )
82-
$codeGenerationConfig.getImportTracker().importExplicit( "${codeGenerationConfig.getPackageName()}.Meta${extendedElement.getName()}" )
83-
List<StaticProperty<?>> properties = getProperties();
84-
properties.addAll(Meta${extendedElement.getName()}.INSTANCE.getAllProperties());
85-
return properties;
86-
#else
87-
return getProperties();
88-
#end
80+
#if( $element.getExtends().isPresent() )
81+
#set( $extendedElement = $element.getExtends().get() )
82+
$codeGenerationConfig.getImportTracker().importExplicit( "java.util.stream.Stream" )
83+
$codeGenerationConfig.getImportTracker().importExplicit( "java.util.stream.Collectors" )
84+
$codeGenerationConfig.getImportTracker().importExplicit( "java.util.Collection" )
85+
$codeGenerationConfig.getImportTracker().importExplicit( "${codeGenerationConfig.getPackageName()}.Meta${extendedElement.getName()}" )
86+
return Stream.of( getProperties(), Meta${extendedElement.getName()}.INSTANCE.getAllProperties() ).flatMap( Collection::stream ).collect( Collectors.toList() );
87+
#else
88+
return getProperties();
89+
#end
8990
}
9091

9192
#if( !$element.getPreferredNames().isEmpty() )

core/sds-aspect-model-java-generator/src/main/resources/java-static-class-property-lib.vm

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@
6767
#if( $util.hasContainerType( $property ) )
6868
$codeGenerationConfig.getImportTracker().importExplicit( $StaticConstraintContainerProperty )
6969
#set( $containedType = $util.getCharacteristicJavaType( $property, $codeGenerationConfig ) )
70-
#propertyDeclaration() StaticConstraintContainerProperty<$containedType, $propertyType, #getConstraintClassName(), #getCharacteristicClassName()>
70+
#propertyDeclaration() StaticConstraintContainerProperty<$containedType, $propertyType, #getCharacteristicClassName()>
7171
$util.toConstant( $property.getName() ) = #staticProperty( $property $codeGenerationConfig );
7272
#elseif( $util.hasUnit( $property.getCharacteristic().get() ) )
7373
$codeGenerationConfig.getImportTracker().importExplicit( $StaticConstraintUnitProperty )
7474
$codeGenerationConfig.getImportTracker().importExplicit( $Unit )
75-
#propertyDeclaration() StaticConstraintUnitProperty<$propertyType, #getConstraintClassName(), #getCharacteristicClassName()>
75+
#propertyDeclaration() StaticConstraintUnitProperty<$propertyType, #getCharacteristicClassName()>
7676
$util.toConstant( $property.getName() ) = #staticProperty( $property $codeGenerationConfig );
7777
#else
78-
#propertyDeclaration() StaticConstraintProperty<$propertyType, #getConstraintClassName(), #getCharacteristicClassName()>
78+
#propertyDeclaration() StaticConstraintProperty<$propertyType, #getCharacteristicClassName()>
7979
$util.toConstant( $property.getName() ) = #staticProperty( $property $codeGenerationConfig );
8080
#end
8181
#else
@@ -108,14 +108,13 @@
108108
#if( $util.hasContainerType( $property ) )
109109
$codeGenerationConfig.getImportTracker().importExplicit( $StaticConstraintContainerProperty )
110110
#set( $containedType = $util.getCharacteristicJavaType( $property, $codeGenerationConfig ) )
111-
new StaticConstraintContainerProperty<$containedType, $propertyType, #getConstraintClassName(),
112-
#getCharacteristicClassName()>(
111+
new StaticConstraintContainerProperty<$containedType, $propertyType, #getCharacteristicClassName()>(
113112
#elseif( $util.hasUnit( $property.getCharacteristic().get() ) )
114113
$codeGenerationConfig.getImportTracker().importExplicit( $StaticConstraintUnitProperty )
115114
$codeGenerationConfig.getImportTracker().importExplicit( $Unit )
116-
new StaticConstraintUnitProperty<$propertyType, #getConstraintClassName(), #getCharacteristicClassName()>(
115+
new StaticConstraintUnitProperty<$propertyType, #getCharacteristicClassName()>(
117116
#else
118-
new StaticConstraintProperty<$propertyType, #getConstraintClassName(), #getCharacteristicClassName()>(
117+
new StaticConstraintProperty<$propertyType, #getCharacteristicClassName()>(
119118
#end
120119
#else
121120
#if( $util.hasContainerType( $property ) && !$propertyType.startsWith( "Map" ) )
@@ -149,8 +148,8 @@ Optional.of("$property.getPayloadName()"),
149148
## Body
150149
#if( $Trait.isAssignableFrom( $property.getCharacteristic().get().getClass() ) )
151150
@Override
152-
public #getConstraintClassName() getConstraint() {
153-
return (#getConstraintClassName())((Trait)getCharacteristic().get()).getConstraints().iterator().next();
151+
public List<Constraint> getConstraints() {
152+
return ((Trait)getCharacteristic().get()).getConstraints();
154153
}
155154

156155
@Override

core/sds-aspect-model-java-generator/src/test/java/io/openmanufacturing/sds/aspectmodel/java/StaticMetaModelJavaGeneratorTest.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@
4040
import io.openmanufacturing.sds.aspectmetamodel.KnownVersion;
4141
import io.openmanufacturing.sds.metamodel.datatypes.Curie;
4242
import io.openmanufacturing.sds.metamodel.impl.DefaultCharacteristic;
43-
import io.openmanufacturing.sds.metamodel.impl.DefaultFixedPointConstraint;
44-
import io.openmanufacturing.sds.metamodel.impl.DefaultLengthConstraint;
4543
import io.openmanufacturing.sds.metamodel.impl.DefaultList;
4644
import io.openmanufacturing.sds.metamodel.impl.DefaultMeasurement;
47-
import io.openmanufacturing.sds.metamodel.impl.DefaultRangeConstraint;
48-
import io.openmanufacturing.sds.metamodel.impl.DefaultRegularExpressionConstraint;
4945
import io.openmanufacturing.sds.staticmetamodel.StaticContainerProperty;
5046
import io.openmanufacturing.sds.staticmetamodel.StaticProperty;
5147
import io.openmanufacturing.sds.staticmetamodel.StaticUnitProperty;
@@ -244,13 +240,9 @@ public void testGenerateStaticMetaModelWithExtendedEntity( final KnownVersion me
244240
final int expectedNumberOfParameters = 0;
245241
final List<String> getAllPropertiesWithoutExtended = List.of( "returngetProperties();" );
246242
final List<String> getPropertiesMetaTestEntity = List.of(
247-
"List<StaticProperty<?>>properties=getProperties();",
248-
"properties.addAll(MetaParentTestEntity.INSTANCE.getAllProperties());",
249-
"returnproperties;" );
243+
"returnStream.of(getProperties(),MetaParentTestEntity.INSTANCE.getAllProperties()).flatMap(Collection::stream).collect(Collectors.toList());" );
250244
final List<String> getPropertiesMetaParentTestEntity = List.of(
251-
"List<StaticProperty<?>>properties=getProperties();",
252-
"properties.addAll(MetaParentOfParentEntity.INSTANCE.getAllProperties());",
253-
"returnproperties;" );
245+
"returnStream.of(getProperties(),MetaParentOfParentEntity.INSTANCE.getAllProperties()).flatMap(Collection::stream).collect(Collectors.toList());" );
254246
result.assertMethodBody( "MetaAspectWithExtendedEntity", methodName, expectOverride, Optional.empty(), expectedNumberOfParameters,
255247
getAllPropertiesWithoutExtended );
256248
result.assertMethodBody( "MetaParentTestEntity", methodName, expectOverride, Optional.empty(), expectedNumberOfParameters,
@@ -270,25 +262,25 @@ public void testGenerateStaticMetaModelWithConstraints( final KnownVersion metaM
270262
result.assertFields( "MetaAspectWithConstraints",
271263
ImmutableMap.<String, Object> builder().put( "NAMESPACE", String.class ).put( "MODEL_ELEMENT_URN", String.class )
272264
.put( "CHARACTERISTIC_NAMESPACE", String.class ).put( "INSTANCE", "MetaAspectWithConstraints" ).put( "TEST_PROPERTY_WITH_REGULAR_EXPRESSION",
273-
new TypeToken<StaticConstraintProperty<String, DefaultRegularExpressionConstraint, DefaultCharacteristic>>() {
265+
new TypeToken<StaticConstraintProperty<String, DefaultCharacteristic>>() {
274266
} ).put( "TEST_PROPERTY_WITH_DECIMAL_MIN_DECIMAL_MAX_RANGE_CONSTRAINT",
275-
new TypeToken<StaticConstraintProperty<BigDecimal, DefaultRangeConstraint, DefaultMeasurement>>() {
267+
new TypeToken<StaticConstraintProperty<BigDecimal, DefaultMeasurement>>() {
276268
} ).put( "TEST_PROPERTY_WITH_DECIMAL_MAX_RANGE_CONSTRAINT",
277-
new TypeToken<StaticConstraintProperty<BigDecimal, DefaultRangeConstraint, DefaultMeasurement>>() {
269+
new TypeToken<StaticConstraintProperty<BigDecimal, DefaultMeasurement>>() {
278270
} ).put( "TEST_PROPERTY_WITH_MIN_MAX_RANGE_CONSTRAINT",
279-
new TypeToken<StaticConstraintProperty<Integer, DefaultRangeConstraint, DefaultMeasurement>>() {
271+
new TypeToken<StaticConstraintProperty<Integer, DefaultMeasurement>>() {
280272
} ).put( "TEST_PROPERTY_WITH_MIN_RANGE_CONSTRAINT",
281-
new TypeToken<StaticConstraintProperty<Integer, DefaultRangeConstraint, DefaultMeasurement>>() {
273+
new TypeToken<StaticConstraintProperty<Integer, DefaultMeasurement>>() {
282274
} ).put( "TEST_PROPERTY_RANGE_CONSTRAINT_WITH_FLOAT_TYPE",
283-
new TypeToken<StaticConstraintProperty<Float, DefaultRangeConstraint, DefaultMeasurement>>() {
275+
new TypeToken<StaticConstraintProperty<Float, DefaultMeasurement>>() {
284276
} ).put( "TEST_PROPERTY_RANGE_CONSTRAINT_WITH_DOUBLE_TYPE",
285-
new TypeToken<StaticConstraintProperty<Double, DefaultRangeConstraint, DefaultMeasurement>>() {
277+
new TypeToken<StaticConstraintProperty<Double, DefaultMeasurement>>() {
286278
} ).put( "TEST_PROPERTY_WITH_MIN_MAX_LENGTH_CONSTRAINT",
287-
new TypeToken<StaticConstraintProperty<String, DefaultLengthConstraint, DefaultCharacteristic>>() {
279+
new TypeToken<StaticConstraintProperty<String, DefaultCharacteristic>>() {
288280
} ).put( "TEST_PROPERTY_WITH_MIN_LENGTH_CONSTRAINT",
289-
new TypeToken<StaticConstraintProperty<BigInteger, DefaultLengthConstraint, DefaultCharacteristic>>() {
281+
new TypeToken<StaticConstraintProperty<BigInteger, DefaultCharacteristic>>() {
290282
} ).put( "TEST_PROPERTY_COLLECTION_LENGTH_CONSTRAINT",
291-
new TypeToken<StaticConstraintContainerProperty<BigInteger, List<BigInteger>, DefaultLengthConstraint, DefaultList>>() {
283+
new TypeToken<StaticConstraintContainerProperty<BigInteger, List<BigInteger>, DefaultList>>() {
292284
} ).build(), new HashMap<>() );
293285
}
294286

@@ -365,7 +357,7 @@ public void testGenerateStaticMetaModelWithFixedPointConstraints( final KnownVer
365357
result.assertFields( "MetaAspectWithFixedPoint",
366358
ImmutableMap.<String, Object> builder().put( "NAMESPACE", String.class ).put( "MODEL_ELEMENT_URN", String.class )
367359
.put( "CHARACTERISTIC_NAMESPACE", String.class ).put( "INSTANCE", "MetaAspectWithFixedPoint" )
368-
.put( "TEST_PROPERTY", new TypeToken<StaticConstraintProperty<BigDecimal, DefaultFixedPointConstraint, DefaultMeasurement>>() {
360+
.put( "TEST_PROPERTY", new TypeToken<StaticConstraintProperty<BigDecimal, DefaultMeasurement>>() {
369361
} ).build(), new HashMap<>() );
370362
}
371363

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() );

0 commit comments

Comments
 (0)