Skip to content

Commit 8cb4214

Browse files
committed
fixed issue with names collision during diagram generation
#310
1 parent fb2f6ad commit 8cb4214

File tree

37 files changed

+158
-84
lines changed

37 files changed

+158
-84
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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package io.openmanufacturing.sds.aspectmodel.generator.diagram;
2+
3+
import org.apache.jena.graph.Node;
4+
import org.apache.jena.rdf.model.Model;
5+
import org.apache.jena.sparql.expr.NodeValue;
6+
import org.apache.jena.sparql.function.Function;
7+
import org.apache.jena.sparql.function.FunctionBase1;
8+
import org.apache.jena.sparql.function.FunctionFactory;
9+
10+
import io.openmanufacturing.sds.aspectmodel.urn.AspectModelUrn;
11+
12+
/**
13+
* {@link FunctionFactory} for the {@link getNamespace} SPARQL function.
14+
*/
15+
public class GetNamespaceFunctionFactory implements FunctionFactory {
16+
17+
private final getNamespace getNamespace;
18+
19+
/**
20+
*/
21+
public GetNamespaceFunctionFactory( final Model context ) {
22+
this.getNamespace = new getNamespace( context.getNsPrefixURI( "" ) );
23+
}
24+
25+
@Override
26+
public Function create( String s ) {
27+
return getNamespace;
28+
}
29+
30+
/**
31+
* A custom SPARQL function which provides the namespace of a model element.
32+
*/
33+
public static class getNamespace extends FunctionBase1 {
34+
35+
private final String defaultNs;
36+
37+
public getNamespace( String defaultNs ) {
38+
this.defaultNs = defaultNs;
39+
}
40+
41+
@Override
42+
public NodeValue exec( NodeValue nodeValue ) {
43+
final Node node = nodeValue.asNode();
44+
if ( node.isBlank() || !node.isURI() ) {
45+
return NodeValue.makeNodeString( defaultNs );
46+
}
47+
final AspectModelUrn nodeUrn = AspectModelUrn.fromUrn( node.getURI() );
48+
return NodeValue.makeString( nodeUrn.getUrnPrefix() );
49+
}
50+
}
51+
}

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-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/collection2boxmodel.sparql

Lines changed: 2 additions & 1 deletion
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 boxes for Collection Characteristics
2122
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 .

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_1_0_0/entityinstance-entity-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 Entity Instances and Entities
2122
construct {
@@ -41,8 +42,8 @@ construct {
4142
bind( strafter( str( ?instance ), "#" ) as ?instanceName )
4243
bind( concat( ?instanceName, "EntityInstance" ) as ?instanceBoxName )
4344

44-
bind( iri( concat( str( : ), ?instanceBoxName ) ) as ?from )
45-
bind( iri( concat( str( : ), ?entityBoxName ) ) as ?to )
46-
bind( iri( concat( str( : ), ?instanceBoxName, "_To_", ?entityBoxName ) ) as ?edge )
45+
bind( iri( concat( func:getNamespace( ?instance ), ?instanceBoxName ) ) as ?from )
46+
bind( iri( concat( func:getNamespace( ?entity ), ?entityBoxName ) ) as ?to )
47+
bind( iri( concat( func:getNamespace( ?instance ), ?instanceBoxName, "_To_", ?entityBoxName ) ) as ?edge )
4748
bind( "is a" as ?title )
4849
}

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_1_0_0/entityinstance-nestedentityinstance-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 Entity Instances and nested Entity Instances
2122
construct {
@@ -56,9 +57,9 @@ construct {
5657
bind( strafter( str( ?listValue ), "#" ) as ?nestedInstanceName )
5758
}
5859

59-
bind( iri( concat( str( : ), ?instanceBoxName ) ) as ?from )
60+
bind( iri( concat( func:getNamespace( ?instance ), ?instanceBoxName ) ) as ?from )
6061
bind( concat( ?nestedInstanceName, "EntityInstance" ) as ?nestedInstanceBoxName )
61-
bind( iri( concat( str( : ), ?nestedInstanceBoxName ) ) as ?to )
62-
bind( iri( concat( str( : ), ?instanceBoxName, "_To_", ?nestedInstanceBoxName ) ) as ?edge )
62+
bind( iri( concat( func:getNamespace( if(!isBlank( ?propertyValue ), ?propertyValue, ?listValue )), ?nestedInstanceBoxName ) ) as ?to )
63+
bind( iri( concat( func:getNamespace( ?instance ), ?instanceBoxName, "_To_", ?nestedInstanceBoxName ) ) as ?edge )
6364
bind( concat( ?propertyName, " value" ) as ?title )
6465
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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 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 boxes for Meta Model Properties
1920
construct {
@@ -26,6 +27,6 @@ construct {
2627
filter( ?metaModelElement in ( samm:Property ) )
2728
?metaModelElement rdfs:label ?metaModelElementName .
2829
bind( concat( ?metaModelElementName, "MetaModelElement" ) as ?boxName )
29-
bind( iri( concat( str( : ), ?boxName ) ) as ?metaModelNodeBox )
30+
bind( iri( concat( func:getNamespace( ?metaModelElement ), ?boxName ) ) as ?metaModelNodeBox )
3031
}
3132

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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 unit: <urn:samm:org.eclipse.esmf.samm:unit:1.0.0#>
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 Units and QuantityKinds (quantityKind)
1920
construct {
@@ -31,10 +32,10 @@ construct {
3132
bind( concat( ucase( substr( ?quantityKindName, 1, 1 ) ), substr( ?quantityKindName, 2 ) ) as ?upperQuantityKindName )
3233

3334
bind( concat( ?upperUnitName, "Unit" ) as ?unitBoxName )
34-
bind( iri( concat( str( : ), ?unitBoxName ) ) as ?from )
35+
bind( iri( concat( func:getNamespace( ?unit ), ?unitBoxName ) ) as ?from )
3536
bind( replace( ?upperQuantityKindName, "-", "" ) as ?quantityKindBoxName )
36-
bind( iri( concat( str( : ), ?quantityKindBoxName ) ) as ?to )
37+
bind( iri( concat( func:getNamespace( ?quantityKind ), ?quantityKindBoxName ) ) as ?to )
3738

38-
bind( iri( concat( str( : ), ?unitBoxName, "_To_", ?quantityKindBoxName ) ) as ?edge )
39+
bind( iri( concat( func:getNamespace( ?unit ), ?unitBoxName, "_To_", ?quantityKindBoxName ) ) as ?edge )
3940
}
4041

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_2_0_0/abstractentity2boxmodel.sparql

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

1718
# Generates boxes for Abstract Entities
1819
construct {
@@ -42,7 +43,7 @@ construct {
4243
bind( strafter( str( ?abstractEntity ), "#" ) as ?abstractEntityName )
4344

4445
bind( concat( ?abstractEntityName, "AbstractEntity" ) as ?boxName )
45-
bind( iri( concat( str( : ), ?boxName ) ) as ?abstractEntityBox )
46+
bind( iri( concat( func:getNamespace( ?abstractEntity ), ?boxName ) ) as ?abstractEntityBox )
4647

4748
optional {
4849
?abstractEntity samm:preferredName ?preferredNameValue .

0 commit comments

Comments
 (0)