Skip to content

Commit 803e6fe

Browse files
committed
Adapt esmf-aspect-model-document-generators to SAMM 2.1.0
1 parent aa44216 commit 803e6fe

File tree

45 files changed

+2753
-106
lines changed

Some content is hidden

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

45 files changed

+2753
-106
lines changed

core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/diagram/AspectModelDiagramGenerator.java

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.OutputStream;
2525
import java.io.UncheckedIOException;
2626
import java.nio.charset.StandardCharsets;
27-
import java.nio.file.Files;
2827
import java.util.Base64;
2928
import java.util.EnumMap;
3029
import java.util.List;
@@ -33,22 +32,8 @@
3332
import java.util.Scanner;
3433
import java.util.Set;
3534
import java.util.function.Function;
36-
import java.util.stream.Collectors;
3735
import java.util.stream.StreamSupport;
3836

39-
import org.apache.commons.text.StringEscapeUtils;
40-
import org.apache.commons.text.WordUtils;
41-
import org.apache.jena.query.ARQ;
42-
import org.apache.jena.query.Query;
43-
import org.apache.jena.query.QueryFactory;
44-
import org.apache.jena.rdf.model.Model;
45-
import org.apache.jena.rdf.model.ModelFactory;
46-
import org.apache.jena.rdf.model.Property;
47-
import org.apache.jena.rdf.model.RDFNode;
48-
import org.apache.jena.rdf.model.Resource;
49-
import org.apache.jena.rdf.model.ResourceFactory;
50-
import org.apache.jena.rdf.model.Statement;
51-
import org.apache.jena.vocabulary.RDF;
5237
import org.eclipse.esmf.aspectmodel.UnsupportedVersionException;
5338
import org.eclipse.esmf.aspectmodel.generator.LanguageCollector;
5439
import org.eclipse.esmf.aspectmodel.resolver.services.MetaModelUrls;
@@ -59,10 +44,22 @@
5944
import org.eclipse.esmf.samm.KnownVersion;
6045

6146
import com.google.common.collect.ImmutableList;
62-
6347
import guru.nidi.graphviz.engine.Graphviz;
6448
import guru.nidi.graphviz.model.MutableGraph;
6549
import guru.nidi.graphviz.parse.Parser;
50+
import org.apache.commons.text.StringEscapeUtils;
51+
import org.apache.commons.text.WordUtils;
52+
import org.apache.jena.query.ARQ;
53+
import org.apache.jena.query.Query;
54+
import org.apache.jena.query.QueryFactory;
55+
import org.apache.jena.rdf.model.Model;
56+
import org.apache.jena.rdf.model.ModelFactory;
57+
import org.apache.jena.rdf.model.Property;
58+
import org.apache.jena.rdf.model.RDFNode;
59+
import org.apache.jena.rdf.model.Resource;
60+
import org.apache.jena.rdf.model.ResourceFactory;
61+
import org.apache.jena.rdf.model.Statement;
62+
import org.apache.jena.vocabulary.RDF;
6663

