Skip to content

Commit 585edf0

Browse files
committed
Update AAS.xsd to AASv3.0 in test code and some code adjustments to comply to new AAS.xsd version
Signed-off-by: Johannes Kristan <[email protected]>
1 parent b219b53 commit 585edf0

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

core/sds-aspect-model-aas-generator/src/main/java/io/openmanufacturing/sds/aspectmodel/aas/AspectModelAASVisitor.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,17 @@ private Optional<SubmodelElement> mapText( final Property property, final Contex
248248
// property will be excluded from generation.
249249
recursiveProperty.remove( property );
250250
if ( property.isOptional() ) {
251-
LOG.warn( String.format( "Having a recursive Property %s which is optional. Will be excluded from AAS mapping.", property ) );
251+
LOG.warn( String.format( "Having a recursive property %s which is optional. Will be excluded from AAS mapping.", property ) );
252252
} else {
253-
LOG.error( String.format( "Having a recursive Property: %s which is not optional is not valid. Check the model. Property will be excluded from AAS mapping.", property ) );
253+
LOG.error( String.format( "Having a recursive property: %s which is not optional is not valid. Check the model. Property will be excluded from AAS mapping.", property ) );
254+
LOG.error( String.format( "Having a recursive property: %s which is not optional is not valid. Check the model. Property will be excluded from AAS mapping.", property ) );
254255
}
255256
return defaultResultForProperty;
256257
}
257258
recursiveProperty.add( property );
258259

259260
if ( property.getCharacteristic().isEmpty() || property.isAbstract() ) {
260-
LOG.warn( String.format( "Having an Abstract Property. Will be excluded from AAS mapping." ) );
261+
LOG.warn( "Having an abstract property. Will be excluded from AAS mapping." );
261262
return Optional.empty();
262263
}
263264

@@ -278,7 +279,7 @@ private SubmodelElement decideOnMapping( final Property property, final Context
278279
return new DefaultProperty.Builder().build();
279280
}
280281

281-
final Type type = property.getCharacteristic().get().getDataType().get();
282+
final Type type = property.getCharacteristic().get().getDataType().orElseThrow();
282283
return decideOnMapping( type, property, context );
283284
}
284285

@@ -341,7 +342,7 @@ private Operation mapText(
341342
}
342343

343344
private OperationVariable mapOperationVariable( final Property property, final Context context ) {
344-
return new DefaultOperationVariable.Builder().value( mapText( property, context ).get() ).build();
345+
return new DefaultOperationVariable.Builder().value( mapText( property, context ).orElseThrow() ).build();
345346
}
346347

