Skip to content

Commit b705d16

Browse files
authored
Merge branch 'main' into 481-samm-cli-aas-generation-mapping-of-set-characteristics
2 parents 15b9e5b + 08b6df0 commit b705d16

File tree

5 files changed

+33
-37
lines changed

5 files changed

+33
-37
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" );

core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/sql/databricks/AspectModelDatabricksDenormalizedSqlVisitor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ public String visitCollection( final Collection collection, final Context contex
257257
.getDescription( config.commentLanguage() ) )
258258
: Optional.empty();
259259
final String typeDef = type.isComplexType()
260-
? entityToStruct( type.as( ComplexType.class ) ).toString()
260+
? entityToStruct( type.as( ComplexType.class ), false ).toString()
261261
: type.accept( this, context );
262262
return column( context.prefix(), "ARRAY<" + typeDef + ">", property.isOptional() || context.forceOptional(),
263263
comment );
264264
}
265265

266-
private DatabricksType.DatabricksStruct entityToStruct( final ComplexType entity ) {
266+
private DatabricksType.DatabricksStruct entityToStruct( final ComplexType entity, final boolean isInsideNestedType ) {
267267
return new DatabricksType.DatabricksStruct( entity.getAllProperties().stream()
268268
.flatMap( property -> {
269269
if ( property.getDataType().isEmpty() || property.isNotInPayload() ) {
@@ -274,12 +274,15 @@ private DatabricksType.DatabricksStruct entityToStruct( final ComplexType entity
274274
if ( type instanceof final Scalar scalar ) {
275275
databricksType = databricksTypeMap.get( scalar.getUrn() );
276276
} else if ( type instanceof final Entity entityType ) {
277-
databricksType = entityToStruct( entityType );
277+
databricksType = entityToStruct( entityType, true );
278278
} else {
279279
return Stream.empty();
280280
}
281+
282+
boolean isOptional = isInsideNestedType || property.isOptional();
283+
281284
return Stream.of( new DatabricksType.DatabricksStructEntry( columnName( property ), databricksType,
282-
property.isOptional(), Optional.ofNullable( property.getDescription( config.commentLanguage() ) ) ) );
285+
isOptional, Optional.ofNullable( property.getDescription( config.commentLanguage() ) ) ) );
283286
} )
284287
.toList() );
285288
}

core/esmf-aspect-model-document-generators/src/test/java/org/eclipse/esmf/aspectmodel/generator/sql/databricks/AspectModelDatabricksDenormalizedSqlVisitorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.junit.jupiter.api.Test;
2525

2626
@SuppressWarnings( "checkstyle:LineLength" )
27-
public class AspectModelDatabricksDenormalizedSqlVisitorTest extends DatabricksTestBase {
27+
class AspectModelDatabricksDenormalizedSqlVisitorTest extends DatabricksTestBase {
2828
@Test
2929
void testAspectWithAbstractEntity() {
3030
assertThat( sql( TestAspect.ASPECT_WITH_ABSTRACT_ENTITY ) ).isEqualTo( """
@@ -319,7 +319,7 @@ CREATE TABLE IF NOT EXISTS aspect_with_multiple_entity_collections (
319319
void testAspectWithNestedEntityList() {
320320
assertThat( sql( TestAspect.ASPECT_WITH_NESTED_ENTITY_LIST ) ).isEqualTo( """
321321
CREATE TABLE IF NOT EXISTS aspect_with_nested_entity_list (
322-
test_list ARRAY<STRUCT<test_string: STRING NOT NULL, test_int: INT NOT NULL, test_float: FLOAT NOT NULL, test_second_list: STRUCT<test_local_date_time: TIMESTAMP NOT NULL, random_value: STRING NOT NULL> NOT NULL>> NOT NULL
322+
test_list ARRAY<STRUCT<test_string: STRING NOT NULL, test_int: INT NOT NULL, test_float: FLOAT NOT NULL, test_second_list: STRUCT<test_local_date_time: TIMESTAMP, random_value: STRING> NOT NULL>> NOT NULL
323323
)
324324
TBLPROPERTIES ('x-samm-aspect-model-urn'='urn:samm:org.eclipse.esmf.test:1.0.0#AspectWithNestedEntityList');
325325
""" );

documentation/developer-guide/modules/tooling-guide/pages/samm-cli.adoc

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@
44
= SAMM CLI
55

66
The SAMM CLI is a command line tool for the validation of Aspect Models and the generation of
7-
artifacts, such as documentation or code, from Aspect Models.
8-
9-
The SAMM CLI is available as a native executable for multiple platforms and as an executable jar:
10-
11-
[TIP]
12-
.Downloading samm-cli
13-
====
14-
* Download executable for Windows (latest): https://github.com/eclipse-esmf/esmf-sdk/releases/download/v{esmf-sdk-version}/samm-cli-{esmf-sdk-version}-windows-x86_64.zip[samm-cli-{esmf-sdk-version}-windows-x86_64.zip]
15-
* Download exectuable for Linux (latest): https://github.com/eclipse-esmf/esmf-sdk/releases/download/v{esmf-sdk-version}/samm-cli-{esmf-sdk-version}-linux-x86_64.tar.gz[samm-cli-{esmf-sdk-version}-linux-x86_64.tar.gz]
16-
* Download executable jar for other platforms and architectures (latest): https://github.com/eclipse-esmf/esmf-sdk/releases/download/v{esmf-sdk-version}/samm-cli-{esmf-sdk-version}.jar[samm-cli-{esmf-sdk-version}.jar]. Running this version requires Java 17.
17-
====
7+
artifacts, such as documentation or code, from Aspect Models. It is available as a native executable
8+
for multiple platforms (Windows, Linux and macOS) and as an executable JAR file. You can find the
9+
latest release [on GitHub](https://github.com/eclipse-esmf/esmf-sdk/releases/latest).
1810

1911
[[samm-cli-getting-started]]
2012
== Running the SAMM CLI

0 commit comments

Comments
 (0)