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

Commit 3dccc85

Browse files
committed
BUGFIX AML serializer now uses correct refSemantic for qualifiers (AAS:Qualifiable/qualifier instead of AAS:Qualifiable/qualifiers)
1 parent a68de65 commit 3dccc85

4 files changed

Lines changed: 71 additions & 26 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ public CAEXFile map(AssetAdministrationShellEnvironment env, AmlSerializationCon
7272
AbstractClassNamingStrategy classNamingStrategy = new NumberingClassNamingStrategy();
7373
classNamingStrategy.registerCustomNaming(LangString.class, x -> "aml-lang=" + x.getLanguage());
7474
PropertyNamingStrategy propertyNamingStrategy = new PropertyNamingStrategy();
75-
propertyNamingStrategy.registerCustomNaming(Referable.class, "descriptions", "description", true);
76-
propertyNamingStrategy.registerCustomNaming(MultiLanguageProperty.class, "values", "value", true);
77-
propertyNamingStrategy.registerCustomNaming(Qualifier.class, x -> "qualifier:" + x.getType() + "=" + x.getValue(), false);
75+
propertyNamingStrategy.registerCustomNaming(Referable.class, "descriptions", "description");
76+
propertyNamingStrategy.registerCustomNaming(MultiLanguageProperty.class, "values", "value");
77+
propertyNamingStrategy.registerCustomNaming(Qualifier.class, x -> "qualifier:" + x.getType() + "=" + x.getValue(), x -> "qualifier");
7878
MappingProvider<SourceBasedMapper> mappingProvider = new MappingProvider<>(
7979
SourceBasedMapper.class,
8080
new DefaultMapper(),

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.adminshell.aas.v3.dataformat.aml.serialization.mappers;
1717

18+
import io.adminshell.aas.v3.dataformat.aml.model.caex.AttributeType;
1819
import io.adminshell.aas.v3.dataformat.aml.serialization.AmlGenerator;
1920
import io.adminshell.aas.v3.dataformat.aml.serialization.MappingContext;
2021
import io.adminshell.aas.v3.dataformat.mapping.MappingException;
@@ -34,4 +35,14 @@ protected String getAttributeName(Qualifier value, MappingContext context) {
3435
value,
3536
context.getProperty().getName());
3637
}
38+
39+
@Override
40+
protected AttributeType.RefSemantic getRefSemantic(Qualifier value, AmlGenerator generator, MappingContext context) {
41+
return generator.refSemantic(
42+
context.getProperty(),
43+
context.getAttributeNamingStrategy().getNameForRefSemantic(
44+
Qualifier.class,
45+
value,
46+
context.getProperty().getName()));
47+
}
3748
}

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialization/naming/PropertyNamingStrategy.java

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.google.common.reflect.TypeToken;
1919
import io.adminshell.aas.v3.dataformat.core.util.MostSpecificTypeTokenComparator;
20+
import io.adminshell.aas.v3.model.Qualifier;
2021
import java.lang.reflect.Type;
2122
import java.util.ArrayList;
2223
import java.util.List;
@@ -31,40 +32,70 @@ public class PropertyNamingStrategy implements NamingStrategy {
3132

3233
protected class TypeSafeFunction<T> {
3334

34-
public TypeSafeFunction(Class<T> inputType, BiFunction<T, String, String> provider, boolean applyToRefSemantic) {
35+
public TypeSafeFunction(Class<T> inputType, BiFunction<T, String, String> nameProvider, BiFunction<T, String, String> refSemanticProvider) {
3536
this.inputType = TypeToken.of(inputType);
36-
this.provider = provider;
37-
this.applyToRefSemantic = applyToRefSemantic;
37+
this.nameProvider = nameProvider;
38+
this.refSemanticProvider = refSemanticProvider;
3839
}
3940
TypeToken inputType;
40-
BiFunction<T, String, String> provider;
41-
boolean applyToRefSemantic;
41+
BiFunction<T, String, String> nameProvider;
42+
BiFunction<T, String, String> refSemanticProvider;
4243
}
4344

44-
public <T> void registerCustomNaming(Class<T> type, BiFunction<T, String, String> provider, boolean applyToRefSemantic) {
45-
customNamings.add(new TypeSafeFunction(type, provider, applyToRefSemantic));
45+
public <T> void registerCustomNaming(Class<T> type,
46+
BiFunction<T, String, String> nameProvider) {
47+
customNamings.add(new TypeSafeFunction(type, nameProvider, nameProvider));
4648
}
4749

48-
public void registerCustomNaming(Class<?> type, String oldName, String newName, boolean applyToRefSemantic) {
49-
customNamings.add(new TypeSafeFunction(type, (obj, property) -> Objects.equals(oldName, property) ? newName : null, applyToRefSemantic));
50+
public <T> void registerCustomNaming(Class<T> type,
51+
BiFunction<T, String, String> nameProvider,
52+
BiFunction<T, String, String> refSemanticProvider) {
53+
customNamings.add(new TypeSafeFunction(type, nameProvider, refSemanticProvider));
5054
}
5155

52-
public <T> void registerCustomNaming(Class<T> type, Function<T, String> provider, boolean applyToRefSemantic) {
53-
customNamings.add(new TypeSafeFunction(type, (x, y) -> provider.apply((T) x), applyToRefSemantic));
56+
public void registerCustomNaming(Class<?> type,
57+
String oldName,
58+
String newName) {
59+
customNamings.add(new TypeSafeFunction(type,
60+
(obj, property) -> Objects.equals(oldName, property) ? newName : null,
61+
(obj, property) -> Objects.equals(oldName, property) ? newName : null));
5462
}
5563

56-
private List<TypeSafeFunction> getCustomNaming(Type type, String property, boolean applyToRefSemantic) {
64+
public void registerCustomNaming(Class<?> type,
65+
String oldName,
66+
String newName,
67+
String newRefSemantic) {
68+
customNamings.add(new TypeSafeFunction(type,
69+
(obj, property) -> Objects.equals(oldName, property) ? newName : null,
70+
(obj, property) -> Objects.equals(oldName, property) ? newRefSemantic : null));
71+
}
72+
73+
public <T> void registerCustomNaming(Class<T> type,
74+
Function<T, String> nameProvider) {
75+
customNamings.add(new TypeSafeFunction(type,
76+
(x, y) -> nameProvider.apply((T) x),
77+
(x, y) -> nameProvider.apply((T) x)));
78+
}
79+
80+
public <T> void registerCustomNaming(Class<T> type,
81+
Function<T, String> nameProvider,
82+
Function<T, String> refSemanticProvider) {
83+
customNamings.add(new TypeSafeFunction(type,
84+
(x, y) -> nameProvider.apply((T) x),
85+
(x, y) -> refSemanticProvider.apply((T) x)));
86+
}
87+
88+
private List<TypeSafeFunction> getCustomNaming(Type type, String property) {
5789
return customNamings.stream()
5890
.filter(x -> x.inputType.isSupertypeOf(type))
59-
.filter(x -> !applyToRefSemantic || x.applyToRefSemantic)
6091
.sorted((x, y) -> Objects.compare(x.inputType, y.inputType, new MostSpecificTypeTokenComparator()))
6192
.collect(Collectors.toList());
6293
}
6394

6495
@Override
6596
public String getName(Type type, Object obj, String property) {
66-
for (TypeSafeFunction customNaming : getCustomNaming(type, property, false)) {
67-
String result = (String) customNaming.provider.apply(obj, property);
97+
for (TypeSafeFunction customNaming : getCustomNaming(type, property)) {
98+
String result = (String) customNaming.nameProvider.apply(obj, property);
6899
if (result != null) {
69100
return result;
70101
}
@@ -74,8 +105,11 @@ public String getName(Type type, Object obj, String property) {
74105

75106
@Override
76107
public String getNameForRefSemantic(Type type, Object obj, String property) {
77-
for (TypeSafeFunction customNaming : getCustomNaming(type, property, true)) {
78-
String result = (String) customNaming.provider.apply(obj, property);
108+
if (Qualifier.class.equals(type) || property.startsWith("qualifier")) {
109+
String d = "";
110+
}
111+
for (TypeSafeFunction customNaming : getCustomNaming(type, property)) {
112+
String result = (String) customNaming.refSemanticProvider.apply(obj, property);
79113
if (result != null) {
80114
return result;
81115
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@
839839
<RefSemantic CorrespondingAttributePath="AAS:Referable/idShort"/>
840840
</Attribute>
841841
<Attribute Name="qualifier:http://acplt.org/Qualifier/ExampleQualifier=100">
842-
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifiers"/>
842+
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifier"/>
843843
<Attribute Name="type">
844844
<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>
845845
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/type"/>
@@ -854,7 +854,7 @@
854854
</Attribute>
855855
</Attribute>
856856
<Attribute Name="qualifier:http://acplt.org/Qualifier/ExampleQualifier2=50">
857-
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifiers"/>
857+
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifier"/>
858858
<Attribute Name="type">
859859
<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/ExampleQualifier2</Value>
860860
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/type"/>
@@ -1348,7 +1348,7 @@
13481348
<RefSemantic CorrespondingAttributePath="AAS:Referable/idShort"/>
13491349
</Attribute>
13501350
<Attribute Name="qualifier:http://acplt.org/Qualifier/ExampleQualifier=null">
1351-
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifiers"/>
1351+
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifier"/>
13521352
<Attribute Name="type">
13531353
<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>
13541354
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/type"/>
@@ -1386,7 +1386,7 @@
13861386
<RefSemantic CorrespondingAttributePath="AAS:Referable/idShort"/>
13871387
</Attribute>
13881388
<Attribute Name="qualifier:http://acplt.org/Qualifier/ExampleQualifier=null">
1389-
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifiers"/>
1389+
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifier"/>
13901390
<Attribute Name="type">
13911391
<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>
13921392
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/type"/>
@@ -1424,7 +1424,7 @@
14241424
<RefSemantic CorrespondingAttributePath="AAS:Referable/idShort"/>
14251425
</Attribute>
14261426
<Attribute Name="qualifier:http://acplt.org/Qualifier/ExampleQualifier=null">
1427-
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifiers"/>
1427+
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifier"/>
14281428
<Attribute Name="type">
14291429
<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>
14301430
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/type"/>
@@ -1545,7 +1545,7 @@
15451545
<RefSemantic CorrespondingAttributePath="AAS:Referable/idShort"/>
15461546
</Attribute>
15471547
<Attribute Name="qualifier:http://acplt.org/Qualifier/ExampleQualifier=null">
1548-
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifiers"/>
1548+
<RefSemantic CorrespondingAttributePath="AAS:Qualifiable/qualifier"/>
15491549
<Attribute Name="type">
15501550
<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>
15511551
<RefSemantic CorrespondingAttributePath="AAS:Qualifier/type"/>

0 commit comments

Comments
 (0)