347348
private List<LangStringTextType> mapText( final Set<io.openmanufacturing.sds.metamodel.datatypes.LangString> localizedStrings ) {
@@ -500,20 +501,29 @@ private DataSpecificationIec61360 extractDataSpecificationContent( final Propert
500501
.map( this::mapDefinitionIec61360 )
501502
.collect( Collectors.toList() );
502503

504+
final List<LangStringPreferredNameTypeIec61360> preferredNames = property.getPreferredNames().size() > 0 ?
505+
property.getPreferredNames().stream().map( this::mapLangStringPreferredNameTypeIec61360 ).collect( Collectors.toList()) :
506+
Collections.singletonList(createLangStringPreferredNameTypeIec61360(DEFAULT_LOCALE, property.getName()));
507+
503508
return new DefaultDataSpecificationIec61360.Builder()
504509
.definition( definitions )
505-
.preferredName( property.getPreferredNames().stream().map( this::mapLangStringPreferredNameTypeIec61360 ).collect( Collectors.toList()) )
506-
.shortName( createLangStringShortNameTypeIec61360( property.getName(), DEFAULT_LOCALE ) )
510+
.preferredName( preferredNames )
511+
.shortName( createLangStringShortNameTypeIec61360( DEFAULT_LOCALE, property.getName() ) )
507512
.dataType( mapIEC61360DataType( property.getCharacteristic() ) )
508513
.build();
509514
}
510515

511516

512517
private DataSpecificationIec61360 extractDataSpecificationContent( final Aspect aspect ) {
513-
return new DefaultDataSpecificationIec61360.Builder()
514-
.definition( aspect.getDescriptions().stream().map( this::mapDefinitionIec61360 ).collect( Collectors.toList()) )
515-
.preferredName( aspect.getPreferredNames().stream().map( this::mapLangStringPreferredNameTypeIec61360 ).collect( Collectors.toList()) )
516-
.build();
518+
List<LangStringPreferredNameTypeIec61360> preferredNames = aspect.getPreferredNames().size() > 0 ?
519+
aspect.getPreferredNames().stream().map( this::mapLangStringPreferredNameTypeIec61360 ).collect( Collectors.toList()) :
520+
Collections.singletonList(createLangStringPreferredNameTypeIec61360(DEFAULT_LOCALE, aspect.getName()));
521+
522+
return new DefaultDataSpecificationIec61360.Builder()
523+
.definition( aspect.getDescriptions().stream().map( this::mapDefinitionIec61360 ).collect( Collectors.toList()) )
524+
.preferredName( preferredNames )
525+
.build();
526+
517527
}
518528

519529
private DataTypeIec61360 mapIEC61360DataType( final Optional<Characteristic> characteristic ) {
@@ -571,7 +581,7 @@ public Environment visitList(
571581
( property ) ->
572582
new DefaultSubmodelElementList.Builder()
573583
.idShort( ID_PREFIX + property.getName() )
574-
.typeValueListElement( AASSubmodelElements.DATA_ELEMENT ) // TODO check if more specific type info is required
584+
.typeValueListElement( AASSubmodelElements.DATA_ELEMENT )
575585
.displayName( mapName( property.getPreferredNames() ) )
576586
.description( mapText( property.getDescriptions() ) )
577587
.value( Collections.singletonList( decideOnMapping( property, context ) ) )

core/sds-aspect-model-aas-generator/src/test/java/io/openmanufacturing/sds/aspectmodel/aas/AspectModelAASGeneratorTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.io.ByteArrayInputStream;
1919
import java.io.ByteArrayOutputStream;
20-
import java.io.File;
2120
import java.io.IOException;
2221
import java.net.URL;
2322
import java.nio.charset.StandardCharsets;
@@ -26,7 +25,6 @@
2625
import java.util.stream.Collectors;
2726

2827
import javax.xml.XMLConstants;
29-
import javax.xml.transform.Source;
3028
import javax.xml.transform.stream.StreamSource;
3129
import javax.xml.validation.Schema;
3230
import javax.xml.validation.SchemaFactory;
@@ -59,7 +57,8 @@
5957
class AspectModelAASGeneratorTest {
6058

6159
public static final String XML_XSD_AAS_SCHEMA_LOCATION =
62-
"https://raw.githubusercontent.com/admin-shell-io/aas-specs/v3.0.6/schemas/xml/AAS.xsd";
60+
"https://raw.githubusercontent.com/aas-core-works/aas-core3.0-testgen/403a0a7cca4a787f642b226bc940ae2d2b319dad/test_data/schema.xsd";
61+
// "https://raw.githubusercontent.com/admin-shell-io/aas-specs/v3.0.6/schemas/xml/AAS.xsd";
6362

6463
AspectModelAASGenerator generator = new AspectModelAASGenerator();
6564

@@ -86,7 +85,7 @@ void testGenerateAasxFromBammAspectWithEntity() throws IOException, Deserializat
8685
"SubmodelElement is not a SubmodelElementCollection." );
8786
final SubmodelElementCollection collection = (SubmodelElementCollection) env.getSubmodels().get( 0 ).getSubmodelElements().get( 0 );
8887
assertEquals( 1, collection.getValue().size(), "Not exactly one Element in SubmodelElementCollection" );
89-
assertEquals( "entityProperty", collection.getValue().stream().findFirst().get().getIdShort() );
88+
assertEquals( "id_entityProperty", collection.getValue().stream().findFirst().get().getIdShort() );
9089

9190
getDataSpecificationIEC61360( "urn:bamm:io.openmanufacturing.test:1.0.0#testProperty", env );
9291
}
@@ -98,7 +97,7 @@ void testGenerateAasxFromBammAspectWithCollection() throws IOException, Deserial
9897
assertEquals( 1, env.getSubmodels().get( 0 ).getSubmodelElements().size(), "Not exactly one SubmodelElement in AAS." );
9998
final SubmodelElement submodelElement = env.getSubmodels().get( 0 ).getSubmodelElements().get( 0 );
10099
assertTrue( submodelElement instanceof SubmodelElementCollection, "SubmodelElement is not a SubmodelElementCollection" );
101-
assertEquals( "testProperty", submodelElement.getIdShort() );
100+
assertEquals( "id_testProperty", submodelElement.getIdShort() );
102101

103102
getDataSpecificationIEC61360( "urn:bamm:io.openmanufacturing.test:1.0.0#testProperty", env );
104103
}
@@ -110,7 +109,7 @@ void testGenerateAasxFromBammAspectWithList() throws IOException, Deserializatio
110109
assertEquals( 1, env.getSubmodels().get( 0 ).getSubmodelElements().size(), "Not exactly one SubmodelElement in AAS." );
111110
final SubmodelElement submodelElement = env.getSubmodels().get( 0 ).getSubmodelElements().get( 0 );
112111
assertTrue( submodelElement instanceof SubmodelElementList, "SubmodelElement is not a SubmodelElementCollection" );
113-
assertEquals( "testProperty", submodelElement.getIdShort() );
112+
assertEquals( "id_testProperty", submodelElement.getIdShort() );
114113

115114
getDataSpecificationIEC61360( "urn:bamm:io.openmanufacturing.test:1.0.0#testProperty", env );
116115
}
@@ -122,7 +121,7 @@ void testGenerateAasxFromBammAspectWithSet() throws IOException, Deserialization
122121
assertEquals( 1, env.getSubmodels().get( 0 ).getSubmodelElements().size(), "Not exactly one SubmodelElement in AAS." );
123122
final SubmodelElement submodelElement = env.getSubmodels().get( 0 ).getSubmodelElements().get( 0 );
124123
assertTrue( submodelElement instanceof SubmodelElementCollection, "SubmodelElement is not a SubmodelElementCollection" );
125-
assertEquals( "testProperty", submodelElement.getIdShort() );
124+
assertEquals( "id_testProperty", submodelElement.getIdShort() );
126125