6764
public class AspectModelDiagramGenerator {
6865
public enum Format {
@@ -140,6 +137,11 @@ ImmutableList.<String> builder().addAll( queryFilesForAllMetaModelVersions )
140137
.addAll( queryFilesForMetaModelVersionsAsOf2_0_0 )
141138
.build() );
142139

140+
aspectToBoxmodelQueryFiles.put( KnownVersion.SAMM_2_1_0,
141+
ImmutableList.<String> builder().addAll( queryFilesForAllMetaModelVersions )
142+
.addAll( queryFilesForMetaModelVersionsAsOf2_0_0 )
143+
.build() );
144+
143145
ARQ.init();
144146
model = versionedModel.getModel();
145147
metaModelVersion = KnownVersion.fromVersionString( versionedModel.getMetaModelVersion().toString() )
@@ -171,7 +173,7 @@ String getInputStreamAsString( final String resource ) {
171173
private void generatePng( final String dotInput, final OutputStream output ) throws IOException {
172174
// To make the font available during PNG generation, it needs to be registered
173175
// in Java Runtime's graphics environment
174-
try{
176+
try {
175177
final File tmpFontFile = generateTmpFontFile();
176178
final Font f = Font.createFont( Font.TRUETYPE_FONT, tmpFontFile );
177179
final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
@@ -184,17 +186,19 @@ private void generatePng( final String dotInput, final OutputStream output ) thr
184186
final Graphviz graphviz = Graphviz.fromGraph( g );
185187
graphviz.render( guru.nidi.graphviz.engine.Format.PNG ).toOutputStream( output );
186188
}
189+
187190
private File generateTmpFontFile() throws IOException {
188-
File tempFontFile = new File( System.getProperty( "java.io.tmpdir" ) + File.separator + "aspect-model-diagram.tmp" );
189-
if ( !tempFontFile.exists() ){
191+
final File tempFontFile = new File( System.getProperty( "java.io.tmpdir" ) + File.separator + "aspect-model-diagram.tmp" );
192+
if ( !tempFontFile.exists() ) {
190193
try ( final InputStream fontStream = getInputStream( FONT_FILE );
191-
final OutputStream output = new FileOutputStream( tempFontFile, false ) ){
192-
fontStream.transferTo( output );
193-
}
194+
final OutputStream output = new FileOutputStream( tempFontFile, false ) ) {
195+
fontStream.transferTo( output );
196+
}
194197
}
195198
tempFontFile.deleteOnExit();
196-
return tempFontFile;
199+
return tempFontFile;
197200
}
201+
198202
private String base64EncodeInputStream( final InputStream in ) throws IOException {
199203
try ( final ByteArrayOutputStream os = new ByteArrayOutputStream() ) {
200204
final byte[] buffer = new byte[1024];
@@ -223,16 +227,16 @@ private void generateSvg( final String dotInput, final OutputStream output ) thr
223227
+ "\");\n"
224228
+ "}\n"
225229
+ "</style>";
226-
final String result = svgOutput.toString( StandardCharsets.UTF_8.name() )
230+
final String result = svgOutput.toString( StandardCharsets.UTF_8 )
227231
.replaceFirst( ">", ">" + css );
228-
output.write( result.getBytes( StandardCharsets.UTF_8.name() ) );
232+
output.write( result.getBytes( StandardCharsets.UTF_8 ) );
229233
}
230234
}
231235

232236
private void breakLongLinesAndEscapeTexts( final Model model ) {
233237
final Property text = boxModelNamespace.text();
234238
final Iterable<Statement> statementIterable = () -> model.listStatements( null, text, (RDFNode) null );
235-
StreamSupport.stream( statementIterable.spliterator(), false ).collect( Collectors.toList() )
239+
StreamSupport.stream( statementIterable.spliterator(), false ).toList()
236240
.forEach( oldStatement -> {
237241
final String newValue = WordUtils.wrap( oldStatement.getLiteral().getString(), 60, "\\l   ", false );
238242
final String escapedValue = StringEscapeUtils.escapeHtml4( newValue );
@@ -297,15 +301,9 @@ public void generateDiagram( final Format outputFormat, final Locale language, f
297301
final String dotResult = generateDot( language );
298302

299303
switch ( outputFormat ) {
300-
case DOT:
301-
out.write( dotResult.getBytes( StandardCharsets.UTF_8 ) );
302-
break;
303-
case PNG:
304-
generatePng( dotResult, out );
305-
break;
306-
case SVG:
307-
generateSvg( dotResult, out );
308-
break;
304+
case DOT -> out.write( dotResult.getBytes( StandardCharsets.UTF_8 ) );
305+
case PNG -> generatePng( dotResult, out );
306+
case SVG -> generateSvg( dotResult, out );
309307
}
310308
}
311309

@@ -349,15 +347,9 @@ public void generateDiagrams( final Set<Format> targetFormats, final Locale lang
349347
try ( final OutputStream outputStream = nameMapper
350348
.apply( format.getArtifactFilename( aspectName, language ) ) ) {
351349
switch ( format ) {
352-
case DOT:
353-
outputStream.write( dotResult.getBytes( StandardCharsets.UTF_8.name() ) );
354-
break;
355-
case PNG:
356-
generatePng( dotResult, outputStream );
357-
break;
358-
case SVG:
359-
generateSvg( dotResult, outputStream );
360-
break;
350+
case DOT -> outputStream.write( dotResult.getBytes( StandardCharsets.UTF_8 ) );
351+
case PNG -> generatePng( dotResult, outputStream );
352+
case SVG -> generateSvg( dotResult, outputStream );
361353
}
362354
}
363355
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright (c) 2023 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 samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#>
13+
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
14+
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
15+
prefix : <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0/boxmodel#>
16+
prefix func: <urn:samm:org.eclipse.esmf.samm:function:2.0.0#>
17+
18+
# Generates boxes for Abstract Entities
19+
construct {
20+
?abstractEntityBox a :Box .
21+
?abstractEntityBox :prototype "Abstract Entity" .
22+
?abstractEntityBox :title ?abstractEntityName .
23+
?abstractEntityBox :modelElement ?abstractEntity .
24+
?abstractEntityBox :entries (
25+
[
26+
a :Entry ;
27+
:title "preferredName" ;
28+
:text ?preferredName
29+
]
30+
[
31+
a :Entry ;
32+
:title "description" ;
33+
:text ?description
34+
]
35+
[
36+
a :Entry ;
37+
:title "see" ;
38+
:text ?seeValues
39+
]
40+
)
41+
} where {
42+
?abstractEntity rdf:type samm:AbstractEntity .
43+
bind( strafter( str( ?abstractEntity ), "#" ) as ?abstractEntityName )
44+
45+
bind( concat( ?abstractEntityName, "AbstractEntity" ) as ?boxName )
46+
bind( iri( concat( func:getNamespace( ?abstractEntity ), ?boxName ) ) as ?abstractEntityBox )
47+
48+
optional {
49+
?abstractEntity samm:preferredName ?preferredNameValue .
50+
filter( lang( ?preferredNameValue ) = "en" )
51+
bind( xsd:string( ?preferredNameValue ) as ?preferredName )
52+
}
53+
54+
optional {
55+
?abstractEntity samm:description ?descriptionValue .
56+
filter( lang( ?descriptionValue ) = "en" )
57+
bind( xsd:string( ?descriptionValue ) as ?description )
58+
}
59+
60+
optional {
61+
{
62+
select ( group_concat( ?seeValue; separator=", " ) as ?seeValues ) ?abstractEntity
63+
where {
64+
select *
65+
where {
66+
?abstractEntity rdf:type samm:AbstractEntity .
67+
?abstractEntity samm:see ?seeValue .
68+
}
69+
order by str( ?seeValue )
70+
}
71+
group by ?abstractEntity
72+
}
73+
}
74+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright (c) 2023 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 samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#>
13+
prefix samm-e: <urn:samm:org.eclipse.esmf.samm:entity:2.1.0#>
14+
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
15+
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
16+
prefix : <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0/boxmodel#>
17+
prefix func: <urn:samm:org.eclipse.esmf.samm:function:2.0.0#>
18+
19+
# Generates boxes for Properties
20+
construct {
21+
?propertyBox a :Box .
22+
?propertyBox :prototype "AbstractProperty" .
23+
?propertyBox :title ?propertyName .
24+
?propertyBox :modelElement ?property .
25+
?propertyBox :entries (
26+
[
27+
a :Entry ;
28+
:title "preferredName" ;
29+
:text ?preferredName
30+
]
31+
[
32+
a :Entry ;
33+
:title "description" ;
34+
:text ?description
35+
]
36+
[
37+
a :Entry ;
38+
:title "see" ;
39+
:text ?seeValues
40+
]
41+
)
42+
} where {
43+
#process Properties defined in the Aspect Model being processed
44+
{
45+
?property rdf:type samm:AbstractProperty .
46+
bind( strafter( str( ?property ), "#" ) as ?propertyName ) .
47+
48+
bind( concat( ?propertyName, "AbstractProperty" ) as ?boxName )
49+
bind( iri( concat( func:getNamespace( ?property ), ?boxName ) ) as ?propertyBox )
50+
51+
optional {
52+
?property samm:preferredName ?preferredNameValue .
53+
filter( lang( ?preferredNameValue ) = "en" )
54+
bind( xsd:string( ?preferredNameValue ) as ?preferredName )
55+
}
56+
57+
optional {
58+
?property samm:description ?descriptionValue .
59+
filter( lang( ?descriptionValue ) = "en" )
60+
bind( xsd:string( ?descriptionValue ) as ?description )
61+
}
62+
63+
#subquery which concatenates all values for the samm:see attributes
64+
optional {
65+
select * where {
66+
?property rdf:type samm:Property .
67+
filter( str( ?subQueryProperty ) = str( ?property ) )
68+
{
69+
select ?subQueryProperty ( group_concat( ?seeValue; separator=", " ) as ?seeValues )
70+
where {
71+
select *
72+
where {
73+
?subQueryProperty rdf:type samm:Property .
74+
?subQueryProperty samm:see ?seeValue .
75+
}
76+
order by str( ?seeValue )
77+
}
78+
group by ?subQueryProperty
79+
}
80+
}
81+
}
82+
}
83+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) 2023 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 samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#>
13+
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
14+
prefix : <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0/boxmodel#>
15+
prefix func: <urn:samm:org.eclipse.esmf.samm:function:2.0.0#>
16+
17+
# Generate edges between Aspects and Operations
18+
construct {
19+
?edge a :Edge .
20+
?edge :title "operation" .
21+
?edge :from ?from .
22+
?edge :to ?to .
23+
} where {
24+
?aspect a samm:Aspect .
25+
bind( strafter( str( ?aspect ), "#" ) as ?aspectName ) .
26+
?operation a samm:Operation .
27+
bind( strafter( str( ?operation ), "#" ) as ?operationName ) .
28+
filter( exists { ?aspect samm:operations/rdf:rest*/rdf:first ?operation } )
29+
30+
bind( concat( ?aspectName, "Aspect" ) as ?aspectBoxName )
31+
bind( iri( concat( func:getNamespace( ?aspect ), ?aspectBoxName ) ) as ?from )
32+
bind( concat( ?operationName, "Operation" ) as ?operationBoxName )
33+
bind( iri( concat( func:getNamespace( ?operation ), ?operationBoxName ) ) as ?to )
34+
35+
bind( iri( concat( func:getNamespace( ?aspect ), ?aspectBoxName, "_To_", ?operationBoxName ) ) as ?edge )
36+
}

0 commit comments

Comments
 (0)