Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predict invalid space in see reference #660

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -27,7 +26,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

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

return reversedHost + ( path.isEmpty() ? "" : "." + path );
return reversedHost + (path.isEmpty() ? "" : "." + path);
}

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

private String sanitizeValue( final String value ) {
return value.replace( "/ ", "/" );
}

private List<String> seeReferences( final Submodel submodel ) {
return validIrdiOrUri( submodel.getId() ).stream().toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.function.Consumer;

Expand All @@ -31,22 +32,37 @@
import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonDeserializer;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.xml.XmlDeserializer;
import org.eclipse.digitaltwin.aas4j.v3.model.Environment;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

class AasToAspectModelGeneratorTest {

@Test
@Disabled( "IDTA-provided sample files can currently not be read with AAS4J" )
void testTranslateDigitalNameplate() {
final InputStream aasx = AasToAspectModelGeneratorTest.class.getClassLoader()
.getResourceAsStream( "Sample_ZVEI_Digital_Nameplate_V10.aasx" );
.getResourceAsStream( "idta/Sample_ZVEI_Digital_Nameplate_V10.aasx" );
final AasToAspectModelGenerator aspectModelGenerator = AasToAspectModelGenerator.fromAasx( aasx );
assertThatCode( aspectModelGenerator::generateAspects ).doesNotThrowAnyException();
}

@Test
void testSeeReferences() {
final InputStream inputStream = AasToAspectModelGeneratorTest.class.getClassLoader().getResourceAsStream(
"idta/IDTA 02022-1-0_Template_Wireless Communication.aasx" );
final AasToAspectModelGenerator aspectModelGenerator = AasToAspectModelGenerator.fromAasx( inputStream );
final List<Aspect> aspects = aspectModelGenerator.generateAspects();

assertThatCode( aspectModelGenerator::generateAspects ).doesNotThrowAnyException();
Yauhenikapl marked this conversation as resolved.
Show resolved Hide resolved

aspects.stream()
.flatMap( aspect -> aspect.getProperties().stream() )
.flatMap( property -> property.getSee().stream() )
.forEach( see -> {
assertThat( see ).doesNotContain( "/ " );
} );
}

@ParameterizedTest
@EnumSource( TestAspect.class )
void testRoundtripConversion( final TestAspect testAspect ) throws DeserializationException {
Expand Down Expand Up @@ -134,4 +150,15 @@ private Environment loadEnvironment( final String name ) {
}
return null;
}

private InputStream getIdtaModel( final String path ) {
try {
final URL url = new URL(
"https://github.com/admin-shell-io/submodel-templates/raw/refs/heads/main/published/" + path.replaceAll( " ", "%20" ) );
return url.openStream();
} catch ( Exception e ) {
e.printStackTrace();
return null;
}
}
}
Binary file not shown.
Binary file not shown.
Loading