127126
getDataSpecificationIEC61360( "urn:bamm:io.openmanufacturing.test:1.0.0#testProperty", env );
128127
}
@@ -134,7 +133,7 @@ void testGenerateAasxFromBammAspectWithSortedSet() throws IOException, Deseriali
134133
assertEquals( 1, env.getSubmodels().get( 0 ).getSubmodelElements().size(), "Not exactly one SubmodelElement in AAS." );
135134
final SubmodelElement submodelElement = env.getSubmodels().get( 0 ).getSubmodelElements().get( 0 );
136135
assertTrue( submodelElement instanceof SubmodelElementList, "SubmodelElement is not a SubmodelElementCollection" );
137-
assertEquals( "testProperty", submodelElement.getIdShort() );
136+
assertEquals( "id_testProperty", submodelElement.getIdShort() );
138137

139138
getDataSpecificationIEC61360( "urn:bamm:io.openmanufacturing.test:1.0.0#testProperty", env );
140139
}
@@ -145,7 +144,7 @@ void testGenerateAasxFromBammAspectWithEitherWithComplexTypes() throws IOExcepti
145144
assertEquals( 1, env.getSubmodels().size(), "Not exactly one Submodel in AAS." );
146145
assertEquals( 1, env.getSubmodels().get( 0 ).getSubmodelElements().size(), 1, "Not exactly one Element in SubmodelElements." );
147146
final SubmodelElementList elementCollection = ((SubmodelElementList) env.getSubmodels().get( 0 ).getSubmodelElements().get( 0 ));
148-
final Set<String> testValues = Set.of( "RightEntity", "LeftEntity" );
147+
final Set<String> testValues = Set.of( "id_RightEntity", "id_LeftEntity" );
149148
assertTrue( elementCollection.getValue().stream().anyMatch( x -> testValues.contains( x.getIdShort() ) ), "Neither left nor right entity contained." );
150149

151150
final Set<String> semanticIds =
@@ -175,10 +174,10 @@ void testGenerateAasxFromBammWithConstraint() throws IOException, Deserializatio
175174
assertEquals( 1, env.getSubmodels().get( 0 ).getSubmodelElements().size(), 6, "Not exactly six Elements in SubmodelElements." );
176175
final SubmodelElement submodelElement =
177176
env.getSubmodels().get( 0 ).getSubmodelElements().stream()
178-
.filter( x -> x.getIdShort().equals( "stringLcProperty" ) )
177+
.filter( x -> x.getIdShort().equals( "id_stringLcProperty" ) )
179178
.findFirst()
180179
.orElseThrow();
181-
assertEquals( "stringLcProperty", submodelElement.getIdShort() );
180+
assertEquals( "id_stringLcProperty", submodelElement.getIdShort() );
182181

183182
final Set<String> semanticIds =
184183
Set.of( "urn:bamm:io.openmanufacturing.test:1.0.0#stringLcProperty",
@@ -218,7 +217,7 @@ void testGenerateAasxFromBammAspectWithEnumeration() throws IOException, Deseria
218217
final DataSpecificationIec61360 dataSpecificationContent =
219218
(DataSpecificationIec61360)
220219
env.getConceptDescriptions().stream()
221-
.filter( x -> x.getIdShort().equals( "TestEnumeration" ) )
220+
.filter( x -> x.getIdShort().equals( "id_TestEnumeration" ) )
222221
.findFirst()
223222
.get()
224223
.getEmbeddedDataSpecifications()

0 commit comments

Comments
 (0)