Skip to content

Commit b5cdf7c

Browse files
committed
Merge branch 'main' into 2.1.x
2 parents b76992d + 233c103 commit b5cdf7c

File tree

146 files changed

+10707
-490
lines changed

Some content is hidden

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

146 files changed

+10707
-490
lines changed

.github/workflows/pull_request_check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ jobs:
1414
uses: actions/setup-java@v2
1515
with:
1616
distribution: 'temurin'
17-
java-version: '11'
17+
java-version: '17'
1818
- name: Run tests
1919
run: mvn -B clean install

.github/workflows/release-workflow.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
with:
1515
ref: main
1616
fetch-depth: 0
17-
- name: Set up JDK 11
17+
- name: Set up JDK 17
1818
uses: actions/setup-java@v2
1919
with:
2020
distribution: 'temurin'
21-
java-version: '11'
21+
java-version: '17'
2222
server-id: ossrh
2323
server-username: OSSRH_USERNAME
2424
server-password: OSSRH_TOKEN

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
package io.openmanufacturing.sds.metamodel.loader;
1515

16+
import java.util.ArrayList;
1617
import java.util.List;
1718
import java.util.Optional;
1819
import java.util.Set;
1920

2021
import org.apache.jena.rdf.model.Model;
22+
import org.apache.jena.rdf.model.Resource;
23+
import org.apache.jena.rdf.model.Statement;
2124
import org.apache.jena.rdf.model.StmtIterator;
2225
import org.apache.jena.vocabulary.RDF;
2326
import org.slf4j.Logger;
@@ -29,6 +32,7 @@
2932
import io.openmanufacturing.sds.aspectmodel.UnsupportedVersionException;
3033
import io.openmanufacturing.sds.aspectmodel.resolver.AspectModelResolver;
3134
import io.openmanufacturing.sds.aspectmodel.resolver.exceptions.InvalidModelException;
35+
import io.openmanufacturing.sds.aspectmodel.resolver.exceptions.InvalidNamespaceException;
3236
import io.openmanufacturing.sds.aspectmodel.resolver.exceptions.InvalidRootElementCountException;
3337
import io.openmanufacturing.sds.aspectmodel.resolver.exceptions.InvalidVersionException;
3438
import io.openmanufacturing.sds.aspectmodel.resolver.services.VersionedModel;
@@ -73,9 +77,12 @@ private static Try<Aspect> load( final VersionedModel versionedModel ) {
7377
final BAMM bamm = new BAMM( metaModelVersion.get() );
7478
final StmtIterator iterator = model.listStatements( null, RDF.type, bamm.Aspect() );
7579
try {
80+
validateNamespaceOfCustomUnits( bamm, versionedModel.getRawModel() );
7681
final ModelElementFactory modelElementFactory = new ModelElementFactory( metaModelVersion.get(), model );
7782
final Aspect aspect = modelElementFactory.create( Aspect.class, iterator.nextStatement().getSubject() );
7883
return Try.success( aspect );
84+
} catch ( final InvalidNamespaceException exception ) {
85+
return Try.failure( exception );
7986
} catch ( final RuntimeException exception ) {
8087
return Try.failure( new InvalidModelException( "Could not load Aspect model, please make sure the model is valid", exception ) );
8188
}
@@ -114,6 +121,21 @@ public static Try<Aspect> fromVersionedModel( final VersionedModel versionedMode
114121
} );
115122
}
116123

