Skip to content

Commit 365f7c0

Browse files
authored
Merge pull request #660 from bci-oss/bugfix/595-check-see-atrribute-while-converting-ass-model
Predict invalid space in see reference
2 parents 5de6c1b + 73c6719 commit 365f7c0

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.io.IOException;
1818
import java.io.InputStream;
1919
import java.net.URI;
20-
import java.util.ArrayDeque;
2120
import java.util.Arrays;
2221
import java.util.Collections;
2322
import java.util.HashMap;
@@ -27,7 +26,6 @@
2726
import java.util.Optional;
2827
import java.util.Set;
2928
import java.util.function.Function;
30-
import java.util.stream.Collector;
3129
import java.util.stream.Collectors;
3230
import java.util.stream.Stream;
3331

@@ -195,7 +193,7 @@ private String iriToReversedHostNameNotation( final IRI iri ) {
195193
.filter( StringUtils::isNotBlank )
196194
.collect( Collectors.joining( "." ) );
197195

198-
return reversedHost + ( path.isEmpty() ? "" : "." + path );
196+
return reversedHost + (path.isEmpty() ? "" : "." + path);
199197
}
200198

201199
private Optional<IRI> iri( final String lexicalRepresentation ) {
@@ -361,9 +359,14 @@ private List<String> seeReferences( final SubmodelElement element ) {
361359
.filter( key -> key.getType() == KeyTypes.CONCEPT_DESCRIPTION || key.getType() == KeyTypes.GLOBAL_REFERENCE )
362360
.map( Key::getValue )
363361
.flatMap( value -> validIrdiOrUri( value ).stream() )
362+
.map( this::sanitizeValue )
364363
.toList();
365364
}
366365

366+
private String sanitizeValue( final String value ) {
367+
return value.replace( "/ ", "/" );
368+
}
369+
367370
private List<String> seeReferences( final Submodel submodel ) {
368371
return validIrdiOrUri( submodel.getId() ).stream().toList();
369372
}

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.ByteArrayInputStream;
2121
import java.io.IOException;
2222
import java.io.InputStream;
23+
import java.net.URL;
2324
import java.util.List;
2425
import java.util.function.Consumer;
2526

@@ -31,22 +32,37 @@
3132
import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonDeserializer;
3233
import org.eclipse.digitaltwin.aas4j.v3.dataformat.xml.XmlDeserializer;
3334
import org.eclipse.digitaltwin.aas4j.v3.model.Environment;
34-
import org.junit.jupiter.api.Disabled;
3535
import org.junit.jupiter.api.Test;
3636
import org.junit.jupiter.params.ParameterizedTest;
3737
import org.junit.jupiter.params.provider.EnumSource;
3838

3939
class AasToAspectModelGeneratorTest {
4040

4141
@Test
42-
@Disabled( "IDTA-provided sample files can currently not be read with AAS4J" )
4342
void testTranslateDigitalNameplate() {
4443
final InputStream aasx = AasToAspectModelGeneratorTest.class.getClassLoader()
45-
.getResourceAsStream( "Sample_ZVEI_Digital_Nameplate_V10.aasx" );
44+
.getResourceAsStream( "idta/Sample_ZVEI_Digital_Nameplate_V10.aasx" );
4645
final AasToAspectModelGenerator aspectModelGenerator = AasToAspectModelGenerator.fromAasx( aasx );
4746
assertThatCode( aspectModelGenerator::generateAspects ).doesNotThrowAnyException();
4847
}
4948

49+
@Test
50+
void testSeeReferences() {
51+
final InputStream inputStream = AasToAspectModelGeneratorTest.class.getClassLoader().getResourceAsStream(
52+
"idta/IDTA 02022-1-0_Template_Wireless Communication.aasx" );
53+
final AasToAspectModelGenerator aspectModelGenerator = AasToAspectModelGenerator.fromAasx( inputStream );
54+
final List<Aspect> aspects = aspectModelGenerator.generateAspects();
55+
56+
assertThatCode( aspectModelGenerator::generateAspects ).doesNotThrowAnyException();
57+
58+
aspects.stream()
59+
.flatMap( aspect -> aspect.getProperties().stream() )
60+
.flatMap( property -> property.getSee().stream() )
61+
.forEach( see -> {
62+
assertThat( see ).doesNotContain( "/ " );
63+
} );
64+
}
65+
5066
@ParameterizedTest
5167
@EnumSource( TestAspect.class )
5268
void testRoundtripConversion( final TestAspect testAspect ) throws DeserializationException {
@@ -134,4 +150,15 @@ private Environment loadEnvironment( final String name ) {
134150
}
135151
return null;
136152
}
153+
154+
private InputStream getIdtaModel( final String path ) {
155+
try {
156+
final URL url = new URL(
157+
"https://github.com/admin-shell-io/submodel-templates/raw/refs/heads/main/published/" + path.replaceAll( " ", "%20" ) );
158+
return url.openStream();
159+
} catch ( Exception e ) {
160+
e.printStackTrace();
161+
return null;
162+
}
163+
}
137164
}
9.11 KB
Binary file not shown.
7.66 KB
Binary file not shown.

0 commit comments

Comments
 (0)