@@ -143,12 +143,13 @@ private interface SubmodelElementBuilder {
143
143
144
144
private final List <PropertyMapper <?>> customPropertyMappers = new ArrayList <>();
145
145
146
- public AspectModelAASVisitor withPropertyMapper ( final PropertyMapper propertyMapper ) {
146
+ public AspectModelAASVisitor withPropertyMapper ( final PropertyMapper <?> propertyMapper ) {
147
147
customPropertyMappers .add ( propertyMapper );
148
148
149
149
return this ;
150
150
}
151
151
152
+ @ SuppressWarnings ( "unchecked" )
152
153
protected <T extends SubmodelElement > PropertyMapper <T > findPropertyMapper ( final Property property ) {
153
154
return (PropertyMapper <T >) getCustomPropertyMappers ().stream ()
154
155
.filter ( mapper -> mapper .canHandle ( property ) )
@@ -167,23 +168,24 @@ public Environment visitBase( final ModelElement base, final Context context ) {
167
168
}
168
169
169
170
@ Override
170
- public Environment visitAspect ( final Aspect aspect , Context context ) {
171
- if ( context == null ) {
171
+ public Environment visitAspect ( final Aspect aspect , final Context context ) {
172
+ Context usedContext = context ;
173
+ if ( usedContext == null ) {
172
174
final Submodel submodel = new DefaultSubmodel .Builder ().build ();
173
175
final Environment environment = new DefaultEnvironment .Builder ().submodels ( Collections .singletonList ( submodel ) ).build ();
174
- context = new Context ( environment , submodel );
175
- context .setEnvironment ( environment );
176
+ usedContext = new Context ( environment , submodel );
177
+ usedContext .setEnvironment ( environment );
176
178
}
177
179
178
- final Submodel submodel = context .getSubmodel ();
180
+ final Submodel submodel = usedContext .getSubmodel ();
179
181
submodel .setIdShort ( aspect .getName () );
180
182
submodel .setId ( aspect .getAspectModelUrn ().toString () + "/submodel" );
181
183
submodel .setSemanticID ( buildReferenceToConceptDescription ( aspect ) );
182
184
submodel .setDescription ( LangStringMapper .TEXT .map ( aspect .getDescriptions () ) );
183
- submodel .setKind ( context .getModelingKind () );
185
+ submodel .setKind ( usedContext .getModelingKind () );
184
186
submodel .setAdministration ( new DefaultAdministrativeInformation .Builder ().build () );
185
187
186
- createConceptDescription ( aspect , context );
188
+ createConceptDescription ( aspect , usedContext );
187
189
188
190
final AssetAdministrationShell administrationShell =
189
191
new DefaultAssetAdministrationShell .Builder ()
@@ -192,18 +194,17 @@ public Environment visitAspect( final Aspect aspect, Context context ) {
192
194
.description ( LangStringMapper .TEXT .createLangString ( ADMIN_SHELL_NAME , "en" ) )
193
195
.administration ( new DefaultAdministrativeInformation .Builder ().build () )
194
196
.assetInformation ( new DefaultAssetInformation .Builder ()
195
- .assetKind ( context .getAssetKind () )
197
+ .assetKind ( usedContext .getAssetKind () )
196
198
.build () )
197
199
.embeddedDataSpecifications ( extractEmbeddedDataSpecification ( aspect ) )
198
200
.build ();
199
- context
200
- .getEnvironment ()
201
+ usedContext .getEnvironment ()
201
202
.setAssetAdministrationShells ( Collections .singletonList ( administrationShell ) );
202
203
203
- context .appendToSubModelElements ( visitProperties ( aspect .getProperties (), context ) );
204
- context .appendToSubModelElements ( visitOperations ( aspect .getOperations (), context ) );
204
+ usedContext .appendToSubModelElements ( visitProperties ( aspect .getProperties (), usedContext ) );
205
+ usedContext .appendToSubModelElements ( visitOperations ( aspect .getOperations (), usedContext ) );
205
206
206
- return context .getEnvironment ();
207
+ return usedContext .getEnvironment ();
207
208
}
208
209
209
210
private List <SubmodelElement > visitOperations (
@@ -394,9 +395,9 @@ private DataSpecificationIec61360 extractDataSpecificationContent( final Propert
394
395
.map ( LangStringMapper .DEFINITION ::map )
395
396
.collect ( Collectors .toList () );
396
397
397
- final List <LangStringPreferredNameTypeIec61360 > preferredNames = property .getPreferredNames ().size () > 0 ?
398
- property . getPreferredNames (). stream (). map ( LangStringMapper .PREFERRED_NAME :: map ). collect ( Collectors . toList ( ) ) :
399
- Collections . singletonList ( LangStringMapper .PREFERRED_NAME . createLangString ( property . getName (), DEFAULT_LOCALE ) );
398
+ final List <LangStringPreferredNameTypeIec61360 > preferredNames = property .getPreferredNames ().isEmpty () ?
399
+ Collections . singletonList ( LangStringMapper .PREFERRED_NAME . createLangString ( property . getName (), DEFAULT_LOCALE ) ) :
400
+ property . getPreferredNames (). stream (). map ( LangStringMapper .PREFERRED_NAME :: map ). collect ( Collectors . toList ( ) );
400
401
401
402
return new DefaultDataSpecificationIec61360 .Builder ()
402
403
.definition ( definitions )
@@ -408,9 +409,9 @@ private DataSpecificationIec61360 extractDataSpecificationContent( final Propert
408
409
}
409
410
410
411
private DataSpecificationIec61360 extractDataSpecificationContent ( final Aspect aspect ) {
411
- final List <LangStringPreferredNameTypeIec61360 > preferredNames = aspect .getPreferredNames ().size () > 0 ?
412
- aspect . getPreferredNames (). stream (). map ( LangStringMapper .PREFERRED_NAME :: map ). collect ( Collectors . toList ( ) ) :
413
- Collections . singletonList ( LangStringMapper .PREFERRED_NAME . createLangString ( aspect . getName (), DEFAULT_LOCALE ) );
412
+ final List <LangStringPreferredNameTypeIec61360 > preferredNames = aspect .getPreferredNames ().isEmpty () ?
413
+ Collections . singletonList ( LangStringMapper .PREFERRED_NAME . createLangString ( aspect . getName (), DEFAULT_LOCALE ) ) :
414
+ aspect . getPreferredNames (). stream (). map ( LangStringMapper .PREFERRED_NAME :: map ). collect ( Collectors . toList ( ) );
414
415
415
416
return new DefaultDataSpecificationIec61360 .Builder ()
416
417
.definition ( aspect .getDescriptions ().stream ().map ( LangStringMapper .DEFINITION ::map ).collect ( Collectors .toList () ) )
@@ -478,14 +479,14 @@ private <T extends Collection> Environment visitCollectionProperty(
478
479
( property ) ->
479
480
new DefaultSubmodelElementList .Builder ()
480
481
.idShort ( ID_PREFIX + property .getName () )
481
- .typeValueListElement ( AASSubmodelElements .DATA_ELEMENT ) // TODO check if more specific type info is reuired
482
+ .typeValueListElement ( AASSubmodelElements .DATA_ELEMENT )
482
483
.displayName ( LangStringMapper .NAME .map ( property .getPreferredNames () ) )
483
484
.description ( LangStringMapper .TEXT .map ( property .getDescriptions () ) )
484
485
.value ( List .of ( decideOnMapping ( property , context ) ) )
485
486
.build ();
486
487
final Optional <JsonNode > rawValue = context .getRawPropertyValue ();
487
488
return rawValue .map ( node -> {
488
- if ( node instanceof ArrayNode arrayNode ) {
489
+ if ( node instanceof final ArrayNode arrayNode ) {
489
490
final SubmodelElementBuilder listBuilder =
490
491
( property ) -> {
491
492
final var values = getValues ( collection , property , context , arrayNode );
@@ -526,7 +527,7 @@ private <T extends Collection> List<SubmodelElement> getValues( final T collecti
526
527
context .finishIteration ( property );
527
528
return values ;
528
529
}
529
- } ).orElseGet ( () -> List . of () );
530
+ } ).orElseGet ( List :: of );
530
531
}
531
532
532
533
// Either will be mapped by adding both the left and the right side to the SubmodelTemplate.
@@ -548,7 +549,7 @@ public Environment visitEither(
548
549
final SubmodelElementList eitherSubModelElements =
549
550
new DefaultSubmodelElementList .Builder ()
550
551
.idShort ( ID_PREFIX + either .getName () )
551
- .typeValueListElement ( AASSubmodelElements .DATA_ELEMENT ) // TODO check if more specific type info is rqujried
552
+ .typeValueListElement ( AASSubmodelElements .DATA_ELEMENT )
552
553
.displayName ( LangStringMapper .NAME .map ( either .getPreferredNames () ) )
553
554
.description ( LangStringMapper .TEXT .map ( either .getDescriptions () ) )
554
555
.value ( submodelElements )
0 commit comments