Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit f3169a0

Browse files
committed
Bugfix AML Serializer - serialize datatype for Qualifier with value == null
1 parent dff58bb commit f3169a0

4 files changed

Lines changed: 80 additions & 26 deletions

File tree

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialization/mappers/AbstractElementMapperWithValueType.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,27 @@ protected AttributeType.Builder toAttribute(T value, AmlGenerator generator, Map
103103
.copyOf(original)
104104
.withAttribute(untouchedAttributes);
105105
for (String property : typedProperties) {
106+
AttributeType.Builder typedAttributeBuilder;
106107
Optional<AttributeType> attributeToType = original.getAttribute().stream()
107108
.filter(x -> property.equals(x.getName()))
108109
.findFirst();
109110
if (attributeToType.isPresent()) {
110-
AttributeType.Builder typedAttributeBuilder = AttributeType.copyOf(attributeToType.get());
111-
if (valueTypeProperty.isPresent()) {
112-
try {
113-
typedAttributeBuilder = typedAttributeBuilder.withAttributeDataType(
114-
PROPERTY_VALUE_TYPE_NAMESPACE_PREFIX + valueTypeProperty.get().getReadMethod().invoke(value));
115-
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
116-
throw new MappingException(String.format("error reading property %s", PROPERTY_VALUE_TYPE_NAME));
117-
}
111+
typedAttributeBuilder = AttributeType.copyOf(attributeToType.get());
112+
} else {
113+
typedAttributeBuilder = super.toAttribute(null, generator, context
114+
.with(AasUtils.getProperty(value, property)));
115+
}
116+
Object type = null;
117+
if (valueTypeProperty.isPresent()) {
118+
try {
119+
type = valueTypeProperty.get().getReadMethod().invoke(value);
120+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
121+
throw new MappingException(String.format("error reading property %s", PROPERTY_VALUE_TYPE_NAME));
122+
}
123+
}
124+
if (attributeToType.isPresent() || type != null) {
125+
if (type != null) {
126+
typedAttributeBuilder = typedAttributeBuilder.withAttributeDataType(PROPERTY_VALUE_TYPE_NAMESPACE_PREFIX + type);
118127
}
119128
builder = builder.addAttribute(typedAttributeBuilder.build());
120129
}

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialization/mappers/QualifierMapper.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,25 @@ public void map(Qualifier value, AmlGenerator generator, MappingContext context)
3030

3131
@Override
3232
protected String getAttributeName(Qualifier value, MappingContext context) {
33-
return context.getPropertyNamingStrategy().getName(
34-
Qualifier.class,
35-
value,
36-
context.getProperty().getName());
33+
if (value != null && Qualifier.class.isAssignableFrom(value.getClass())) {
34+
return context.getPropertyNamingStrategy().getName(
35+
Qualifier.class,
36+
value,
37+
context.getProperty().getName());
38+
}
39+
return super.getAttributeName(value, context);
3740
}
3841

3942
@Override
4043
protected AttributeType.RefSemantic getRefSemantic(Qualifier value, AmlGenerator generator, MappingContext context) {
41-
return generator.refSemantic(
42-
context.getProperty(),
43-
context.getPropertyNamingStrategy().getNameForRefSemantic(
44-
Qualifier.class,
45-
value,
46-
context.getProperty().getName()));
44+
if (value != null && Qualifier.class.isAssignableFrom(value.getClass())) {
45+
return generator.refSemantic(
46+
context.getProperty(),
47+
context.getPropertyNamingStrategy().getNameForRefSemantic(
48+
Qualifier.class,
49+
value,
50+
context.getProperty().getName()));
51+
}
52+
return super.getRefSemantic(value, generator, context);
4753
}
4854
}

dataformat-aml/src/test/java/io/adminshell/aas/v3/dataformat/aml/fixtures/FullExample.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -874,14 +874,14 @@ public class FullExample {
874874
.value(new DefaultProperty.Builder()
875875
.idShort("ExampleProperty")
876876
.value(null)
877-
//.valueType("string")
877+
.valueType("string")
878878
.build())
879879
.value(new DefaultMultiLanguageProperty.Builder()
880880
.idShort("ExampleMultiLanguageProperty")
881881
.build())
882882
.value(new DefaultRange.Builder()
883883
.idShort("ExampleRange")
884-
//.valueType("int")
884+
.valueType("int")
885885
.min(null)
886886
.max(null)
887887
.build())
@@ -1064,7 +1064,7 @@ public class FullExample {
10641064
.build())
10651065
.build())
10661066
.qualifier(new DefaultQualifier.Builder()
1067-
//.valueType("string")
1067+
.valueType("string")
10681068
.type("http://acplt.org/Qualifier/ExampleQualifier")
10691069
.build())
10701070
.value("exampleValue")
@@ -1085,7 +1085,7 @@ public class FullExample {
10851085
.build())
10861086
.build())
10871087
.qualifier(new DefaultQualifier.Builder()
1088-
//.valueType("string")
1088+
.valueType("string")
10891089
.type("http://acplt.org/Qualifier/ExampleQualifier")
10901090
.build())
10911091
.value("exampleValue")
@@ -1106,7 +1106,7 @@ public class FullExample {
11061106
.build())
11071107
.build())
11081108
.qualifier(new DefaultQualifier.Builder()
1109-
//.valueType("string")
1109+
.valueType("string")
11101110
.type("http://acplt.org/Qualifier/ExampleQualifier")
11111111
.build())
11121112
.value("exampleValue")
@@ -1182,7 +1182,7 @@ public class FullExample {
11821182
.build())
11831183
.build())
11841184
.qualifier(new DefaultQualifier.Builder()
1185-
//.valueType("string")
1185+
.valueType("string")
11861186
.type("http://acplt.org/Qualifier/ExampleQualifier")
11871187
.build())
11881188
.value("exampleValue")
@@ -1634,7 +1634,7 @@ public class FullExample {
16341634

16351635
public final static ConceptDescription CONCEPT_DESCRIPTION_1 = new DefaultConceptDescription.Builder()
16361636
.idShort("TestConceptDescription")
1637-
.description(new LangString("An example concept description for the test application", "en-us"))
1637+
.description(new LangString("An example concept description for the test application", "en-us"))
16381638
.description(new LangString("Ein Beispiel-ConceptDescription für eine Test-Anwendung", "de"))
16391639
.identification(new DefaultIdentifier.Builder()
16401640
.idType(IdentifierType.IRI)
@@ -1663,7 +1663,7 @@ public class FullExample {
16631663

16641664
public final static ConceptDescription CONCEPT_DESCRIPTION_3 = new DefaultConceptDescription.Builder()
16651665
.idShort("TestConceptDescription1")
1666-
.description(new LangString("An example concept description for the test application", "en-us"))
1666+
.description(new LangString("An example concept description for the test application", "en-us"))
16671667
.description(new LangString("Ein Beispiel-ConceptDescription für eine Test-Anwendung", "de"))
16681668
.identification(new DefaultIdentifier.Builder()
16691669
.idType(IdentifierType.IRI)

dataformat-aml/src/test/resources/test_demo_full_example.aml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,9 @@
10261026
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">ExampleProperty</Value>
10271027
<RefSemantic CorrespondingAttributePath="AAS:Referable/idShort"/>
10281028
</Attribute>
1029+
<Attribute Name="value" AttributeDataType="xs:string">
1030+
<RefSemantic CorrespondingAttributePath="AAS:Property/value"/>
1031+
</Attribute>
10291032
<ExternalInterface ID="59" Name="ReferableReference" RefBaseClassPath="AssetAdministrationShellInterfaceClassLib/ReferableReference"/>
10301033
<RoleRequirements RefBaseRoleClassPath="AssetAdministrationShellRoleClassLib/Property"/>
10311034
</InternalElement>
@@ -1042,6 +1045,12 @@
10421045
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">ExampleRange</Value>
10431046
<RefSemantic CorrespondingAttributePath="AAS:Referable/idShort"/>
10441047
</Attribute>
1048+
<Attribute Name="min" AttributeDataType="xs:int">
1049+
<RefSemantic CorrespondingAttributePath="AAS:Range/min"/>
1050+
</Attribute>
1051+
<Attribute Name="max" AttributeDataType="xs:int">
1052+
<RefSemantic CorrespondingAttributePath="AAS:Range/max"/>
1053+
</Attribute>
10451054
<RoleRequirements RefBaseRoleClassPath="AssetAdministrationShellRoleClassLib/Range"/>
10461055
</InternalElement>
10471056
<RoleRequirements RefBaseRoleClassPath="AssetAdministrationShellRoleClassLib/SubmodelElementCollection"/>
@@ -1366,6 +1375,9 @@
13661375
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">http://acplt.org/Qualifier/ExampleQualifier</Value>
13671376
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/type"/>
13681377
</Attribute>
1378+
<Attribute Name="value" AttributeDataType="xs:string">
1379+
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/value"/>
1380+
</Attribute>
13691381
</Attribute>
13701382
<Attribute Name="semanticId">
13711383
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">(GlobalReference)[IRI]http://acplt.org/Properties/ExampleProperty</Value>
@@ -1404,6 +1416,9 @@
14041416
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">http://acplt.org/Qualifier/ExampleQualifier</Value>
14051417
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/type"/>
14061418
</Attribute>
1419+
<Attribute Name="value" AttributeDataType="xs:string">
1420+
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/value"/>
1421+
</Attribute>
14071422
</Attribute>
14081423
<Attribute Name="semanticId">
14091424
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">(GlobalReference)[IRI]http://acplt.org/Properties/ExampleProperty</Value>
@@ -1442,6 +1457,9 @@
14421457
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">http://acplt.org/Qualifier/ExampleQualifier</Value>
14431458
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/type"/>
14441459
</Attribute>
1460+
<Attribute Name="value" AttributeDataType="xs:string">
1461+
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/value"/>
1462+
</Attribute>
14451463
</Attribute>
14461464
<Attribute Name="semanticId">
14471465
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">(GlobalReference)[IRI]http://acplt.org/Properties/ExampleProperty</Value>
@@ -1563,6 +1581,9 @@
15631581
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">http://acplt.org/Qualifier/ExampleQualifier</Value>
15641582
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/type"/>
15651583
</Attribute>
1584+
<Attribute Name="value" AttributeDataType="xs:string">
1585+
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/value"/>
1586+
</Attribute>
15661587
</Attribute>
15671588
<Attribute Name="semanticId">
15681589
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">(GlobalReference)[IRI]http://acplt.org/Properties/ExampleProperty</Value>
@@ -3374,6 +3395,9 @@
33743395
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">ExampleProperty</Value>
33753396
<RefSemantic CorrespondingAttributePath="AAS:Referable/idShort"/>
33763397
</Attribute>
3398+
<Attribute Name="value" AttributeDataType="xs:string">
3399+
<RefSemantic CorrespondingAttributePath="AAS:Property/value"/>
3400+
</Attribute>
33773401
<ExternalInterface ID="131" Name="ReferableReference" RefBaseClassPath="AssetAdministrationShellInterfaceClassLib/ReferableReference"/>
33783402
<RoleRequirements RefBaseRoleClassPath="AssetAdministrationShellRoleClassLib/Property"/>
33793403
</InternalElement>
@@ -3390,6 +3414,12 @@
33903414
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">ExampleRange</Value>
33913415
<RefSemantic CorrespondingAttributePath="AAS:Referable/idShort"/>
33923416
</Attribute>
3417+
<Attribute Name="min" AttributeDataType="xs:int">
3418+
<RefSemantic CorrespondingAttributePath="AAS:Range/min"/>
3419+
</Attribute>
3420+
<Attribute Name="max" AttributeDataType="xs:int">
3421+
<RefSemantic CorrespondingAttributePath="AAS:Range/max"/>
3422+
</Attribute>
33933423
<RoleRequirements RefBaseRoleClassPath="AssetAdministrationShellRoleClassLib/Range"/>
33943424
</InternalElement>
33953425
<RoleRequirements RefBaseRoleClassPath="AssetAdministrationShellRoleClassLib/SubmodelElementCollection"/>
@@ -3571,6 +3601,9 @@
35713601
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">ExampleProperty</Value>
35723602
<RefSemantic CorrespondingAttributePath="AAS:Referable/idShort"/>
35733603
</Attribute>
3604+
<Attribute Name="value" AttributeDataType="xs:string">
3605+
<RefSemantic CorrespondingAttributePath="AAS:Property/value"/>
3606+
</Attribute>
35743607
<ExternalInterface ID="159" Name="ReferableReference" RefBaseClassPath="AssetAdministrationShellInterfaceClassLib/ReferableReference"/>
35753608
<RoleRequirements RefBaseRoleClassPath="AssetAdministrationShellRoleClassLib/Property"/>
35763609
</InternalElement>
@@ -3587,6 +3620,12 @@
35873620
<Value xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">ExampleRange</Value>
35883621
<RefSemantic CorrespondingAttributePath="AAS:Referable/idShort"/>
35893622
</Attribute>
3623+
<Attribute Name="min" AttributeDataType="xs:int">
3624+
<RefSemantic CorrespondingAttributePath="AAS:Range/min"/>
3625+
</Attribute>
3626+
<Attribute Name="max" AttributeDataType="xs:int">
3627+
<RefSemantic CorrespondingAttributePath="AAS:Range/max"/>
3628+
</Attribute>
35903629
<RoleRequirements RefBaseRoleClassPath="AssetAdministrationShellRoleClassLib/Range"/>
35913630
</InternalElement>
35923631
<RoleRequirements RefBaseRoleClassPath="AssetAdministrationShellRoleClassLib/SubmodelElementCollection"/>

0 commit comments

Comments
 (0)