Skip to content

Commit 700e45d

Browse files
authored
Merge pull request #326 from bci-oss/bug/310-diagram-name-collision
Fix for names collision during diagram generation
2 parents 091715c + a32d709 commit 700e45d

File tree

85 files changed

+451
-327
lines changed

Some content is hidden

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

85 files changed

+451
-327
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public String getArtifactFilename( final String aspectName, final Locale languag
7878
private static final String FONT_FILE = "diagram/RobotoCondensed-Regular.ttf";
7979

8080
static final String GET_ELEMENT_NAME_FUNC = "urn:samm:org.eclipse.esmf.samm:function:2.0.0#getElementName";
81+
static final String GET_NAMESPACE_FUNC = "urn:samm:org.eclipse.esmf.samm:function:2.0.0#getNamespace";
8182

8283
private final Query boxmodelToDotQuery;
8384
private final BoxModel boxModelNamespace;
@@ -143,7 +144,10 @@ ImmutableList.<String> builder().addAll( queryFilesForAllMetaModelVersions )
143144
boxmodelToDotQuery = QueryFactory.create( getInputStreamAsString( "boxmodel2dot.sparql" ) );
144145
boxModelNamespace = new BoxModel( metaModelVersion );
145146

146-
sparqlExecutor = new SparqlExecutor().useCustomFunction( GET_ELEMENT_NAME_FUNC, new GetElementNameFunctionFactory( model ) );
147+
sparqlExecutor = new SparqlExecutor()
148+
.useCustomFunction( GET_ELEMENT_NAME_FUNC, new GetElementNameFunctionFactory( model ) )
149+
.useCustomFunction( GET_NAMESPACE_FUNC, new GetNamespaceFunctionFactory( model ) )
150+
;
147151
}
148152

