|
39 | 39 | import org.eclipse.digitaltwin.aas4j.v3.model.Key;
|
40 | 40 | import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes;
|
41 | 41 | import org.eclipse.digitaltwin.aas4j.v3.model.LangString;
|
| 42 | +import org.eclipse.digitaltwin.aas4j.v3.model.ModelingKind; |
42 | 43 | import org.eclipse.digitaltwin.aas4j.v3.model.Operation;
|
43 | 44 | import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;
|
44 | 45 | import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
|
|
72 | 73 | import com.fasterxml.jackson.databind.node.ArrayNode;
|
73 | 74 | import com.google.common.collect.ImmutableMap;
|
74 | 75 |
|
| 76 | +import io.openmanufacturing.sds.aspectmetamodel.KnownVersion; |
| 77 | +import io.openmanufacturing.sds.aspectmodel.urn.AspectModelUrn; |
| 78 | +import io.openmanufacturing.sds.aspectmodel.vocabulary.BAMM; |
75 | 79 | import io.openmanufacturing.sds.characteristic.Code;
|
76 | 80 | import io.openmanufacturing.sds.characteristic.Collection;
|
77 | 81 | import io.openmanufacturing.sds.characteristic.Duration;
|
|
92 | 96 | import io.openmanufacturing.sds.metamodel.Property;
|
93 | 97 | import io.openmanufacturing.sds.metamodel.Scalar;
|
94 | 98 | import io.openmanufacturing.sds.metamodel.Type;
|
| 99 | +import io.openmanufacturing.sds.metamodel.loader.MetaModelBaseAttributes; |
95 | 100 | import io.openmanufacturing.sds.metamodel.visitor.AspectVisitor;
|
96 | 101 |
|
97 | 102 | public class AspectModelAASVisitor implements AspectVisitor<Environment, Context> {
|
@@ -572,26 +577,52 @@ private <T extends Collection> List<SubmodelElement> getValues( final T collecti
|
572 | 577 | public Environment visitEither(
|
573 | 578 | final Either either, final Context context ) {
|
574 | 579 | final List<SubmodelElement> submodelElements = new ArrayList<>();
|
575 |
| - if ( either.getLeft().getDataType().isPresent() ) { |
576 |
| - submodelElements.add( |
577 |
| - decideOnMapping( either.getLeft().getDataType().get(), context.getProperty(), context ) ); |
578 |
| - } |
579 |
| - if ( either.getRight().getDataType().isPresent() ) { |
580 |
| - submodelElements.add( |
581 |
| - decideOnMapping( either.getRight().getDataType().get(), context.getProperty(), context ) ); |
582 |
| - } |
583 |
| - final SubmodelElementList aasSubModelElementCollection = |
| 580 | + final var property = context.getProperty(); |
| 581 | + either.getLeft().getDataType() |
| 582 | + .flatMap( dataType -> handleEitherField( "left", either.getLeft(), property, context ) ) |
| 583 | + .ifPresent( submodelElements::add ); |
| 584 | + either.getRight().getDataType() |
| 585 | + .flatMap( dataType -> handleEitherField( "right", either.getRight(), property, context ) ) |
| 586 | + .ifPresent( submodelElements::add ); |
| 587 | + |
| 588 | + //context.setProperty( property ); |
| 589 | + final SubmodelElementList eitherSubModelElements = |
584 | 590 | new DefaultSubmodelElementList.Builder()
|
585 | 591 | .idShort( either.getName() )
|
586 | 592 | .displayName( map( either.getPreferredNames() ) )
|
587 | 593 | .description( map( either.getDescriptions() ) )
|
588 | 594 | .value( submodelElements )
|
589 | 595 | .kind( context.getModelingKind() )
|
590 | 596 | .build();
|
591 |
| - context.setPropertyResult( aasSubModelElementCollection ); |
| 597 | + context.setPropertyResult( eitherSubModelElements ); |
592 | 598 | return context.environment;
|
593 | 599 | }
|
594 | 600 |
|
| 601 | + private Optional<SubmodelElement> handleEitherField( final String field, final Characteristic fieldCharacteristic, |
| 602 | + final Property property, final Context context ) { |
| 603 | + Optional<SubmodelElement> result = Optional.empty(); |
| 604 | + if ( context.getModelingKind().equals( ModelingKind.INSTANCE ) ) { |
| 605 | + final var fieldProperty = createProperty( property.getMetaModelVersion(), field, fieldCharacteristic ); |
| 606 | + context.setProperty( fieldProperty ); |
| 607 | + if ( context.getRawPropertyValue().isPresent() ) { |
| 608 | + result = Optional.ofNullable( decideOnMapping( fieldCharacteristic.getDataType().get(), context.getProperty(), context ) ); |
| 609 | + } |
| 610 | + context.getPropertyResult(); |
| 611 | + } else { |
| 612 | + result = Optional.ofNullable( decideOnMapping( fieldCharacteristic.getDataType().get(), context.getProperty(), context ) ); |
| 613 | + } |
| 614 | + |
| 615 | + return result; |
| 616 | + } |
| 617 | + |
| 618 | + private Property createProperty( final KnownVersion modelVersion, final String propertyName, final Characteristic characteristic ) { |
| 619 | + final MetaModelBaseAttributes propertyAttributes = |
| 620 | + MetaModelBaseAttributes.from( modelVersion, AspectModelUrn.fromUrn( new BAMM( modelVersion ).Property().getURI() ), propertyName ); |
| 621 | + return new io.openmanufacturing.sds.metamodel.impl.DefaultProperty( propertyAttributes, Optional.of( characteristic ), Optional.empty(), false, false, |
| 622 | + Optional.empty(), false, |
| 623 | + Optional.empty() ); |
| 624 | + } |
| 625 | + |
595 | 626 | @Override
|
596 | 627 | public Environment visitQuantifiable(
|
597 | 628 | final Quantifiable quantifiable, final Context context ) {
|
|
0 commit comments