-
Notifications
You must be signed in to change notification settings - Fork 12
Allow property mapping customizations for collection properties #598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andreas-schilling
merged 5 commits into
eclipse-esmf:main
from
bci-oss:feature/547-allow-collectionproperty-mapping-customization
Jul 9, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4a2a24e
Allow property mapping customizations for collection properties
andreas-schilling 19aabac
Fix style issues
andreas-schilling 95ffa37
Merge branch 'main' into feature/547-allow-collectionproperty-mapping…
andreas-schilling c7bbf7c
Merge branch 'main' into feature/547-allow-collectionproperty-mapping…
andreas-schilling f4076fc
Merge branch 'main' into feature/547-allow-collectionproperty-mapping…
andreas-schilling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...aas-generator/src/test/java/org/eclipse/esmf/aspectmodel/aas/IntegerCollectionMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.eclipse.esmf.aspectmodel.aas; | ||
|
||
import java.util.List; | ||
import java.util.stream.StreamSupport; | ||
|
||
import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; | ||
import org.eclipse.esmf.metamodel.Property; | ||
import org.eclipse.esmf.metamodel.Type; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.AasSubmodelElements; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementList; | ||
|
||
public class IntegerCollectionMapper implements PropertyMapper<SubmodelElementList> { | ||
@Override | ||
public SubmodelElementList mapToAasProperty( final Type type, final Property property, final Context context ) { | ||
final List<? extends SubmodelElement> values = context.getRawPropertyValue() | ||
.stream() | ||
.filter( JsonNode::isArray ) | ||
.map( ArrayNode.class::cast ) | ||
.flatMap( arrayNode -> StreamSupport.stream( arrayNode.spliterator(), false ) | ||
.map( value -> new DefaultProperty.Builder().idShort( "intValue" ) | ||
.valueType( DataTypeDefXsd.INT ) | ||
.value( value.asText() ) | ||
.build() ) ) | ||
.toList(); | ||
|
||
return new DefaultSubmodelElementList.Builder() | ||
.idShort( property.getName() ) | ||
.displayName( LangStringMapper.NAME.map( property.getPreferredNames() ) ) | ||
.description( LangStringMapper.TEXT.map( property.getDescriptions() ) ) | ||
.value( (List<SubmodelElement>) values ) | ||
.typeValueListElement( AasSubmodelElements.SUBMODEL_ELEMENT ) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public boolean canHandle( final Property property ) { | ||
return property.getAspectModelUrn() | ||
.map( urn -> urn.equals( AspectModelUrn.fromUrn( "urn:samm:org.eclipse.esmf.test:1.0.0#testList" ) ) ) | ||
.orElse( false ); | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.