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

Commit 391a3ac

Browse files
Working on deserialization, add deserialization of Range
1 parent 493838e commit 391a3ac

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public AssetAdministrationShellEnvironment map(CAEXFile aml) throws MappingExcep
7070
mappingProvider.register(new QualifierMapper());
7171
mappingProvider.register(new OperationCollectionMapper());
7272
mappingProvider.register(new FileMapper());
73+
mappingProvider.register(new RangeMapper());
7374
AbstractClassNamingStrategy classNamingStrategy = new NumberingClassNamingStrategy();
7475

7576
PropertyNamingStrategy propertyNamingStrategy = new PropertyNamingStrategy();

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,14 @@ protected Object propertyFromAttribute(AmlParser parser, AttributeType attribute
338338
return result;
339339
}
340340

341+
protected String getDataTypeFromAttribute(AttributeType attributeType){
342+
if(attributeType == null || attributeType.getAttributeDataType() == null){
343+
return null;
344+
}
345+
String attributeDataType = attributeType.getAttributeDataType();
346+
return attributeDataType.substring(attributeDataType.lastIndexOf(":") + 1);
347+
}
348+
341349
protected boolean skipProperty(PropertyDescriptor property) {
342350
return ignoredProperties.contains(property.getName());
343351
}
@@ -436,6 +444,5 @@ protected List<InterfaceClassType> findExternalInterface(CAEXObject parent, Pred
436444
return ((InternalElementType) parent).getExternalInterface().stream().filter(filter).collect(Collectors.toList());
437445
}
438446
return List.of();
439-
440447
}
441448
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.core.util.AasUtils;
23+
import io.adminshell.aas.v3.dataformat.mapping.MappingException;
24+
import io.adminshell.aas.v3.model.Range;
25+
26+
import java.beans.PropertyDescriptor;
27+
import java.util.List;
28+
29+
/**
30+
*
31+
*/
32+
public class RangeMapper extends DefaultMapper<Range> {
33+
34+
public static final String MIN_ATTRIBUTE_NAME = "min";
35+
public static final String MAX_ATTRIBUTE_NAME = "max";
36+
protected static PropertyDescriptor PROPERTY_VALUE_TYPE = AasUtils.getProperty(Range.class, "valueType");
37+
38+
public RangeMapper() {
39+
super(PROPERTY_VALUE_TYPE.getName());
40+
}
41+
42+
@Override
43+
protected void mapProperties(Object parent, AmlParser parser, MappingContext context) throws MappingException {
44+
if (parent == null || context == null) {
45+
return;
46+
}
47+
48+
AttributeType attributeTypeMin = findAttributes(parser.getCurrent(),
49+
x -> x.getName().equalsIgnoreCase(MIN_ATTRIBUTE_NAME)).stream().findFirst().orElse(null);
50+
51+
AttributeType attributeTypeMax = findAttributes(parser.getCurrent(),
52+
x -> x.getName().equalsIgnoreCase(MAX_ATTRIBUTE_NAME)).stream().findFirst().orElse(null);
53+
54+
if (attributeTypeMax == null || attributeTypeMin == null)
55+
throw new MappingException(String.format("no min/max attributes are found in range %s %s", parser.getCurrent().getID(), parser.getCurrent().getName()));
56+
57+
String dataTypeMin = getDataTypeFromAttribute(attributeTypeMin);
58+
String dataTypeMax = getDataTypeFromAttribute(attributeTypeMax);
59+
60+
//TODO: is that a constraint?
61+
if (!dataTypeMax.equalsIgnoreCase(dataTypeMin))
62+
throw new MappingException(String.format("min/max attributes in range %s %s has different attribute datatypes", parser.getCurrent().getID(), parser.getCurrent().getName()));
63+
64+
((Range) parent).setValueType(dataTypeMax);
65+
66+
super.mapProperties(parent, parser, context);
67+
}
68+
69+
}

0 commit comments

Comments
 (0)