Skip to content

Commit

Permalink
Merge branch 'main' into feature/generate-samm-model-from-aasx
Browse files Browse the repository at this point in the history
  • Loading branch information
atextor committed Dec 15, 2023
2 parents 7113654 + 3f8c676 commit e87ad2d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,12 @@ private void createConceptDescription( final Property property, final Context co
if ( property.getCharacteristic().isEmpty() ) {
return;
}
final Characteristic characteristic = property.getCharacteristic().get();
// check if the concept description is already created. If not create a new one.
if ( !context.hasEnvironmentConceptDescription( property.getAspectModelUrn().toString() ) ) {
final ConceptDescription conceptDescription =
new DefaultConceptDescription.Builder()
.idShort( characteristic.getName() )
.displayName( LangStringMapper.NAME.map( characteristic.getPreferredNames() ) )
.idShort( property.getName() )
.displayName( LangStringMapper.NAME.map( property.getPreferredNames() ) )
.embeddedDataSpecifications( extractEmbeddedDataSpecification( property ) )
.id( DEFAULT_MAPPER.determineIdentifierFor( property ) )
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void testGenerateAasxFromAspectModelWithEnumeration() throws DeserializationExce
assertEquals( 2, env.getConceptDescriptions().size() );

final DataSpecificationIec61360 dataSpecificationContent = (DataSpecificationIec61360) env.getConceptDescriptions().stream()
.filter( conceptDescription -> conceptDescription.getIdShort().equals( "TestEnumeration" ) )
.filter( conceptDescription -> conceptDescription.getIdShort().equals( "testProperty" ) )
.findFirst()
.get()
.getEmbeddedDataSpecifications()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.xml.datatype.DatatypeFactory;
Expand Down Expand Up @@ -222,8 +223,16 @@ private Map<String, Object> transformCollectionProperty( final BasicProperty pro
final List<Object> collectionValues = getCollectionValues( property, (Collection) characteristic );
return toMap( property.getName(), collectionValues );
} else if ( isConstrainedCollection( characteristic ) ) {
return toMap( property.getName(), getCollectionValues( property, characteristic.as( Trait.class ).getBaseCharacteristic().as( Collection.class ),
(LengthConstraint) characteristic.as( Trait.class ).getConstraints().get( 0 ) ) );

final Collection collection = characteristic.as( Trait.class ).getBaseCharacteristic().as( Collection.class );

final List<Constraint> constraints = characteristic.as( Trait.class ).getConstraints().stream().filter( trait -> trait.is( LengthConstraint.class ) )
.toList();

return !constraints.isEmpty() ?
toMap( property.getName(), getCollectionValues( property, collection,
(LengthConstraint) characteristic.as( Trait.class ).getConstraints().get( 0 ) ) ) :
toMap( property.getName(), getCollectionValues( property, collection ) );
}
return ImmutableMap.of();
}
Expand All @@ -233,8 +242,7 @@ private boolean isConstrainedCollection( final Characteristic characteristic ) {
return false;
}
final Trait trait = characteristic.as( Trait.class );
return trait.getBaseCharacteristic().is( Collection.class ) && (trait.getConstraints().size() == 1) &&
trait.getConstraints().get( 0 ).is( LengthConstraint.class );
return trait.getBaseCharacteristic().is( Collection.class ) && (!trait.getConstraints().isEmpty());
}

