20
20
import java .util .Map ;
21
21
import java .util .Optional ;
22
22
import java .util .Set ;
23
- import java .util .function .Supplier ;
24
23
import java .util .stream .Collectors ;
25
24
import java .util .stream .StreamSupport ;
26
25
41
40
import org .eclipse .digitaltwin .aas4j .v3 .model .Operation ;
42
41
import org .eclipse .digitaltwin .aas4j .v3 .model .OperationVariable ;
43
42
import org .eclipse .digitaltwin .aas4j .v3 .model .Reference ;
43
+ import org .eclipse .digitaltwin .aas4j .v3 .model .ReferenceTypes ;
44
44
import org .eclipse .digitaltwin .aas4j .v3 .model .Submodel ;
45
45
import org .eclipse .digitaltwin .aas4j .v3 .model .SubmodelElement ;
46
46
import org .eclipse .digitaltwin .aas4j .v3 .model .SubmodelElementCollection ;
47
47
import org .eclipse .digitaltwin .aas4j .v3 .model .SubmodelElementList ;
48
48
import org .eclipse .digitaltwin .aas4j .v3 .model .ValueList ;
49
49
import org .eclipse .digitaltwin .aas4j .v3 .model .ValueReferencePair ;
50
+ import org .eclipse .digitaltwin .aas4j .v3 .model .impl .DefaultAdministrativeInformation ;
50
51
import org .eclipse .digitaltwin .aas4j .v3 .model .impl .DefaultAssetAdministrationShell ;
51
52
import org .eclipse .digitaltwin .aas4j .v3 .model .impl .DefaultAssetInformation ;
52
53
import org .eclipse .digitaltwin .aas4j .v3 .model .impl .DefaultBlob ;
@@ -176,19 +177,26 @@ public Environment visitAspect( final Aspect aspect, Context context ) {
176
177
177
178
final Submodel submodel = context .getSubmodel ();
178
179
submodel .setIdShort ( aspect .getName () );
180
+ submodel .setId ( aspect .getAspectModelUrn ().toString () + "/submodel" );
179
181
submodel .setSemanticId ( buildReferenceToConceptDescription ( aspect ) );
180
182
submodel .setDescription ( langStringMapper .map ( aspect .getDescriptions () ) );
181
183
submodel .setKind ( context .getModelingKind () );
184
+ submodel .setAdministration ( new DefaultAdministrativeInformation .Builder ().build () );
185
+ submodel .setChecksum ( String .valueOf ( aspect .hashCode () ) );
182
186
183
187
createConceptDescription ( aspect , context );
184
188
185
189
final AssetAdministrationShell administrationShell =
186
190
new DefaultAssetAdministrationShell .Builder ()
187
191
.id ( DEFAULT_MAPPER .determineIdentifierFor ( aspect ) )
188
192
.idShort ( ADMIN_SHELL_NAME )
193
+ .description ( langStringMapper .createLangString ( ADMIN_SHELL_NAME , "en" ) )
194
+ .checksum ( "a checksum" )
195
+ .administration ( new DefaultAdministrativeInformation .Builder ().build () )
189
196
.assetInformation ( new DefaultAssetInformation .Builder ()
190
197
.assetKind ( context .getAssetKind () )
191
198
.build () )
199
+ .embeddedDataSpecifications ( extractEmbeddedDataSpecification ( aspect ) )
192
200
.build ();
193
201
context
194
202
.getEnvironment ()
@@ -207,14 +215,17 @@ private List<SubmodelElement> visitOperations(
207
215
208
216
private List <SubmodelElement > visitProperties (
209
217
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 () );
211
222
}
212
223
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 ()
215
227
.filter ( i -> i .getIdShort ().equals ( property .getName () ) )
216
- .findFirst ()
217
- .orElse ( new DefaultProperty .Builder ().build () );
228
+ .findFirst ();
218
229
if ( recursiveProperty .contains ( property ) ) {
219
230
// The guard checks for recursion in properties. If a recursion happens, the respective
220
231
// property will be excluded from generation.
@@ -226,13 +237,13 @@ private SubmodelElement map( final Property property, final Context context ) {
226
237
"Having a recursive Property: %s which is not optional is not valid. Check the model. Property will be excluded from AAS mapping." ,
227
238
property ) );
228
239
}
229
- return defaultResultForProperty . get () ;
240
+ return defaultResultForProperty ;
230
241
}
231
242
recursiveProperty .add ( property );
232
243
233
- if ( property .getCharacteristic ().isEmpty () ) {
244
+ if ( property .getCharacteristic ().isEmpty () || property . isAbstract () ) {
234
245
LOG .warn ( String .format ( "Having an Abstract Property. Will be excluded from AAS mapping." ) );
235
- return defaultResultForProperty . get ();
246
+ return Optional . empty ();
236
247
}
237
248
238
249
// Characteristic defines how the property is mapped to SubmodelElement
@@ -243,7 +254,8 @@ private SubmodelElement map( final Property property, final Context context ) {
243
254
final SubmodelElement element = context .getPropertyResult ();
244
255
245
256
recursiveProperty .remove ( property );
246
- return element ;
257
+
258
+ return Optional .of ( element );
247
259
}
248
260
249
261
private SubmodelElement decideOnMapping ( final Property property , final Context context ) {
@@ -294,7 +306,7 @@ private Operation map( final io.openmanufacturing.sds.metamodel.Operation operat
294
306
}
295
307
296
308
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 ();
298
310
}
299
311
300
312
private Reference buildReferenceToEnumValue ( final Enumeration enumeration , final Object value ) {
@@ -303,7 +315,7 @@ private Reference buildReferenceToEnumValue( final Enumeration enumeration, fina
303
315
.type ( KeyTypes .DATA_ELEMENT )
304
316
.value ( DEFAULT_MAPPER .determineIdentifierFor ( enumeration ) + ":" + value .toString () )
305
317
.build ();
306
- return new DefaultReference .Builder ().keys ( key ).build ();
318
+ return new DefaultReference .Builder ().type ( ReferenceTypes . MODEL_REFERENCE ). keys ( key ).build ();
307
319
}
308
320
309
321
private Reference buildReferenceToConceptDescription ( final Aspect aspect ) {
@@ -312,7 +324,23 @@ private Reference buildReferenceToConceptDescription( final Aspect aspect ) {
312
324
.type ( KeyTypes .CONCEPT_DESCRIPTION )
313
325
.value ( DEFAULT_MAPPER .determineIdentifierFor ( aspect ) )
314
326
.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 () );
316
344
}
317
345
318
346
private void createConceptDescription ( final Property property , final Context context ) {
@@ -351,12 +379,14 @@ private void createConceptDescription( final Aspect aspect, final Context contex
351
379
352
380
private EmbeddedDataSpecification extractEmbeddedDataSpecification ( final Property property ) {
353
381
return new DefaultEmbeddedDataSpecification .Builder ()
382
+ .dataSpecification ( buildReferenceForSeeElement ( property .getAspectModelUrn ().toString () ) )
354
383
.dataSpecificationContent ( extractDataSpecificationContent ( property ) )
355
384
.build ();
356
385
}
357
386
358
387
private EmbeddedDataSpecification extractEmbeddedDataSpecification ( final Aspect aspect ) {
359
388
return new DefaultEmbeddedDataSpecification .Builder ()
389
+ .dataSpecification ( buildReferenceForSeeElement ( aspect .getAspectModelUrn ().toString () ) )
360
390
.dataSpecificationContent ( extractDataSpecificationContent ( aspect ) )
361
391
.build ();
362
392
}
@@ -369,8 +399,11 @@ private DataSpecificationIEC61360 extractDataSpecificationContent( final Propert
369
399
370
400
return new DefaultDataSpecificationIEC61360 .Builder ()
371
401
.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 () ) )
373
405
.shortName ( langStringMapper .createLangString ( property .getName (), DEFAULT_LOCALE ) )
406
+
374
407
.dataType ( mapIEC61360DataType ( property .getCharacteristic () ) )
375
408
.build ();
376
409
}
@@ -380,8 +413,11 @@ private DataSpecificationIEC61360 extractDataSpecificationContent( final Aspect
380
413
381
414
return new DefaultDataSpecificationIEC61360 .Builder ()
382
415
.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 () ) )
384
419
.shortName ( langStringMapper .createLangString ( aspect .getName (), DEFAULT_LOCALE ) )
420
+ .value ( aspect .getName () )
385
421
.build ();
386
422
}
387
423
0 commit comments