Skip to content

Commit 08b6df0

Browse files
authored
Merge pull request #653 from bci-oss/595-correctly-translate-idta-submodel-templates-to-samm
Update URN rules
2 parents 74c3d0f + a2b4e94 commit 08b6df0

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.net.URI;
2020
import java.util.ArrayDeque;
2121
import java.util.Arrays;
22+
import java.util.Collections;
2223
import java.util.HashMap;
2324
import java.util.List;
2425
import java.util.Locale;
@@ -172,28 +173,29 @@ public List<String> getSubmodelNames() {
172173
.collect( Collectors.toList() );
173174
}
174175

175-
protected String escapeUrnNamespacePart( final String namespacePart ) {
176-
if ( namespacePart.matches( AspectModelUrn.NAMESPACE_REGEX_PART ) ) {
177-
return namespacePart;
176+
private String iriToReversedHostNameNotation( final IRI iri ) {
177+
final URI uri;
178+
try {
179+
uri = URI.create( iri.toString().contains( "://" ) ? iri.toString() : "https://" + iri );
180+
} catch ( IllegalArgumentException e ) {
181+
throw new IllegalArgumentException( "Incorrect IRI: " + iri, e );
178182
}
179-
throw new AspectModelGenerationException( "Encountered URI with invalid namespace part: " + namespacePart );
180-
}
181183

182-
private <T> Collector<T, ArrayDeque<T>, ArrayDeque<T>> reverseOrder() {
183-
return Collector.of( ArrayDeque::new, ArrayDeque::addFirst, ( deque1, deque2 ) -> {
184-
deque2.addAll( deque1 );
185-
return deque2;
186-
} );
187-
}
184+
if ( uri.getHost() == null ) {
185+
throw new IllegalArgumentException( "URI doesn't contain host: " + uri );
186+
}
188187

189-
private String iriToReversedHostNameNotation( final IRI iri ) {
190-
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( "/" ) ) )
188+
final String[] hostParts = uri.getHost().split( "\\." );
189+
final List<String> hostPartsList = Arrays.asList( hostParts );
190+
Collections.reverse( hostPartsList );
191+
final String reversedHost = String.join( ".", hostPartsList );
192+
193+
final String[] pathParts = uri.getPath().split( "/" );
194+
final String path = Arrays.stream( pathParts )
194195
.filter( StringUtils::isNotBlank )
195-
.map( this::escapeUrnNamespacePart )
196196
.collect( Collectors.joining( "." ) );
197+
198+
return reversedHost + ( path.isEmpty() ? "" : "." + path );
197199
}
198200

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

core/esmf-aspect-model-aas-generator/src/test/java/org/eclipse/esmf/aspectmodel/aas/AasToAspectModelGeneratorTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@
3636
import org.junit.jupiter.params.ParameterizedTest;
3737
import org.junit.jupiter.params.provider.EnumSource;
3838

39-
public class AasToAspectModelGeneratorTest {
39+
class AasToAspectModelGeneratorTest {
4040

41-
// IDTA-provided sample files can currently not be read with AAS4J
4241
@Test
43-
@Disabled
42+
@Disabled( "IDTA-provided sample files can currently not be read with AAS4J" )
4443
void testTranslateDigitalNameplate() {
4544
final InputStream aasx = AasToAspectModelGeneratorTest.class.getClassLoader()
4645
.getResourceAsStream( "Sample_ZVEI_Digital_Nameplate_V10.aasx" );

0 commit comments

Comments
 (0)