Skip to content

Commit 646aa93

Browse files
authored
Merge pull request #244 from bci-oss/201-improve-validation-api
Improve validation API
2 parents 6d48d90 + 6573c60 commit 646aa93

File tree

125 files changed

+9298
-291
lines changed

Some content is hidden

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

125 files changed

+9298
-291
lines changed

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

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
<artifactId>jena-core</artifactId>
5151
</dependency>
5252
<dependency>
53-
<groupId>org.topbraid</groupId>
54-
<artifactId>shacl</artifactId>
53+
<groupId>org.apache.jena</groupId>
54+
<artifactId>jena-arq</artifactId>
5555
</dependency>
5656
<dependency>
5757
<groupId>io.vavr</groupId>
@@ -88,14 +88,14 @@
8888
<artifactId>lombok</artifactId>
8989
<scope>test</scope>
9090
</dependency>
91-
9291
</dependencies>
9392

9493
<build>
9594
<plugins>
9695
<plugin>
9796
<groupId>org.apache.maven.plugins</groupId>
9897
<artifactId>maven-compiler-plugin</artifactId>
98+
<version>${maven-compiler-plugin-version}</version>
9999
<configuration>
100100
<annotationProcessorPaths>
101101
<path>
@@ -106,6 +106,76 @@
106106
</annotationProcessorPaths>
107107
</configuration>
108108
</plugin>
109+
110+
<!-- Exclude updated meta model shape files from sds-aspect-meta-model dependency -->
111+
<plugin>
112+
<groupId>org.apache.maven.plugins</groupId>
113+
<artifactId>maven-dependency-plugin</artifactId>
114+
<version>${maven-dependency-plugin-version}</version>
115+
<executions>
116+
<execution>
117+
<id>unpack</id>
118+
<phase>generate-sources</phase>
119+
<goals>
120+
<goal>unpack</goal>
121+
</goals>
122+
<configuration>
123+
<artifactItems>
124+
<artifactItem>
125+
<groupId>io.openmanufacturing</groupId>
126+
<artifactId>sds-aspect-meta-model</artifactId>
127+
<version>${aspect-meta-model-version}</version>
128+
<type>jar</type>
129+
<overWrite>true</overWrite>
130+
<outputDirectory>${project.build.directory}/classes</outputDirectory>
131+
<excludes>
132+
bamm/meta-model/2.0.0/aspect-meta-model-shapes.ttl,bamm/characteristic/2.0.0/characteristic-shapes.ttl
133+
</excludes>
134+
</artifactItem>
135+
</artifactItems>
136+
</configuration>
137+
</execution>
138+
</executions>
139+
</plugin>
140+
141+
<!-- Download updated meta model shape files -->
142+
<!-- This refers to the state of the shape files after merging of https://github.com/OpenManufacturingPlatform/sds-bamm-aspect-meta-model/pull/176 -->
143+
<plugin>
144+
<groupId>com.googlecode.maven-download-plugin</groupId>
145+
<artifactId>download-maven-plugin</artifactId>
146+
<version>${download-maven-plugin-version}</version>
147+
<executions>
148+
<execution>
149+
<id>download-meta-model-shapes</id>
150+
<phase>process-resources</phase>
151+
<goals>
152+
<goal>wget</goal>
153+
</goals>
154+
<configuration>
155+
<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
157+
</url>
158+
<outputFileName>aspect-meta-model-shapes.ttl</outputFileName>
159+
<outputDirectory>${project.build.directory}/classes/bamm/meta-model/2.0.0</outputDirectory>
160+
</configuration>
161+
</execution>
162+
<execution>
163+
<id>download-characteristics-shapes</id>
164+
<phase>process-resources</phase>
165+
<goals>
166+
<goal>wget</goal>
167+
</goals>
168+
<configuration>
169+
<url>
170+
https://raw.githubusercontent.com/OpenManufacturingPlatform/sds-bamm-aspect-meta-model/159ced3e69e5d694e5158f2942cb3182941cf032/src/main/resources/bamm/characteristic/2.0.0/characteristic-shapes.ttl
171+
</url>
172+
<outputFileName>characteristic-shapes.ttl</outputFileName>
173+
<outputDirectory>${project.build.directory}/classes/bamm/characteristic/2.0.0</outputDirectory>
174+
</configuration>
175+
</execution>
176+
</executions>
177+
</plugin>
178+
109179
</plugins>
110180
</build>
111181
</project>
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+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525

