Skip to content

Commit da23fe5

Browse files
committed
Update URN rules
1 parent 10a1f4d commit da23fe5

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

core/esmf-aspect-model-aas-generator/src/main/java/org/eclipse/esmf/aspectmodel/aas/AasToAspectModelGenerator.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ public List<String> getSubmodelNames() {
172172
.collect( Collectors.toList() );
173173
}
174174

175-
protected String escapeUrnNamespacePart( final String namespacePart ) {
175+
protected String escapeUrnNamespacePart( String namespacePart ) {
176+
if ( namespacePart.contains( "-" ) ) {
177+
namespacePart = namespacePart.replaceAll( "-", "." );
178+
return namespacePart;
179+
}
176180
if ( namespacePart.matches( AspectModelUrn.NAMESPACE_REGEX_PART ) ) {
177181
return namespacePart;
178182
}
@@ -186,14 +190,34 @@ private <T> Collector<T, ArrayDeque<T>, ArrayDeque<T>> reverseOrder() {
186190
} );
187191
}
188192

193+
// private String iriToReversedHostNameNotation( final IRI iri ) {
194+
// final URI uri = URI.create( iri.toString().contains( "://" ) ? iri.toString() : "https://" + iri );
195+
// return Stream.concat(
196+
// Arrays.stream( uri.getHost().split( "\\." ) ).collect( reverseOrder() ).stream(),
197+
// Arrays.stream( uri.getPath().split( "/" ) ) )
198+
// .filter( StringUtils::isNotBlank )
199+
// .map( this::escapeUrnNamespacePart )
200+
// .collect( Collectors.joining( "." ) );
201+
// }
202+
189203
private String iriToReversedHostNameNotation( final IRI iri ) {
190204
final URI uri = URI.create( iri.toString().contains( "://" ) ? iri.toString() : "https://" + iri );
191-
return Stream.concat(
192-
Arrays.stream( uri.getHost().split( "\\." ) ).collect( reverseOrder() ).stream(),
193-
Arrays.stream( uri.getPath().split( "/" ) ) )
205+
206+
String[] hostParts = uri.getHost().split( "\\." );
207+
String[] pathParts = uri.getPath().split( "/" );
208+
209+
String reversedHost = Arrays.stream( hostParts )
210+
.collect( reverseOrder() )
211+
.stream()
212+
.map( part -> part.replaceAll( "-", "." ) )
213+
.collect( Collectors.joining( "." ) );
214+
215+
String path = Arrays.stream( pathParts )
194216
.filter( StringUtils::isNotBlank )
195-
.map( this::escapeUrnNamespacePart )
217+
.limit( pathParts.length - 2 )
196218
.collect( Collectors.joining( "." ) );
219+
220+
return reversedHost + "." + path;
197221
}
198222

199223
private Optional<IRI> iri( final String lexicalRepresentation ) {

core/esmf-aspect-model-urn/src/test/java/org/eclipse/esmf/aspectmodel/urn/AspectModelUrnTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,17 @@ void validNamespaceTest() throws URISyntaxException {
342342
assertThat( elementUrnWithDash.getNamespaceMainPart() ).isNotEmpty();
343343
assertThat( elementUrnWithDash.getNamespaceMainPart() ).isEqualTo( "org.eclipse.esmf-test" );
344344
}
345+
346+
@Test
347+
void invalidNamespaceTest() throws URISyntaxException {
348+
final URI validNamespaceUrnUnderscore = new URI( "urn:samm:com.bosch.nexeed.digitaltwin:aspect-model:Er?ors:1.1.0#TestAspect" );
349+
final AspectModelUrn elementUrnWithUnderscore = AspectModelUrn.fromUrn( validNamespaceUrnUnderscore );
350+
assertThat( elementUrnWithUnderscore.getNamespaceMainPart() ).isNotEmpty();
351+
assertThat( elementUrnWithUnderscore.getNamespaceMainPart() ).isEqualTo( "org.eclipse.esmf_test" );
352+
353+
final URI invalidNamespaceUrnDash = new URI( "urn:samm:org.eclipse.esmf-test:0.0.1#TestAspect" );
354+
final AspectModelUrn elementUrnWithDash = AspectModelUrn.fromUrn( invalidNamespaceUrnDash );
355+
assertThat( elementUrnWithDash.getNamespaceMainPart() ).isNotEmpty();
356+
assertThat( elementUrnWithDash.getNamespaceMainPart() ).isEqualTo( "org.eclipse.esmf-test" );
357+
}
345358
}

0 commit comments

Comments
 (0)