Skip to content

Commit 0a53802

Browse files
Merge branch 'migrate_aas_generator_to_aas4j' into feature/add-generator-for-submodels
# Conflicts: # core/sds-aspect-model-aas-generator/src/main/java/io/openmanufacturing/sds/aspectmodel/aas/AspectModelAASVisitor.java # core/sds-aspect-model-aas-generator/src/test/java/io/openmanufacturing/sds/aspectmodel/aas/AspectModelAASGeneratorTest.java
2 parents a963180 + ff1eb23 commit 0a53802

File tree

3 files changed

+129
-66
lines changed

3 files changed

+129
-66
lines changed

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

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Map;
2121
import java.util.Optional;
2222
import java.util.Set;
23-
import java.util.function.Supplier;
2423
import java.util.stream.Collectors;
2524
import java.util.stream.StreamSupport;
2625

@@ -41,12 +40,14 @@
4140
import org.eclipse.digitaltwin.aas4j.v3.model.Operation;
4241
import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;
4342
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
43+
import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes;
4444
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
4545
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement;
4646
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection;
4747
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList;
4848
import org.eclipse.digitaltwin.aas4j.v3.model.ValueList;
4949
import org.eclipse.digitaltwin.aas4j.v3.model.ValueReferencePair;
50+
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation;
5051
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell;
5152
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetInformation;
5253
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultBlob;
@@ -176,19 +177,26 @@ public Environment visitAspect( final Aspect aspect, Context context ) {
176177

177178
final Submodel submodel = context.getSubmodel();
178179
submodel.setIdShort( aspect.getName() );
180+
submodel.setId( aspect.getAspectModelUrn().toString() + "/submodel" );
179181
submodel.setSemanticId( buildReferenceToConceptDescription( aspect ) );
180182
submodel.setDescription( langStringMapper.map( aspect.getDescriptions() ) );
181183
submodel.setKind( context.getModelingKind() );
184+
submodel.setAdministration( new DefaultAdministrativeInformation.Builder().build() );
185+
submodel.setChecksum( String.valueOf( aspect.hashCode() ) );
182186

183187
createConceptDescription( aspect, context );
184188

185189
final AssetAdministrationShell administrationShell =
186190
new DefaultAssetAdministrationShell.Builder()
187191
.id( DEFAULT_MAPPER.determineIdentifierFor( aspect ) )
188192
.idShort( ADMIN_SHELL_NAME )
193+
.description( langStringMapper.createLangString( ADMIN_SHELL_NAME, "en" ) )
194+
.checksum( "a checksum" )
195+
.administration( new DefaultAdministrativeInformation.Builder().build() )
189196
.assetInformation( new DefaultAssetInformation.Builder()
190197
.assetKind( context.getAssetKind() )
191198
.build() )
199+
.embeddedDataSpecifications( extractEmbeddedDataSpecification( aspect ) )
192200
.build();
193201
context
194202
.getEnvironment()
@@ -207,14 +215,17 @@ private List<SubmodelElement> visitOperations(
207215

208216
private List<SubmodelElement> visitProperties(
209217
final List<Property> elements, final Context context ) {
210-
return elements.stream().map( i -> map( i, context ) ).collect( Collectors.toList() );
218+
return elements.stream().map( i -> map( i, context ) )
219+
.filter( Optional::isPresent )
220+
.map( Optional::get )
221+
.collect( Collectors.toList() );
211222
}
212223

213-
private SubmodelElement map( final Property property, final Context context ) {
214-
final Supplier<SubmodelElement> defaultResultForProperty = () -> context.getSubmodel().getSubmodelElements().stream()
224+
private Optional<SubmodelElement> map( final Property property, final Context context ) {
225+
final Optional<SubmodelElement> defaultResultForProperty = context.getSubmodel()
226+
.getSubmodelElements().stream()
215227
.filter( i -> i.getIdShort().equals( property.getName() ) )
216-
.findFirst()
217-
.orElse( new DefaultProperty.Builder().build() );
228+
.findFirst();
218229
if ( recursiveProperty.contains( property ) ) {
219230
// The guard checks for recursion in properties. If a recursion happens, the respective
220231
// property will be excluded from generation.
@@ -226,13 +237,13 @@ private SubmodelElement map( final Property property, final Context context ) {
226237
"Having a recursive Property: %s which is not optional is not valid. Check the model. Property will be excluded from AAS mapping.",
227238
property ) );
228239
}
229-
return defaultResultForProperty.get();
240+
return defaultResultForProperty;
230241
}
231242
recursiveProperty.add( property );
232243

233-
if ( property.getCharacteristic().isEmpty() ) {
244+
if ( property.getCharacteristic().isEmpty() || property.isAbstract() ) {
234245
LOG.warn( String.format( "Having an Abstract Property. Will be excluded from AAS mapping." ) );
235-
return defaultResultForProperty.get();
246+
return Optional.empty();
236247
}
237248

238249
// Characteristic defines how the property is mapped to SubmodelElement
@@ -243,7 +254,8 @@ private SubmodelElement map( final Property property, final Context context ) {
243254
final SubmodelElement element = context.getPropertyResult();
244255

245256
recursiveProperty.remove( property );
246-
return element;
257+
258+
return Optional.of( element );
247259
}
248260

249261
private SubmodelElement decideOnMapping( final Property property, final Context context ) {
@@ -294,7 +306,7 @@ private Operation map( final io.openmanufacturing.sds.metamodel.Operation operat
294306
}
295307

296308
private OperationVariable mapOperationVariable( final Property property, final Context context ) {
297-
return new DefaultOperationVariable.Builder().value( map( property, context ) ).build();
309+
return new DefaultOperationVariable.Builder().value( map( property, context ).get() ).build();
298310
}
299311

300312
private Reference buildReferenceToEnumValue( final Enumeration enumeration, final Object value ) {
@@ -303,7 +315,7 @@ private Reference buildReferenceToEnumValue( final Enumeration enumeration, fina
303315
.type( KeyTypes.DATA_ELEMENT )
304316
.value( DEFAULT_MAPPER.determineIdentifierFor( enumeration ) + ":" + value.toString() )
305317
.build();
306-
return new DefaultReference.Builder().keys( key ).build();
318+
return new DefaultReference.Builder().type( ReferenceTypes.MODEL_REFERENCE ).keys( key ).build();
307319
}
308320

309321
private Reference buildReferenceToConceptDescription( final Aspect aspect ) {
@@ -312,7 +324,23 @@ private Reference buildReferenceToConceptDescription( final Aspect aspect ) {
312324
.type( KeyTypes.CONCEPT_DESCRIPTION )
313325
.value( DEFAULT_MAPPER.determineIdentifierFor( aspect ) )
314326
.build();
315-
return new DefaultReference.Builder().keys( key ).build();
327+
return new DefaultReference.Builder().type( ReferenceTypes.MODEL_REFERENCE ).keys( key ).build();
328+
}
329+
330+
private Reference buildReferenceForSeeElement( final String seeReference ) {
331+
final Key key =
332+
new DefaultKey.Builder()
333+
.type( KeyTypes.GLOBAL_REFERENCE )
334+
.value( seeReference )
335+
.build();
336+
return new DefaultReference.Builder()
337+
.type( ReferenceTypes.GLOBAL_REFERENCE )
338+
.keys( key )
339+
.build();
340+
}
341+
342+
private List<Reference> buildReferencesForSeeElements( final List<String> seeReferences ) {
343+
return seeReferences.stream().map( this::buildReferenceForSeeElement ).collect( Collectors.toList() );
316344
}
317345

318346
private void createConceptDescription( final Property property, final Context context ) {
@@ -351,12 +379,14 @@ private void createConceptDescription( final Aspect aspect, final Context contex
351379

352380
private EmbeddedDataSpecification extractEmbeddedDataSpecification( final Property property ) {
353381
return new DefaultEmbeddedDataSpecification.Builder()
382+
.dataSpecification( buildReferenceForSeeElement( property.getAspectModelUrn().toString() ) )
354383
.dataSpecificationContent( extractDataSpecificationContent( property ) )
355384
.build();
356385
}
357386

358387
private EmbeddedDataSpecification extractEmbeddedDataSpecification( final Aspect aspect ) {
359388
return new DefaultEmbeddedDataSpecification.Builder()
389+
.dataSpecification( buildReferenceForSeeElement( aspect.getAspectModelUrn().toString() ) )
360390
.dataSpecificationContent( extractDataSpecificationContent( aspect ) )
361391
.build();
362392
}
@@ -369,8 +399,11 @@ private DataSpecificationIEC61360 extractDataSpecificationContent( final Propert
369399

370400
return new DefaultDataSpecificationIEC61360.Builder()
371401
.definition( definitions )
372-
.preferredName( langStringMapper.map( property.getPreferredNames() ) )
402+
.preferredName( property.getPreferredNames().isEmpty() ?
403+
Collections.singletonList( langStringMapper.createLangString( property.getName(), DEFAULT_LOCALE ) ) :
404+
langStringMapper.map( property.getPreferredNames() ) )
373405
.shortName( langStringMapper.createLangString( property.getName(), DEFAULT_LOCALE ) )
406+
374407
.dataType( mapIEC61360DataType( property.getCharacteristic() ) )
375408
.build();
376409
}
@@ -380,8 +413,11 @@ private DataSpecificationIEC61360 extractDataSpecificationContent( final Aspect
380413

381414
return new DefaultDataSpecificationIEC61360.Builder()
382415
.definition( definitions )
383-
.preferredName( langStringMapper.map( aspect.getPreferredNames() ) )
416+
.preferredName( aspect.getPreferredNames().isEmpty() ?
417+
Collections.singletonList( langStringMapper.createLangString( aspect.getName(), DEFAULT_LOCALE ) ) :
418+
langStringMapper.map( aspect.getPreferredNames() ) )
384419
.shortName( langStringMapper.createLangString( aspect.getName(), DEFAULT_LOCALE ) )
420+
.value( aspect.getName() )
385421
.build();
386422
}
387423

0 commit comments

Comments
 (0)