2626
import org.apache.jena.rdf.model.Model;
2727
import org.apache.jena.rdf.model.ModelFactory;
28+
import org.apache.jena.rdf.model.Property;
2829
import org.apache.jena.rdf.model.RDFNode;
2930
import org.apache.jena.rdf.model.Resource;
3031
import org.apache.jena.rdf.model.ResourceFactory;
3132
import org.apache.jena.rdf.model.Statement;
3233
import org.apache.jena.vocabulary.RDF;
33-
import org.topbraid.shacl.vocabulary.SH;
3434

3535
import com.google.common.collect.ImmutableMap;
3636
import com.google.common.collect.Streams;
@@ -165,7 +165,8 @@ public Try<Model> loadShapesModel( final KnownVersion bammVersion ) {
165165
* @return the tuples of the original statement to replace and the replacement statement
166166
*/
167167
private Set<Tuple2<Statement, Statement>> determineBammUrlsToReplace( final Model model ) {
168-
return Streams.stream( model.listStatements( null, SH.jsLibraryURL, (RDFNode) null ) )
168+
final Property shaclJsLibraryUrl = ResourceFactory.createProperty( "http://www.w3.org/ns/shacl#jsLibraryURL" );
169+
return Streams.stream( model.listStatements( null, shaclJsLibraryUrl, (RDFNode) null ) )
169170
.filter( statement -> statement.getObject().isLiteral() )
170171
.filter( statement -> statement.getObject().asLiteral().getString().startsWith( "bamm://" ) )
171172
.flatMap( statement -> rewriteBammUrl( statement.getObject().asLiteral().getString() )

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

Lines changed: 16 additions & 3 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
@@ -12,9 +12,14 @@
1212
*/
1313
package io.openmanufacturing.sds.aspectmodel.resolver.services;
1414

15+
import java.io.BufferedReader;
16+
import java.io.ByteArrayInputStream;
1517
import java.io.IOException;
1618
import java.io.InputStream;
19+
import java.io.InputStreamReader;
1720
import java.net.URL;
21+
import java.nio.charset.StandardCharsets;
22+
import java.util.stream.Collectors;
1823

1924
import javax.annotation.Nullable;
2025

@@ -25,6 +30,7 @@
2530
import org.slf4j.Logger;
2631
import org.slf4j.LoggerFactory;
2732

33+
import io.openmanufacturing.sds.aspectmodel.resolver.exceptions.ParserException;
2834
import io.vavr.control.Try;
2935

3036
public final class TurtleLoader {
@@ -47,8 +53,13 @@ public static Try<Model> loadTurtle( @Nullable final InputStream inputStream ) {
4753
return Try.failure( new IllegalArgumentException() );
4854
}
4955

56+
final String modelContent = new BufferedReader(
57+
new InputStreamReader( inputStream, StandardCharsets.UTF_8 ) )
58+
.lines()
59+
.collect( Collectors.joining( "\n" ) );
60+
5061
final Model streamModel = ModelFactory.createDefaultModel();
51-
try ( final InputStream turtleInputStream = inputStream ) {
62+
try ( final InputStream turtleInputStream = new ByteArrayInputStream( modelContent.getBytes() ) ) {
5263
streamModel.read( turtleInputStream, "", RDFLanguages.TURTLE.getName() );
5364
return Try.success( streamModel );
5465
} catch ( final IllegalArgumentException exception ) {
@@ -57,8 +68,10 @@ public static Try<Model> loadTurtle( @Nullable final InputStream inputStream ) {
5768
final String formattedErrorMessage = String
5869
.format( incorrectDataTypeDefinitionMessage, exception.getMessage() );
5970
return Try.failure( new IllegalArgumentException( formattedErrorMessage ) );
60-
} catch ( final IOException | RiotException exception ) {
71+
} catch ( final IOException exception ) {
6172
return Try.failure( exception );
73+
} catch ( final RiotException exception ) {
74+
return Try.failure( new ParserException( exception, modelContent ) );
6275
}
6376
}
6477

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

Lines changed: 2 additions & 3 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
@@ -30,11 +30,10 @@
3030
import org.junit.jupiter.params.ParameterizedTest;
3131
import org.junit.jupiter.params.provider.MethodSource;
3232

33+
import io.openmanufacturing.sds.aspectmetamodel.KnownVersion;
3334
import io.openmanufacturing.sds.test.MetaModelVersions;
3435
import io.openmanufacturing.sds.test.TestAspect;
3536

36-
import io.openmanufacturing.sds.aspectmetamodel.KnownVersion;
37-
3837
public class EntityInstance2BoxModelTest extends MetaModelVersions {
3938
private final String sparqlQueryFileName = "entityinstance2boxmodel.sparql";
4039
private final String entityInstance2EntityInstanceEdgesSparqlQueryFileName = "entityinstance-nestedentityinstance-edges2boxmodel.sparql";

core/sds-aspect-model-resolver/src/main/java/io/openmanufacturing/sds/aspectmodel/resolver/AspectModelResolver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public Try<VersionedModel> resolveAspectModel( final ResolutionStrategy resolver
101101

102102
if ( mergedModel.isFailure() ) {
103103
if ( mergedModel.getCause() instanceof FileNotFoundException ) {
104-
return Try.failure( new ModelResolutionException( "While trying to resolve " + input + ": " + mergedModel.getCause() ) );
104+
return Try.failure( new ModelResolutionException( "Could not resolve " + input, mergedModel.getCause() ) );
105105
}
106106
return Try.failure( mergedModel.getCause() );
107107
}
@@ -219,7 +219,8 @@ private Try<Model> getModelForUrn( final String urn, final ResolutionStrategy re
219219
}
220220
return resolutionStrategy.apply( aspectModelUrn ).flatMap( model -> {
221221
if ( !model.contains( model.createResource( urn ), RDF.type, (RDFNode) null ) ) {
222-
return Try.failure( new ModelResolutionException( "Resolution strategy returned a model which does contain element definition for " + urn ) );
222+
return Try.failure(
223+
new ModelResolutionException( "Resolution strategy returned a model which does not contain element definition for " + urn ) );
223224
}
224225
return Try.success( model );
225226
} );

core/sds-aspect-model-resolver/src/main/java/io/openmanufacturing/sds/aspectmodel/resolver/ClasspathStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,6 @@ public Try<Model> apply( final AspectModelUrn aspectModelUrn ) {
173173
.getOrElse( false ) )
174174
.findFirst()
175175
.orElse( Try.failure( new FileNotFoundException(
176-
"The model file " + aspectModelUrn + " could not be found in directory: " + directory ) ) );
176+
"No model file containing " + aspectModelUrn + " could be found in directory: " + directory ) ) );
177177
}
178178
}

core/sds-aspect-model-resolver/src/main/java/io/openmanufacturing/sds/aspectmodel/resolver/FileSystemStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ public Try<Model> apply( final AspectModelUrn aspectModelUrn ) {
9090
.getOrElse( false ) )
9191
.findFirst()
9292
.orElse( Try.failure( new FileNotFoundException(
93-
"The model file " + aspectModelUrn.toString() + " could not be found in directory: " + directory ) ) );
93+
"No model file containing " + aspectModelUrn.toString() + " could be found in directory: " + directory ) ) );
9494
}
9595
}

core/sds-aspect-model-resolver/src/main/java/io/openmanufacturing/sds/aspectmodel/resolver/ModelResolutionException.java

Lines changed: 3 additions & 3 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
@@ -20,7 +20,7 @@ public ModelResolutionException( final String message ) {
2020
super( message );
2121
}
2222

23-
public ModelResolutionException( final Throwable cause ) {
24-
super( cause );
23+
public ModelResolutionException( final String message, final Throwable cause ) {
24+
super( message, cause );
2525
}
2626
}

core/sds-aspect-model-validator/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@
5252
<groupId>io.openmanufacturing</groupId>
5353
<artifactId>sds-aspect-model-resolver</artifactId>
5454
</dependency>
55+
<dependency>
56+
<groupId>org.graalvm.sdk</groupId>
57+
<artifactId>graal-sdk</artifactId>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.graalvm.js</groupId>
61+
<artifactId>js</artifactId>
62+
<scope>runtime</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.graalvm.js</groupId>
66+
<artifactId>js-scriptengine</artifactId>
67+
</dependency>
5568
<dependency>
5669
<groupId>org.projectlombok</groupId>
5770
<artifactId>lombok</artifactId>

0 commit comments

Comments
 (0)