149153
InputStream getInputStream( final String resource ) {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2023 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 org.eclipse.esmf.aspectmodel.generator.diagram;
15+
16+
import org.apache.jena.graph.Node;
17+
import org.apache.jena.rdf.model.Model;
18+
import org.apache.jena.sparql.expr.NodeValue;
19+
import org.apache.jena.sparql.function.Function;
20+
import org.apache.jena.sparql.function.FunctionBase1;
21+
import org.apache.jena.sparql.function.FunctionFactory;
22+
import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;
23+
24+
/**
25+
* {@link FunctionFactory} for the {@link getNamespace} SPARQL function.
26+
*/
27+
public class GetNamespaceFunctionFactory implements FunctionFactory {
28+
29+
private final getNamespace getNamespace;
30+
31+
/**
32+
*/
33+
public GetNamespaceFunctionFactory( final Model context ) {
34+
this.getNamespace = new getNamespace( context.getNsPrefixURI( "" ) );
35+
}
36+
37+
@Override
38+
public Function create( String s ) {
39+
return getNamespace;
40+
}
41+
42+
/**
43+
* A custom SPARQL function which provides the namespace of a model element.
44+
*/
45+
private static class getNamespace extends FunctionBase1 {
46+
47+
private final String defaultNs;
48+
49+
public getNamespace( String defaultNs ) {
50+
this.defaultNs = defaultNs;
51+
}
52+
53+
@Override
54+
public NodeValue exec( NodeValue nodeValue ) {
55+
final Node node = nodeValue.asNode();
56+
if ( node.isBlank() || !node.isURI() ) {
57+
return NodeValue.makeNodeString( defaultNs );
58+
}
59+
final AspectModelUrn nodeUrn = AspectModelUrn.fromUrn( node.getURI() );
60+
return NodeValue.makeString( nodeUrn.getUrnPrefix() );
61+
}
62+
}
63+
}

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_1_0_0/aspect-operation-edges2boxmodel.sparql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0#>
1313
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
1414
prefix : <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0/boxmodel#>
15+
prefix func: <urn:samm:org.eclipse.esmf.samm:function:2.0.0#>
1516

1617
# Generate edges between Aspects and Operations
1718
construct {
@@ -27,9 +28,9 @@ construct {
2728
filter( exists { ?aspect samm:operations/rdf:rest*/rdf:first ?operation } )
2829

2930
bind( concat( ?aspectName, "Aspect" ) as ?aspectBoxName )
30-
bind( iri( concat( str( : ), ?aspectBoxName ) ) as ?from )
31+
bind( iri( concat( func:getNamespace( ?aspect ), ?aspectBoxName ) ) as ?from )
3132
bind( concat( ?operationName, "Operation" ) as ?operationBoxName )
32-
bind( iri( concat( str( : ), ?operationBoxName ) ) as ?to )
33+
bind( iri( concat( func:getNamespace( ?operation ), ?operationBoxName ) ) as ?to )
3334

34-
bind( iri( concat( str( : ), ?aspectBoxName, "_To_", ?operationBoxName ) ) as ?edge )
35+
bind( iri( concat( func:getNamespace( ?aspect ), ?aspectBoxName, "_To_", ?operationBoxName ) ) as ?edge )
3536
}

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_1_0_0/aspect-property-edges2boxmodel.sparql

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ prefix samm-e: <urn:samm:org.eclipse.esmf.samm:entity:1.0.0#>
1414
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
1515
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
1616
prefix : <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0/boxmodel#>
17+
prefix func: <urn:samm:org.eclipse.esmf.samm:function:2.0.0#>
1718

1819
# Generates edges between Aspects or Entites and Properties
1920
construct {
@@ -38,12 +39,12 @@ construct {
3839

3940
bind( if( ?class = samm:Aspect, "Aspect", "Entity" ) as ?typeName )
4041
bind( concat( ?aspectOrEntityName, ?typeName ) as ?aspectOrEntityBoxName )
41-
bind( iri( concat( str( : ), ?aspectOrEntityBoxName ) ) as ?from )
42+
bind( iri( concat( func:getNamespace( ?aspectOrEntity ), ?aspectOrEntityBoxName ) ) as ?from )
4243

4344
bind( concat( ?propertyName, "Property" ) as ?propertyBoxName )
44-
bind( iri( concat( str( : ), ?propertyBoxName ) ) as ?to )
45+
bind( iri( concat( func:getNamespace( ?property ), ?propertyBoxName ) ) as ?to )
4546

46-
bind( iri( concat( str( : ), ?aspectOrEntityBoxName, "_To_", ?propertyBoxName ) ) as ?edge )
47+
bind( iri( concat( func:getNamespace( ?aspectOrEntity ), ?aspectOrEntityBoxName, "_To_", ?propertyBoxName ) ) as ?edge )
4748

4849
optional {
4950
?aspectOrEntity samm:properties/rdf:rest*/rdf:first ?propertyNode .
@@ -75,8 +76,8 @@ construct {
7576
}
7677

7778
optional {
78-
?aspectOrEntity samm:properties/rdf:rest*/rdf:first ?propertyNode .
79-
bind( "property" as ?title )
79+
?aspectOrEntity samm:properties/rdf:rest*/rdf:first ?propertyNode .
80+
bind( "property" as ?title )
8081
}
8182
}
8283

@@ -94,12 +95,12 @@ construct {
9495
?refiningEntity samm:name ?entityName .
9596
?property samm:name ?propertyName .
9697
bind( concat( ?entityName, "Entity" ) as ?entityBoxName )
97-
bind( iri( concat( str( : ), ?entityBoxName ) ) as ?from )
98+
bind( iri( concat( func:getNamespace( ?refiningEntity ), ?entityBoxName ) ) as ?from )
9899

99100
bind( concat( ?propertyName, "Property" ) as ?propertyBoxName )
100-
bind( iri( concat( str( : ), ?propertyBoxName ) ) as ?to )
101+
bind( iri( concat( func:getNamespace( ?property ), ?propertyBoxName ) ) as ?to )
101102

102-
bind( iri( concat( str( : ), ?entityBoxName, "_To_", ?propertyBoxName ) ) as ?edge )
103+
bind( iri( concat( func:getNamespace( ?refiningEntity ), ?entityBoxName, "_To_", ?propertyBoxName ) ) as ?edge )
103104

104105
optional {
105106
?aspectOrEntity samm:properties/rdf:rest*/rdf:first ?propertyNode .
@@ -131,8 +132,8 @@ construct {
131132
}
132133

133134
optional {
134-
?aspectOrEntity samm:properties/rdf:rest*/rdf:first ?propertyNode .
135-
bind( "property" as ?title )
135+
?aspectOrEntity samm:properties/rdf:rest*/rdf:first ?propertyNode .
136+
bind( "property" as ?title )
136137
}
137138
}
138139
}

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_1_0_0/aspect2boxmodel.sparql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0#>
1313
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
1414
prefix : <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0/boxmodel#>
15+
prefix func: <urn:samm:org.eclipse.esmf.samm:function:2.0.0#>
1516

1617
# Generates boxes for Aspects
1718
construct {
@@ -40,7 +41,7 @@ construct {
4041
?aspect samm:name ?aspectName .
4142

4243
bind( concat( ?aspectName, "Aspect" ) as ?boxName )
43-
bind( iri( concat( str( : ), ?boxName ) ) as ?aspectBox )
44+
bind( iri( concat( func:getNamespace( ?aspect ), ?boxName ) ) as ?aspectBox )
4445

4546
optional {
4647
?aspect samm:preferredName ?preferredNameValue .

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_1_0_0/characteristic-characteristic-edges2boxmodel.sparql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0#>
1313
prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:1.0.0#>
1414
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
1515
prefix : <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0/boxmodel#>
16+
prefix func: <urn:samm:org.eclipse.esmf.samm:function:2.0.0#>
1617

1718
# Generates edges between Trait and other Characteristics (baseCharacteristic)
1819
construct {
@@ -25,11 +26,11 @@ construct {
2526
?characteristic samm-c:baseCharacteristic ?baseCharacteristic .
2627
?baseCharacteristic samm:name ?baseCharacteristicName .
2728
bind( concat( ?characteristicName, "Characteristic" ) as ?box1Name )
28-
bind( iri( concat( str( : ), ?box1Name ) ) as ?from )
29+
bind( iri( concat( func:getNamespace( ?characteristic ), ?box1Name ) ) as ?from )
2930

3031
bind( concat( ?baseCharacteristicName, "Characteristic" ) as ?box2Name )
31-
bind( iri( concat( str( : ), ?box2Name ) ) as ?to )
32+
bind( iri( concat( func:getNamespace( ?baseCharacteristic ), ?box2Name ) ) as ?to )
3233

33-
bind( iri( concat( str( : ), ?box1Name, "_To_", ?box2Name ) ) as ?edge )
34+
bind( iri( concat( func:getNamespace( ?characteristic ), ?box1Name, "_To_", ?box2Name ) ) as ?edge )
3435
}
3536

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_1_0_0/characteristic-constraint-edges2boxmodel.sparql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
1616
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
1717
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
1818
prefix : <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0/boxmodel#>
19+
prefix func: <urn:samm:org.eclipse.esmf.samm:function:2.0.0#>
1920

2021
# Generates edges between Trait and Constraints (constraint)
2122
construct {
@@ -28,7 +29,7 @@ construct {
2829
?characteristic samm:name ?characteristicName .
2930

3031
bind( concat( ?characteristicName, "Characteristic" ) as ?characteristicBoxName )
31-
bind( iri( concat( str( : ), ?characteristicBoxName ) ) as ?from )
32+
bind( iri( concat( func:getNamespace( ?characteristic ), ?characteristicBoxName ) ) as ?from )
3233

3334
optional {
3435
?constraint samm:name ?givenConstraintName .
@@ -59,8 +60,8 @@ construct {
5960
bind( coalesce( concat( ?givenConstraintName, "Constraint" ),
6061
concat( "Constraint", substr( md5( ?constraintPropertyValues ), 0, 11 ) ) ) as ?constraintBoxName )
6162

62-
bind( iri( concat( str( : ), ?constraintBoxName ) ) as ?to )
63+
bind( iri( concat( func:getNamespace( ?constraint ), ?constraintBoxName ) ) as ?to )
6364

64-
bind( iri( concat( str( : ), ?characteristicBoxName, "_To_", ?constraintBoxName ) ) as ?edge )
65+
bind( iri( concat( func:getNamespace( ?characteristic ), ?characteristicBoxName, "_To_", ?constraintBoxName ) ) as ?edge )
6566
}
6667

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_1_0_0/characteristic-entity-edges2boxmodel.sparql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ prefix samm-e: <urn:samm:org.eclipse.esmf.samm:entity:1.0.0#>
1414
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
1515
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
1616
prefix : <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0/boxmodel#>
17+
prefix func: <urn:samm:org.eclipse.esmf.samm:function:2.0.0#>
1718

1819
# Generates edges between Characteristic and Entities (dataType)
1920
construct {
@@ -29,11 +30,11 @@ construct {
2930
?characteristic samm:name ?characteristicName .
3031
?entity samm:name ?entityName .
3132
bind( concat( ?characteristicName, "Characteristic" ) as ?characteristicBoxName )
32-
bind( iri( concat( str( : ), ?characteristicBoxName ) ) as ?from )
33+
bind( iri( concat( func:getNamespace( ?characteristic ), ?characteristicBoxName ) ) as ?from )
3334

3435
bind( concat( ?entityName, "Entity" ) as ?entityBoxName )
35-
bind( iri( concat( str( : ), ?entityBoxName ) ) as ?to )
36+
bind( iri( concat( func:getNamespace( ?characteristic ), ?entityBoxName ) ) as ?to )
3637

37-
bind( iri( concat( str( : ), ?characteristicBoxName, "_To_", ?entityBoxName ) ) as ?edge )
38+
bind( iri( concat( func:getNamespace( ?characteristic ), ?characteristicBoxName, "_To_", ?entityBoxName ) ) as ?edge )
3839
}
3940

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_1_0_0/characteristic-metamodelnode-edges2boxmodel.sparql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0#>
1313
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
1414
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
1515
prefix : <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0/boxmodel#>
16+
prefix func: <urn:samm:org.eclipse.esmf.samm:function:2.0.0#>
1617

1718
# Generates edges between Characteristic and Meta Model Properties (dataType)
1819
construct {
@@ -27,10 +28,10 @@ construct {
2728
?metaModelElement rdfs:label ?metaModelElementName .
2829

2930
bind( concat( ?characteristicName, "Characteristic" ) as ?characteristicBoxName )
30-
bind( iri( concat( str( : ), ?characteristicBoxName ) ) as ?from )
31+
bind( iri( concat( func:getNamespace( ?characteristic ), ?characteristicBoxName ) ) as ?from )
3132
bind( concat( ?metaModelElementName, "MetaModelElement" ) as ?metaModelElementBoxName )
32-
bind( iri( concat( str( : ), ?metaModelElementBoxName ) ) as ?to )
33+
bind( iri( concat( func:getNamespace( ?metaModelElement ), ?metaModelElementBoxName ) ) as ?to )
3334

34-
bind( iri( concat( str( : ), ?characteristicBoxName, "_To_", ?metaModelElementBoxName ) ) as ?edge )
35+
bind( iri( concat( func:getNamespace( ?characteristic ), ?characteristicBoxName, "_To_", ?metaModelElementBoxName ) ) as ?edge )
3536
}
3637

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_1_0_0/characteristic2boxmodel.sparql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
1515
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
1616
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
1717
prefix : <urn:samm:org.eclipse.esmf.samm:meta-model:1.0.0/boxmodel#>
18+
prefix func: <urn:samm:org.eclipse.esmf.samm:function:2.0.0#>
1819

1920
# Generates boxes for Characteristics that are not Collections, Constraints, Enumeration/State or StructuredValue
2021
construct {
@@ -67,7 +68,7 @@ construct {
6768

6869
?characteristic samm:name ?characteristicName .
6970
bind( concat( ?characteristicName, "Characteristic" ) as ?boxName )
70-
bind( iri( concat( str( : ), ?boxName ) ) as ?characteristicBox )
71+
bind( iri( concat( func:getNamespace( ?characteristic ), ?boxName ) ) as ?characteristicBox )
7172

7273
optional {
7374
?characteristic samm:preferredName ?preferredNameValue .

0 commit comments

Comments
 (0)