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

Commit b839481

Browse files
Working on deserialization, add deserialisation of Qualifiers
1 parent bf81b9d commit b839481

5 files changed

Lines changed: 122 additions & 11 deletions

File tree

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/deserialization/Aml2AasMapper.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,9 @@
1515
*/
1616
package io.adminshell.aas.v3.dataformat.aml.deserialization;
1717

18-
import io.adminshell.aas.v3.dataformat.aml.deserialization.mappers.AssetAdministrationShellEnvironmentMapper;
18+
import io.adminshell.aas.v3.dataformat.aml.deserialization.mappers.*;
1919
import io.adminshell.aas.v3.dataformat.aml.AmlDeserializationConfig;
2020
import io.adminshell.aas.v3.dataformat.aml.AmlDocumentInfo;
21-
import io.adminshell.aas.v3.dataformat.aml.deserialization.mappers.AssetAdministrationShellMapper;
22-
import io.adminshell.aas.v3.dataformat.aml.deserialization.mappers.EnumMapper;
23-
import io.adminshell.aas.v3.dataformat.aml.deserialization.mappers.IdentifiableMapper;
24-
import io.adminshell.aas.v3.dataformat.aml.deserialization.mappers.LangStringCollectionMapper;
25-
import io.adminshell.aas.v3.dataformat.aml.deserialization.mappers.ReferableMapper;
26-
import io.adminshell.aas.v3.dataformat.aml.deserialization.mappers.ReferenceElementMapper;
27-
import io.adminshell.aas.v3.dataformat.aml.deserialization.mappers.ReferenceMapper;
28-
import io.adminshell.aas.v3.dataformat.aml.deserialization.mappers.RelationshipElementMapper;
2921
import io.adminshell.aas.v3.dataformat.aml.model.caex.CAEXFile;
3022
import io.adminshell.aas.v3.dataformat.aml.serialization.naming.AbstractClassNamingStrategy;
3123
import io.adminshell.aas.v3.dataformat.aml.serialization.naming.NumberingClassNamingStrategy;
@@ -36,6 +28,9 @@
3628
import io.adminshell.aas.v3.model.Identifiable;
3729
import io.adminshell.aas.v3.model.MultiLanguageProperty;
3830
import io.adminshell.aas.v3.model.Referable;
31+
import io.adminshell.aas.v3.model.Qualifiable;
32+
33+
3934
import java.util.List;
4035