124+
private static void validateNamespaceOfCustomUnits( final BAMM bamm, final Model rawModel ) {
125+
final List<String> customUnitsWithBammNamespace = new ArrayList<>();
126+
rawModel.listStatements( null, RDF.type, bamm.Unit() )
127+
.mapWith( Statement::getSubject )
128+
.filterKeep( subject -> subject.getNameSpace().equals( bamm.getNamespace() ) )
129+
.mapWith( Resource::getLocalName )
130+
.forEach( customUnitsWithBammNamespace::add );
131+
132+
if ( !customUnitsWithBammNamespace.isEmpty() ) {
133+
throw new InvalidNamespaceException(
134+
String.format( "Aspect model contains unit(s) %s not specified in the unit catalog but referred with bamm namespace",
135+
customUnitsWithBammNamespace ) );
136+
}
137+
}
138+
117139
private static List<Try<AspectModelUrn>> getUrns( final VersionedModel migratedModel, final KnownVersion version ) {
118140
final BAMM bamm = new BAMM( version );
119141
return migratedModel.getModel().listStatements( null, RDF.type, bamm.Aspect() ).mapWith( statement ->

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: 117 additions & 3 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>
@@ -50,8 +54,8 @@
5054
<artifactId>jena-core</artifactId>
5155
</dependency>
5256
<dependency>
53-
<groupId>org.topbraid</groupId>
54-
<artifactId>shacl</artifactId>
57+
<groupId>org.apache.jena</groupId>
58+
<artifactId>jena-arq</artifactId>
5559
</dependency>
5660
<dependency>
5761
<groupId>io.vavr</groupId>
@@ -88,14 +92,14 @@
8892
<artifactId>lombok</artifactId>
8993
<scope>test</scope>
9094
</dependency>
91-
9295
</dependencies>
9396

9497
<build>
9598
<plugins>
9699
<plugin>
97100
<groupId>org.apache.maven.plugins</groupId>
98101
<artifactId>maven-compiler-plugin</artifactId>
102+
<version>${maven-compiler-plugin-version}</version>
99103
<configuration>
100104
<annotationProcessorPaths>
101105
<path>
@@ -106,6 +110,116 @@
106110
</annotationProcessorPaths>
107111
</configuration>
108112
</plugin>
113+
114+
<!-- Exclude updated meta model shape files from sds-aspect-meta-model dependency -->
115+
<plugin>
116+
<groupId>org.apache.maven.plugins</groupId>
117+
<artifactId>maven-dependency-plugin</artifactId>
118+
<version>${maven-dependency-plugin-version}</version>
119+
<executions>
120+
<execution>
121+
<id>unpack</id>
122+
<phase>generate-sources</phase>
123+
<goals>
124+
<goal>unpack</goal>
125+
</goals>
126+
<configuration>
127+
<artifactItems>
128+
<artifactItem>
129+
<groupId>io.openmanufacturing</groupId>
130+
<artifactId>sds-aspect-meta-model</artifactId>
131+
<version>${aspect-meta-model-version}</version>
132+
<type>jar</type>
133+
<overWrite>false</overWrite>
134+
<outputDirectory>${project.build.directory}/classes</outputDirectory>
135+
<excludes>
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
137+
</excludes>
138+
</artifactItem>
139+
</artifactItems>
140+
</configuration>
141+
</execution>
142+
</executions>
143+
</plugin>
144+
145+
<!-- Download updated meta model shape files -->
146+
<!-- This refers to the state of the shape files after merging of https://github.com/OpenManufacturingPlatform/sds-bamm-aspect-meta-model/pull/176 -->
147+
<plugin>
148+
<groupId>com.googlecode.maven-download-plugin</groupId>
149+
<artifactId>download-maven-plugin</artifactId>
150+
<version>${download-maven-plugin-version}</version>
151+
<executions>
152+
<execution>
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>
171+
<phase>process-resources</phase>
172+
<goals>
173+
<goal>wget</goal>
174+
</goals>
175+
<configuration>
176+
<url>
177+
${bamm-revision}/src/main/resources/bamm/meta-model/2.0.0/aspect-meta-model-shapes.ttl
178+
</url>
179+
<outputFileName>aspect-meta-model-shapes.ttl</outputFileName>
180+
<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>
201+
</configuration>
202+
</execution>
203+
<execution>
204+
<id>download-characteristics-shapes-2-0-0</id>
205+
<phase>process-resources</phase>
206+
<goals>
207+
<goal>wget</goal>
208+
</goals>
209+
<configuration>
210+
<url>
211+
${bamm-revision}/src/main/resources/bamm/characteristic/2.0.0/characteristic-shapes.ttl
212+
</url>
213+
<outputFileName>characteristic-shapes.ttl</outputFileName>
214+
<outputDirectory>${project.build.directory}/classes/bamm/characteristic/2.0.0</outputDirectory>
215+
<overwrite>true</overwrite>
216+
<followRedirects>true</followRedirects>
217+
<skipCache>true</skipCache>
218+
</configuration>
219+
</execution>
220+
</executions>
221+
</plugin>
222+
109223
</plugins>
110224
</build>
111225
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
package io.openmanufacturing.sds.aspectmodel.resolver.exceptions;
14+
15+
import java.io.Serial;
16+
17+
/**
18+
* An exception indicating that usage of the given namespace is invalid.
19+
*/
20+
public final class InvalidNamespaceException extends RuntimeException {
21+
22+
@Serial
23+
private static final long serialVersionUID = -1075433954587137319L;
24+
25+
/**
26+
* Creates an instance of the exception.
27+
* @param message The detailed message of the problem.
28+
* @param cause The cause of the problem.
29+
*/
30+
public InvalidNamespaceException( final String message, final Throwable cause ) {
31+
super( message, cause );
32+
}
33+
34+
/**
35+
* Creates an instance of the exception.
36+
* @param message The detailed message of the problem.
37+
*/
38+
public InvalidNamespaceException( final String message ) {
39+
super( message );
40+
}
41+
42+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.resolver.exceptions;
15+
16+
public class ParserException extends Exception {
17+
private final String sourceDocument;
18+
19+
public ParserException( final Throwable cause, final String sourceDocument ) {
20+
super( cause.getMessage(), cause );
21+
this.sourceDocument = sourceDocument;
22+
}
23+
24+
public String getSourceDocument() {
25+
return sourceDocument;
26+
}
27+
}

0 commit comments

Comments
 (0)