Skip to content

Commit 233c103

Browse files
authored
Merge pull request #259 from bci-oss/bugfix/OMP-SDK-236-fix-cycle-detection-in-models
Fix cycle detection in models
2 parents 6c8e9ee + d774c95 commit 233c103

File tree

17 files changed

+1143
-219
lines changed

17 files changed

+1143
-219
lines changed

core/sds-aspect-meta-model-java/src/main/java/io/openmanufacturing/sds/metamodel/loader/instantiator/PropertyInstantiator.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,16 @@ public Property apply( final Resource property ) {
6060
final boolean isAbstract = property.getModel().contains( property, RDF.type, bamm.AbstractProperty() );
6161

6262
final MetaModelBaseAttributes metaModelBaseAttributes = buildBaseAttributes( property );
63-
final DefaultPropertyWrapper defaultPropertyWrapper = new DefaultPropertyWrapper( metaModelBaseAttributes);
63+
final DefaultPropertyWrapper defaultPropertyWrapper = new DefaultPropertyWrapper( metaModelBaseAttributes );
6464

6565
if ( resourcePropertyMap.containsKey( property ) ) {
6666
final Property propertyInstance = resourcePropertyMap.get( property );
67-
resourcePropertyMap.remove( property );
6867
return propertyInstance;
6968
}
7069
resourcePropertyMap.put( property, defaultPropertyWrapper );
71-
DefaultProperty defProperty;
70+
final DefaultProperty defProperty;
7271
if ( isAbstract ) {
73-
defProperty = new DefaultProperty( metaModelBaseAttributes, Optional.of( fallbackCharacteristic), Optional.empty(), isOptional,
72+
defProperty = new DefaultProperty( metaModelBaseAttributes, Optional.of( fallbackCharacteristic ), Optional.empty(), isOptional,
7473
isNotInPayload, payloadName, isAbstract, extends_ );
7574
} else {
7675
final Resource characteristicResource = attributeValue( property, bamm.characteristic() ).getResource();
@@ -91,7 +90,7 @@ public Property apply( final Resource property ) {
9190
return new DefaultScalarValue( value, type );
9291
} ) );
9392

94-
defProperty = new DefaultProperty( metaModelBaseAttributes, Optional.of( characteristic), exampleValue, isOptional,
93+
defProperty = new DefaultProperty( metaModelBaseAttributes, Optional.of( characteristic ), exampleValue, isOptional,
9594
isNotInPayload, payloadName, isAbstract, extends_ );
9695
}
9796
defaultPropertyWrapper.setProperty( defProperty );

core/sds-aspect-meta-model-resolver/pom.xml

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<name>SDS Aspect Meta Model Resolver</name>
2929
<packaging>jar</packaging>
3030

31+
<properties>
32+
<bamm-revision>https://raw.githubusercontent.com/OpenManufacturingPlatform/sds-bamm-aspect-meta-model/5c097dd7357b129ba1771985a9ab1d29fcc32bcd</bamm-revision>
33+
</properties>
34+
3135
<dependencies>
3236
<dependency>
3337
<groupId>io.openmanufacturing</groupId>
@@ -126,10 +130,10 @@
126130
<artifactId>sds-aspect-meta-model</artifactId>
127131
<version>${aspect-meta-model-version}</version>
128132
<type>jar</type>
129-
<overWrite>true</overWrite>
133+
<overWrite>false</overWrite>
130134
<outputDirectory>${project.build.directory}/classes</outputDirectory>
131135
<excludes>
132-
bamm/meta-model/2.0.0/aspect-meta-model-shapes.ttl,bamm/characteristic/2.0.0/characteristic-shapes.ttl
136+
bamm/meta-model/1.0.0/aspect-meta-model-shapes.ttl,bamm/characteristic/1.0.0/characteristic-shapes.ttl,bamm/meta-model/2.0.0/aspect-meta-model-shapes.ttl,bamm/characteristic/2.0.0/characteristic-shapes.ttl
133137
</excludes>
134138
</artifactItem>
135139
</artifactItems>
@@ -146,31 +150,71 @@
146150
<version>${download-maven-plugin-version}</version>
147151
<executions>
148152
<execution>
149-
<id>download-meta-model-shapes</id>
153+
<id>download-meta-model-shapes-1-0-0</id>
154+
<phase>process-resources</phase>
155+
<goals>
156+
<goal>wget</goal>
157+
</goals>
158+
<configuration>
159+
<url>
160+
${bamm-revision}/src/main/resources/bamm/meta-model/1.0.0/aspect-meta-model-shapes.ttl
161+
</url>
162+
<outputFileName>aspect-meta-model-shapes.ttl</outputFileName>
163+
<outputDirectory>${project.build.directory}/classes/bamm/meta-model/1.0.0</outputDirectory>
164+
<overwrite>true</overwrite>
165+
<followRedirects>true</followRedirects>
166+
<skipCache>true</skipCache>
167+
</configuration>
168+
</execution>
169+
<execution>
170+
<id>download-meta-model-shapes-2-0-0</id>
150171
<phase>process-resources</phase>
151172
<goals>
152173
<goal>wget</goal>
153174
</goals>
154175
<configuration>
155176
<url>
156-
https://raw.githubusercontent.com/OpenManufacturingPlatform/sds-bamm-aspect-meta-model/159ced3e69e5d694e5158f2942cb3182941cf032/src/main/resources/bamm/meta-model/2.0.0/aspect-meta-model-shapes.ttl
177+
${bamm-revision}/src/main/resources/bamm/meta-model/2.0.0/aspect-meta-model-shapes.ttl
157178
</url>
158179
<outputFileName>aspect-meta-model-shapes.ttl</outputFileName>
159180
<outputDirectory>${project.build.directory}/classes/bamm/meta-model/2.0.0</outputDirectory>
181+
<overwrite>true</overwrite>
182+
<followRedirects>true</followRedirects>
183+
<skipCache>true</skipCache>
184+
</configuration>
185+
</execution>
186+
<execution>
187+
<id>download-characteristics-shapes-1-0-0</id>
188+
<phase>process-resources</phase>
189+
<goals>
190+
<goal>wget</goal>
191+
</goals>
192+
<configuration>
193+
<url>
194+
${bamm-revision}/src/main/resources/bamm/characteristic/1.0.0/characteristic-shapes.ttl
195+
</url>
196+
<outputFileName>characteristic-shapes.ttl</outputFileName>
197+
<outputDirectory>${project.build.directory}/classes/bamm/characteristic/1.0.0</outputDirectory>
198+
<overwrite>true</overwrite>
199+
<followRedirects>true</followRedirects>
200+
<skipCache>true</skipCache>
160201
</configuration>
161202
</execution>
162203
<execution>
163-
<id>download-characteristics-shapes</id>
204+
<id>download-characteristics-shapes-2-0-0</id>
164205
<phase>process-resources</phase>
165206
<goals>
166207
<goal>wget</goal>
167208
</goals>
168209
<configuration>
169210
<url>
170-
https://raw.githubusercontent.com/OpenManufacturingPlatform/sds-bamm-aspect-meta-model/159ced3e69e5d694e5158f2942cb3182941cf032/src/main/resources/bamm/characteristic/2.0.0/characteristic-shapes.ttl
211+
${bamm-revision}/src/main/resources/bamm/characteristic/2.0.0/characteristic-shapes.ttl
171212
</url>
172213
<outputFileName>characteristic-shapes.ttl</outputFileName>
173214
<outputDirectory>${project.build.directory}/classes/bamm/characteristic/2.0.0</outputDirectory>
215+
<overwrite>true</overwrite>
216+
<followRedirects>true</followRedirects>
217+
<skipCache>true</skipCache>
174218
</configuration>
175219
</execution>
176220
</executions>

core/sds-aspect-meta-model-resolver/src/main/java/io/openmanufacturing/sds/aspectmodel/resolver/services/MetaModelUrls.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2021 Robert Bosch Manufacturing Solutions GmbH
33
*
44
* See the AUTHORS file(s) distributed with this work for additional
5-
* information regarding authorship.
5+
* information regarding authorship.
66
*
77
* This Source Code Form is subject to the terms of the Mozilla Public
88
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -13,12 +13,16 @@
1313

1414
package io.openmanufacturing.sds.aspectmodel.resolver.services;
1515

16+
import java.io.IOException;
1617
import java.net.URL;
18+
import java.util.List;
1719
import java.util.Optional;
1820

1921
import org.slf4j.Logger;
2022
import org.slf4j.LoggerFactory;
2123

24+
import com.google.common.collect.ImmutableList;
25+
2226
import io.openmanufacturing.sds.aspectmetamodel.KnownVersion;
2327

2428
/**
@@ -40,10 +44,36 @@ private MetaModelUrls() {
4044
*/
4145
public static Optional<URL> url( final String part, final KnownVersion version, final String fileName ) {
4246
final String spec = String.format( "bamm/%s/%s/%s", part, version.toVersionString(), fileName );
43-
final URL result = MetaModelUrls.class.getClassLoader().getResource( spec );
44-
if ( result == null ) {
45-
LOG.warn( "Could not resolve meta model resource {}", spec );
47+
try {
48+
final List<URL> urls = ImmutableList.copyOf( MetaModelUrls.class.getClassLoader().getResources( spec ).asIterator() );
49+
if ( urls.size() == 1 ) {
50+
return Optional.of( urls.get( 0 ) );
51+
}
52+
if ( urls.isEmpty() ) {
53+
return nothingFound( spec );
54+
}
55+
56+
// If multiple resources with the given spec are found:
57+
// - return the one from the file system, if it exists
58+
// - otherwise, the one from jar
59+
// - otherwise, any of the found resources
60+
URL jarUrl = null;
61+
for ( final URL url : urls ) {
62+
if ( url.getProtocol().equals( "file" ) ) {
63+
return Optional.of( url );
64+
}
65+
if ( url.getProtocol().equals( "jar" ) ) {
66+
jarUrl = url;
67+
}
68+
}
69+
return Optional.of( jarUrl == null ? urls.get( 0 ) : jarUrl );
70+
} catch ( final IOException e ) {
71+
return nothingFound( spec );
4672
}
47-
return Optional.ofNullable( result );
73+
}
74+
75+
private static Optional<URL> nothingFound( final String spec ) {
76+
LOG.warn( "Could not resolve meta model resource {}", spec );
77+
return Optional.empty();
4878
}
4979
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
*/
1313
package io.openmanufacturing.sds.aspectmodel.aas;
1414

15-
import static org.junit.jupiter.api.Assertions.assertEquals;
16-
import static org.junit.jupiter.api.Assertions.assertFalse;
17-
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
import static org.junit.jupiter.api.Assertions.*;
1816

1917
import java.io.ByteArrayInputStream;
2018
import java.io.ByteArrayOutputStream;
@@ -227,7 +225,9 @@ void testGenerateAasxFromBammAspectWithEnumeration() throws IOException, Deseria
227225
value = TestAspect.class,
228226
mode = EnumSource.Mode.EXCLUDE,
229227
names = {
230-
"ASPECT_WITH_STRING_ENUMERATION"
228+
"ASPECT_WITH_STRING_ENUMERATION",
229+
"MODEL_WITH_CYCLES",
230+
"MODEL_WITH_BROKEN_CYCLES"
231231
} )
232232
// anonymous enumeration in test has no urn for enum values but is required for Concept
233233
// Description referencing

0 commit comments

Comments
 (0)