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

Commit 5106685

Browse files
committed
Add view mapping
1 parent 138dffd commit 5106685

12 files changed

Lines changed: 144 additions & 9002 deletions

File tree

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ public AmlSerializer(boolean enableClassLibs) {
7272
public String write(AssetAdministrationShellEnvironment aasEnvironment) throws SerializationException {
7373
try {
7474
CAEXFile caexFile = modelTransformation(aasEnvironment);
75-
String result = convertXml(caexFile);
75+
String xml = convertXml(caexFile);
76+
String cleanUp = cleanUpXml(xml);
77+
String result = cleanUp;
7678
if (enableClassLibs) {
77-
result = addClassLibs(cleanUpXml(result));
79+
result = addClassLibs(cleanUp);
7880
}
7981
return result;
8082
} catch (JsonProcessingException ex) {
@@ -156,13 +158,17 @@ private CAEXFile modelTransformation(AssetAdministrationShellEnvironment environ
156158
// Inside shell loop
157159
forEachWithCounter(administrationShells, (i, administrationShell) -> {
158160
// Map asset info to internal element
159-
AssetInformation asset = administrationShell.getAssetInformation();
160-
InternalElement assetInternalElement = mapper.map(asset, InternalElement.class);
161-
shellInternalElements.get(i).setInternalElements(new ArrayList<InternalElement>() {
162-
{
163-
add(assetInternalElement);
164-
}
165-
});
161+
// AssetInformation asset = administrationShell.getAssetInformation();
162+
// InternalElement assetInternalElement = mapper.map(asset, InternalElement.class);
163+
// shellInternalElements.get(i).setInternalElements(new ArrayList<>() {
164+
// {
165+
// add(assetInternalElement);
166+
// }
167+
// });
168+
169+
// // Map view
170+
// List<InternalElement> viewInternalElements = mapper.mapAsList(administrationShell.getViews(), InternalElement.class);
171+
// shellInternalElements.addAll(viewInternalElements);
166172

167173
// // Map all submodels to internal elements
168174
// forEachWithCounter(administrationShell.getSubmodels(), (j, submodel) -> {

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/model/caex/AASNamespace.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public enum AASNamespace {
4343
Qualifier_ValueId("Qualifier/valueId"),
4444
AssetAdministrationShell_DerivedFrom("AssetAdministrationShell/derivedFrom"),
4545
Asset_AssetIdentificationModel("Asset/assetIdentificationModel"),
46+
AssetAdministrationShell_AssetInformation("AssetAdministrationShell/assetInformation"),
47+
AssetInformation_AssetKind("AssetInformation/assetKind"),
48+
AssetInformation_GlobalAssetId("AssetInformation/globalAssetId"),
4649
AssetAdministrationShell_Submodels("AssetAdministrationShell/submodels"),
4750
Property_Value("Property/value"),
4851
MultiLanguageProperty_Value("MultiLanguageProperty/value"),
@@ -62,7 +65,11 @@ public enum AASNamespace {
6265
RelationshipElement_Second("RelationshipElement/second"),
6366
IdentifierKeyValuePair_Key("IdentifierKeyValuePair/key"),
6467
IdentifierKeyValuePair_Value("IdentifierKeyValuePair/value"),
65-
BillOfMaterial_Reference("BillOfMaterial/reference");
68+
BillOfMaterial_Reference("BillOfMaterial/reference"),
69+
// View
70+
AssetAdministrationShell_View("AssetAdministrationShell/view"),
71+
View_ContainedElement("View/containedElement"),
72+
View_IdShort("View/idShort");
6673

6774
private String refSemantic;
6875

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialize/mapper/AASEnvironmentMapper.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import io.adminshell.aas.v3.dataformat.aml.serialize.mapper.mapper.SubmodelElementCollectionMapper;
5252
import io.adminshell.aas.v3.dataformat.aml.serialize.mapper.mapper.SubmodelElementMapper;
5353
import io.adminshell.aas.v3.dataformat.aml.serialize.mapper.mapper.SubmodelMapper;
54-
import io.adminshell.aas.v3.dataformat.aml.serialize.mapper.mapper.ViewMapper;
5554
import io.adminshell.aas.v3.model.*;
5655
import ma.glasnost.orika.MapperFactory;
5756
import ma.glasnost.orika.impl.ConfigurableMapper;
@@ -132,15 +131,6 @@ protected void configure(MapperFactory factory) {
132131
.customize(new AssetAdministrationShellMapper())
133132
.register();
134133

135-
// View mapping
136-
factory.classMap(View.class, InternalElement.class)
137-
.mapNulls(true)
138-
.fieldMap("semanticId", "attributes[0]")
139-
.converter(SemanticIdToAttributeConverter.class.getName()).add()
140-
.byDefault()
141-
.customize(new ViewMapper())
142-
.register();
143-
144134
// // Asset information mapping
145135
// factory.classMap(AssetInformation.class, InternalElement.class)
146136
// .mapNulls(true)

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialize/mapper/converter/IdShortToAttributeConverter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.adminshell.aas.v3.dataformat.aml.model.caex.AASNamespace;
1919
import io.adminshell.aas.v3.dataformat.aml.model.caex.Attribute;
2020
import io.adminshell.aas.v3.dataformat.aml.model.caex.RefSemantic;
21+
import io.adminshell.aas.v3.dataformat.aml.serialize.mapper.util.UrlEncoderUtil;
2122
import ma.glasnost.orika.CustomConverter;
2223
import ma.glasnost.orika.MappingContext;
2324
import ma.glasnost.orika.metadata.Type;
@@ -26,6 +27,10 @@ public class IdShortToAttributeConverter extends CustomConverter<String, Attribu
2627

2728
@Override
2829
public Attribute convert(String source, Type<? extends Attribute> destinationType, MappingContext mappingContext) {
30+
if(source == null) {
31+
return null;
32+
}
33+
2934
return new Attribute(
3035
"idShort",
3136
null,

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialize/mapper/converter/IdShortToNameConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public class IdShortToNameConverter extends CustomConverter<String, String> {
2525

2626
@Override
2727
public String convert(String source, Type<? extends String> destinationType, MappingContext mappingContext) {
28-
if (source == null) {
29-
return UUID.randomUUID().toString();
28+
if(source == null) {
29+
return null;
3030
}
3131

3232
return source;

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialize/mapper/mapper/AssetAdministrationShellMapper.java

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,45 @@ public class AssetAdministrationShellMapper extends CustomMapper<AssetAdministra
3434
public void mapAtoB(AssetAdministrationShell assetAdministrationShell, InternalElement internalElement, MappingContext context) {
3535
internalElement.setRoleRequirements(new RoleRequirements(AssetAdministrationShellRoleClassLib.AssetAdministrationShell.getRefBaseRoleClassPath()));
3636

37-
// asset information
38-
// submodel references
39-
Attribute submodels = new Attribute(
40-
"submodels",
37+
// AssetInformation
38+
Attribute assetInformation = new Attribute(
39+
"assetInformation",
4140
null,
4241
null,
4342
null,
44-
new RefSemantic(AASNamespace.AssetAdministrationShell_Submodels.getRefSemantic()),
43+
new RefSemantic(AASNamespace.AssetAdministrationShell_AssetInformation.getRefSemantic()),
4544
null
4645
);
47-
submodels.setAttributes(new ArrayList<>());
46+
assetInformation.setAttributes(new ArrayList<>());
47+
assetInformation.getAttributes().add(new Attribute(
48+
"assetKind",
49+
null,
50+
null,
51+
assetAdministrationShell.getAssetInformation().getAssetKind().name(),
52+
new RefSemantic(AASNamespace.AssetInformation_AssetKind.getRefSemantic()),
53+
null
54+
));
55+
assetInformation.getAttributes().add(new Attribute(
56+
"globalAssetId",
57+
null,
58+
null,
59+
ReferenceConverterUtil.convert(assetAdministrationShell.getAssetInformation().getGlobalAssetId()),
60+
new RefSemantic(AASNamespace.AssetInformation_GlobalAssetId.getRefSemantic()),
61+
null
62+
));
63+
internalElement.getAttributes().add(assetInformation);
64+
65+
// Submodels
4866
assetAdministrationShell.getSubmodels().forEach(submodel -> {
67+
Attribute submodels = new Attribute(
68+
"submodel",
69+
null,
70+
null,
71+
null,
72+
new RefSemantic(AASNamespace.AssetAdministrationShell_Submodels.getRefSemantic()),
73+
null
74+
);
75+
submodels.setAttributes(new ArrayList<>());
4976
submodels.getAttributes().add(new Attribute(
5077
"reference",
5178
null,
@@ -54,7 +81,39 @@ public void mapAtoB(AssetAdministrationShell assetAdministrationShell, InternalE
5481
new RefSemantic(AASNamespace.ReferenceElement_Value.getRefSemantic()),
5582
null
5683
));
84+
internalElement.getAttributes().add(submodels);
85+
});
86+
87+
// View
88+
assetAdministrationShell.getViews().forEach(view -> {
89+
Attribute views = new Attribute(
90+
"view",
91+
null,
92+
null,
93+
null,
94+
new RefSemantic(AASNamespace.AssetAdministrationShell_View.getRefSemantic()),
95+
null
96+
);
97+
views.setAttributes(new ArrayList<>());
98+
views.getAttributes().add(new Attribute(
99+
"idShort",
100+
null,
101+
null,
102+
view.getIdShort(),
103+
new RefSemantic(AASNamespace.View_IdShort.getRefSemantic()),
104+
null
105+
));
106+
if(!view.getContainedElements().isEmpty()) {
107+
views.getAttributes().add(new Attribute(
108+
"containedElement",
109+
null,
110+
null,
111+
ReferenceConverterUtil.convert(view.getContainedElements().get(0)),
112+
new RefSemantic(AASNamespace.View_ContainedElement.getRefSemantic()),
113+
null
114+
));
115+
}
116+
internalElement.getAttributes().add(views);
57117
});
58-
internalElement.getAttributes().add(submodels);
59118
}
60119
}

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialize/mapper/mapper/ReferableMapper.java

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

18+
import io.adminshell.aas.v3.dataformat.aml.model.caex.AASNamespace;
19+
import io.adminshell.aas.v3.dataformat.aml.model.caex.Attribute;
1820
import io.adminshell.aas.v3.dataformat.aml.model.caex.InternalElement;
21+
import io.adminshell.aas.v3.dataformat.aml.model.caex.RefSemantic;
1922
import io.adminshell.aas.v3.model.Referable;
2023
import ma.glasnost.orika.CustomMapper;
2124
import ma.glasnost.orika.MappingContext;

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialize/mapper/mapper/ViewMapper.java

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.adminshell.aas.v3.dataformat.aml.serialize.mapper.util;
2+
3+
import java.net.URLEncoder;
4+
import java.nio.charset.StandardCharsets;
5+
6+
public class UrlEncoderUtil {
7+
8+
public static String encode(String url) {
9+
return URLEncoder.encode(url, StandardCharsets.UTF_8);
10+
}
11+
}

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,22 +1569,25 @@ public class FullExample {
15691569

15701570
public static final AssetAdministrationShellEnvironment ENVIRONMENT = new DefaultAssetAdministrationShellEnvironment.Builder()
15711571
.assetAdministrationShells(Arrays.asList(
1572-
AAS_1,
1573-
AAS_2,
1574-
AAS_3,
1575-
AAS_4))
1572+
// AAS_1,
1573+
// AAS_2,
1574+
AAS_3
1575+
// AAS_4
1576+
))
15761577
.submodels(Arrays.asList(
1577-
SUBMODEL_1,
1578-
SUBMODEL_2,
1579-
SUBMODEL_3,
1580-
SUBMODEL_4,
1581-
SUBMODEL_5,
1582-
SUBMODEL_6,
1583-
SUBMODEL_7))
1578+
// SUBMODEL_1,
1579+
// SUBMODEL_2,
1580+
// SUBMODEL_3,
1581+
// SUBMODEL_4,
1582+
// SUBMODEL_5,
1583+
// SUBMODEL_6,
1584+
// SUBMODEL_7
1585+
))
15841586
.conceptDescriptions(Arrays.asList(
1585-
CONCEPT_DESCRIPTION_1,
1586-
CONCEPT_DESCRIPTION_2,
1587-
CONCEPT_DESCRIPTION_3,
1588-
CONCEPT_DESCRIPTION_4))
1587+
// CONCEPT_DESCRIPTION_1,
1588+
// CONCEPT_DESCRIPTION_2,
1589+
// CONCEPT_DESCRIPTION_3,
1590+
// CONCEPT_DESCRIPTION_4
1591+
))
15891592
.build();
15901593
}

0 commit comments

Comments
 (0)