private Map<String, Object> transformAbstractEntityProperty( final BasicProperty property, final boolean useModelExampleValue ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -150,6 +147,8 @@ public void testGenerateJsonForAspectWithCollectionOfEntities( final KnownVersio
assertThat( aspectWithEntityCollection.getTestList() ).hasSize( 1 );

final TestEntityWithSimpleTypes testEntityWithSimpleTypes = aspectWithEntityCollection.getTestList().get( 0 );

assertThat( generatedJson ).contains( "[" ).contains( "]" );
assertTestEntityWithSimpleTypes( testEntityWithSimpleTypes );
}

Expand Down Expand Up @@ -235,6 +234,7 @@ public void testGenerateJsonForAspectWithMultipleCollectionsOfSimpleType( final
final AspectWithMultipleCollectionsOfSimpleType aspectWithCollectionOfSimpleType = parseJson( generatedJson,
AspectWithMultipleCollectionsOfSimpleType.class );

assertThat( generatedJson ).contains( "[" ).contains( "]" );
assertThat( aspectWithCollectionOfSimpleType.getTestListInt() ).containsExactly( 35 );
assertThat( aspectWithCollectionOfSimpleType.getTestListString() ).containsExactly( "test string" );
}
Expand All @@ -246,6 +246,7 @@ public void testGenerateJsonForAspectWithCollectionOfSimpleType( final KnownVers

final AspectWithCollectionOfSimpleType aspectWithCollectionOfSimpleType = parseJson( generatedJson, AspectWithCollectionOfSimpleType.class );

assertThat( generatedJson ).contains( "[" ).contains( "]" );
assertThat( aspectWithCollectionOfSimpleType.getTestList() ).containsExactly( 35 );
}

Expand Down Expand Up @@ -303,6 +304,7 @@ public void testGenerateJsonForAspectWithComplextEntityCollectionEnum( final Kno
final List<AspectWithComplexEntityCollectionEnum.MyEntityTwo> myEntityTwoList = aspectWithComplexEntityCollectionEnum
.getMyPropertyOne().getValue()
.getEntityPropertyOne();
assertThat( generatedJson ).contains( "[" ).contains( "]" );
assertThat( myEntityTwoList ).hasSize( 1 );
assertThat( myEntityTwoList.get( 0 ).getEntityPropertyTwo() ).isEqualTo( "foo" );
}
Expand Down Expand Up @@ -584,6 +586,8 @@ public void testGenerateJsonForAspectWithCollectionWithAbstractEntity( final Kno
final Collection<AbstractTestEntity> testProperty = aspectWithCollectionWithAbstractEntity.getTestProperty();
assertThat( testProperty ).isNotEmpty();
final ExtendingTestEntity extendingTestEntity = (ExtendingTestEntity) testProperty.iterator().next();

assertThat( generatedJson ).contains( "[" ).contains( "]" );
assertThat( extendingTestEntity.getAbstractTestProperty() ).isNotNull();
assertThat( extendingTestEntity.getEntityProperty() ).isNotBlank();
}
Expand All @@ -604,6 +608,7 @@ public void testGenerateJsonForAspectWithAbstractSingleEntity( final KnownVersio
void testGenerateJsonForAspectWithConstrainedSetProperty( final KnownVersion metaModelVersion ) throws IOException {
final String generatedJson = generateJsonForModel( TestAspect.ASPECT_WITH_CONSTRAINED_SET, metaModelVersion );
final AspectWithConstrainedSet aspectWithConstrainedSet = parseJson( generatedJson, AspectWithConstrainedSet.class );
assertThat( generatedJson ).contains( "[" ).contains( "]" );
assertThat( aspectWithConstrainedSet.getTestProperty() ).hasSizeGreaterThan( 0 );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ The available options and their meaning can also be seen in the help text of the
| _--language, -l_ : The language from the model for which a JSON schema should be
generated (default: en) | `samm aspect AspectModel.ttl to schema -l de`
| _--custom-resolver_ : use an external resolver for the resolution of the model elements |
.4+| aspect <model> to aas | Generate Asset Administration Shell (AAS) submodel template for an Aspect Model | `samm aspect AspectModel.ttl to aas`
.4+| aspect <model> to aas | Generate an Asset Administration Shell (AAS) submodel template from an Aspect Model | `samm aspect AspectModel.ttl to aas`
| _--output, -o_ : output file path (default: stdout) |
| _--format, -f_ : output file format (xml, json, or aasx, default: xml) |
| _--custom-resolver_ : use an external resolver for the resolution of the model elements |
Expand Down

0 comments on commit e87ad2d

Please sign in to comment.