4136
/**
@@ -71,12 +66,15 @@ public AssetAdministrationShellEnvironment map(CAEXFile aml) throws MappingExcep
7166
mappingProvider.register(new ReferenceElementMapper());
7267
mappingProvider.register(new ReferableMapper<Referable>());
7368
mappingProvider.register(new IdentifiableMapper<Identifiable>());
69+
mappingProvider.register(new ConstraintCollectionMapper());
70+
mappingProvider.register(new QualifierMapper());
7471
AbstractClassNamingStrategy classNamingStrategy = new NumberingClassNamingStrategy();
7572

7673
PropertyNamingStrategy propertyNamingStrategy = new PropertyNamingStrategy();
7774
propertyNamingStrategy.registerCustomNaming(Referable.class, "descriptions", "description");
7875
propertyNamingStrategy.registerCustomNaming(MultiLanguageProperty.class, "values", "value");
79-
// propertyNamingStrategy.registerCustomNaming(Qualifier.class, x -> "qualifier:" + x.getType() + "=" + x.getValue(), false);
76+
//propertyNamingStrategy.registerCustomNaming(Qualifier.class, x -> "qualifier:" + x.getType() + "=" + x.getValue(), false);
77+
propertyNamingStrategy.registerCustomNaming(Qualifiable.class, "qualifiers", "qualifier","qualifier");
8078
MappingContext context = new MappingContext(mappingProvider, classNamingStrategy, propertyNamingStrategy, config.getTypeFactory());
8179
context.setDocumentInfo(AmlDocumentInfo.fromFile(aml));
8280
AssetAdministrationShellEnvironment result = context.map(AssetAdministrationShellEnvironment.class, parser);

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/deserialization/DefaultMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,9 @@ protected Class<?> typeFromAttribute(AttributeType attribute) throws MappingExce
237237
// alternative way to discover property but more expensive as all properties are considered and not only those defined on class
238238
// Optional<PropertyDescriptor> property = AasUtils.getAasProperties(type.get()).stream().filter(x -> x.getName().equals(type)).findFirst();
239239
try {
240+
//TODO: equals instead of contains. Use old name of PropertyNamingStrategy
240241
Optional<PropertyDescriptor> property = Stream.of(Introspector.getBeanInfo(type).getPropertyDescriptors())
241-
.filter(x -> x.getName().equals(attributePathElements[1])).findFirst();
242+
.filter(x -> x.getName().contains(attributePathElements[1])).findFirst();
242243
if (property.isPresent()) {
243244
return property.get().getReadMethod().getReturnType();
244245
} else {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.adminshell.aas.v3.dataformat.aml.deserialization.mappers;
17+
18+
import io.adminshell.aas.v3.dataformat.aml.deserialization.AmlParser;
19+
import io.adminshell.aas.v3.dataformat.aml.deserialization.DefaultMapper;
20+
import io.adminshell.aas.v3.dataformat.aml.deserialization.MappingContext;
21+
import io.adminshell.aas.v3.dataformat.aml.model.caex.AttributeType;
22+
import io.adminshell.aas.v3.dataformat.aml.model.caex.CAEXObject;
23+
import io.adminshell.aas.v3.dataformat.aml.model.caex.InternalElementType;
24+
import io.adminshell.aas.v3.dataformat.core.util.AasUtils;
25+
import io.adminshell.aas.v3.dataformat.mapping.MappingException;
26+
import io.adminshell.aas.v3.model.*;
27+
28+
import java.beans.PropertyDescriptor;
29+
import java.lang.reflect.InvocationTargetException;
30+
import java.util.ArrayList;
31+
import java.util.Collection;
32+
import java.util.List;
33+
34+
public class ConstraintCollectionMapper extends DefaultMapper<Collection<Constraint>> {
35+
36+
37+
@Override
38+
protected Collection mapCollectionValueProperty(AmlParser parser, MappingContext context) throws MappingException {
39+
40+
//TODO: Need to register specific type Qualifiable
41+
if (!context.getProperty().getName().equalsIgnoreCase("Qualifiers")) {
42+
return super.mapCollectionValueProperty(parser, context);
43+
}
44+
45+
List<AttributeType> values = findAttributes(parser.getCurrent(), x -> x.getRefSemantic().get(0).getCorrespondingAttributePath().contains("AAS:Qualifiable"));
46+
47+
CAEXObject current = parser.getCurrent();
48+
Collection result = new ArrayList<>();
49+
for (AttributeType value : values) {
50+
parser.setCurrent(value);
51+
Object o = context.withoutProperty().map(Qualifier.class, parser);
52+
result.add(o);
53+
}
54+
parser.setCurrent(current);
55+
return result;
56+
}
57+
58+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.adminshell.aas.v3.dataformat.aml.deserialization.mappers;
17+
18+
import io.adminshell.aas.v3.dataformat.aml.deserialization.AmlParser;
19+
import io.adminshell.aas.v3.dataformat.aml.deserialization.DefaultMapper;
20+
import io.adminshell.aas.v3.dataformat.aml.deserialization.MappingContext;
21+
import io.adminshell.aas.v3.dataformat.aml.model.caex.AttributeType;
22+
23+
import io.adminshell.aas.v3.dataformat.mapping.MappingException;
24+
import io.adminshell.aas.v3.model.*;
25+
import io.adminshell.aas.v3.model.impl.DefaultQualifier;
26+
27+
28+
/**
29+
*
30+
*/
31+
public class QualifierMapper extends DefaultMapper<Qualifier> {
32+
33+
@Override
34+
protected Qualifier fromAttribute(AmlParser parser, AttributeType attribute, MappingContext context) throws MappingException {
35+
if (parser == null || attribute == null || context == null) {
36+
return null;
37+
}
38+
39+
Qualifier result = (Qualifier) newInstance(DefaultQualifier.class, context);
40+
mapProperties(result, parser, context);
41+
return result;
42+
43+
}
44+
}

dataformat-core/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@
3939
<artifactId>classgraph</artifactId>
4040
<version>${classgraph.version}</version>
4141
</dependency>
42+
<dependency>
43+
<groupId>com.google.guava</groupId>
44+
<artifactId>guava</artifactId>
45+
<version>30.1.1-jre</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.apache.commons</groupId>
49+
<artifactId>commons-lang3</artifactId>
50+
<version>3.12.0</version>
51+
</dependency>
4252
</dependencies>
4353
<build>
4454
<plugins>

0 commit comments

Comments
 (0)