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

Commit b38c1b0

Browse files
Merge branch 'bugfix/serialization' into bugfix/reference-deserialization
2 parents 1dfd9d8 + a127c87 commit b38c1b0

13 files changed

Lines changed: 2340 additions & 39 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This workflow will deploy the Serializers and the Validator to the sonatype
2+
# staging environment. This will NOT automatically publish the artifacts. An
3+
# authorized user must still manually close the staging repository first.
4+
5+
name: Generate and Deploy to Sonatype
6+
7+
on:
8+
release:
9+
types: [published]
10+
11+
jobs:
12+
13+
deploy:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Set up JDK 1.8
19+
uses: actions/setup-java@v2
20+
with:
21+
java-version: 11
22+
distribution: 'adopt'
23+
server-id: ossrh
24+
server-username: OSSRH_USERNAME
25+
server-password: OSSRH_PASSWORD
26+
gpg-private-key: ${{ secrets.MYGPGKEY_SEC }}
27+
28+
- name: Publish to Apache Maven Central
29+
run: mvn -P MavenCentral license:format deploy
30+
env:
31+
OSSRH_USERNAME: sebbader
32+
OSSRH_PASSWORD: ${{ secrets.SEBBADER_OSSHR_PASSWORD }}
33+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSWORD }}
34+
GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSWORD }}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# This workflow will build a package using Maven and then publish it to GitHub packages when a PR is accepted/new content is pushed
2+
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
3+
4+
name: Maven Publish Snapshot
5+
6+
on:
7+
push:
8+
branches:
9+
- development
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Set up JDK 11
22+
uses: actions/setup-java@v2
23+
with:
24+
java-version: '11'
25+
distribution: 'adopt'
26+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
27+
settings-path: ${{ github.workspace }} # location for the settings.xml file
28+
29+
- name: Build with Maven
30+
run: mvn -B package --file pom.xml
31+
32+
- name: Delete old dataformat-parent package
33+
uses: actions/delete-package-versions@v1
34+
continue-on-error: true
35+
with:
36+
package-name: 'io.admin-shell.aas.dataformat-parent'
37+
38+
- name: Delete old dataformat-core package
39+
uses: actions/delete-package-versions@v1
40+
continue-on-error: true
41+
with:
42+
package-name: 'io.admin-shell.aas.dataformat-core'
43+
44+
- name: Delete old dataformat-aasx package
45+
uses: actions/delete-package-versions@v1
46+
continue-on-error: true
47+
with:
48+
package-name: 'io.admin-shell.aas.dataformat-aasx'
49+
50+
- name: Delete old dataformat-xml package
51+
uses: actions/delete-package-versions@v1
52+
continue-on-error: true
53+
with:
54+
package-name: 'io.admin-shell.aas.dataformat-xml'
55+
56+
- name: Delete old dataformat-aml package
57+
uses: actions/delete-package-versions@v1
58+
continue-on-error: true
59+
with:
60+
package-name: 'io.admin-shell.aas.dataformat-aml'
61+
62+
- name: Delete old dataformat-rdf package
63+
uses: actions/delete-package-versions@v1
64+
continue-on-error: true
65+
with:
66+
package-name: 'io.admin-shell.aas.dataformat-rdf'
67+
68+
- name: Delete old dataformat-json package
69+
uses: actions/delete-package-versions@v1
70+
continue-on-error: true
71+
with:
72+
package-name: 'io.admin-shell.aas.dataformat-json'
73+
74+
- name: Delete old validator package
75+
uses: actions/delete-package-versions@v1
76+
continue-on-error: true
77+
with:
78+
package-name: 'io.admin-shell.aas.validator'
79+
80+
- name: Publish to GitHub Packages Apache Maven
81+
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
82+
env:
83+
GITHUB_TOKEN: ${{ github.token }}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
import io.adminshell.aas.v3.dataformat.mapping.MappingException;
2626
import io.adminshell.aas.v3.dataformat.mapping.MappingProvider;
2727
import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment;
28+
import io.adminshell.aas.v3.model.AssetInformation;
2829
import io.adminshell.aas.v3.model.Identifiable;
2930
import io.adminshell.aas.v3.model.MultiLanguageProperty;
3031
import io.adminshell.aas.v3.model.Referable;
3132
import io.adminshell.aas.v3.model.Qualifiable;
3233

33-
3434
import java.util.List;
3535

3636
/**
@@ -64,8 +64,8 @@ public AssetAdministrationShellEnvironment map(CAEXFile aml) throws MappingExcep
6464
mappingProvider.register(new LangStringCollectionMapper());
6565
mappingProvider.register(new RelationshipElementMapper());
6666
mappingProvider.register(new ReferenceElementMapper());
67-
mappingProvider.register(new ReferableMapper<Referable>());
68-
mappingProvider.register(new IdentifiableMapper<Identifiable>());
67+
mappingProvider.register(new ReferableMapper<>());
68+
mappingProvider.register(new IdentifiableMapper<>());
6969
mappingProvider.register(new ConstraintCollectionMapper());
7070
mappingProvider.register(new QualifierMapper());
7171
mappingProvider.register(new OperationCollectionMapper());
@@ -77,12 +77,15 @@ public AssetAdministrationShellEnvironment map(CAEXFile aml) throws MappingExcep
7777
mappingProvider.register(new EmbeddedDataSpecificationCollectionMapper());
7878
mappingProvider.register(new DataSpecificationIEC61360Mapper());
7979
mappingProvider.register(new EnumDataTypeIEC61360Mapper());
80+
mappingProvider.register(new IdentifierKeyValuePairCollectionMapper());
81+
8082
AbstractClassNamingStrategy classNamingStrategy = new NumberingClassNamingStrategy();
8183

8284
PropertyNamingStrategy propertyNamingStrategy = new PropertyNamingStrategy();
8385
propertyNamingStrategy.registerCustomNaming(Referable.class, "descriptions", "description");
8486
propertyNamingStrategy.registerCustomNaming(MultiLanguageProperty.class, "values", "value");
85-
propertyNamingStrategy.registerCustomNaming(Qualifiable.class, "qualifiers", "qualifier","qualifier");
87+
propertyNamingStrategy.registerCustomNaming(Qualifiable.class, "qualifiers", "qualifier", "qualifier");
88+
propertyNamingStrategy.registerCustomNaming(AssetInformation.class, "specificAssetIds", "specificAssetId");
8689
MappingContext context = new MappingContext(mappingProvider, classNamingStrategy, propertyNamingStrategy, config.getTypeFactory());
8790
context.setDocumentInfo(AmlDocumentInfo.fromFile(aml));
8891
AssetAdministrationShellEnvironment result = context.map(AssetAdministrationShellEnvironment.class, parser);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public AssetAdministrationShellEnvironment map(AmlParser parser, MappingContext
7373
CAEXFile.SystemUnitClassLib systemUnitClassLib = parser.getContent().getSystemUnitClassLib().stream()
7474
.filter(x -> x.getName().equalsIgnoreCase(ASSET_ADMINISTRATION_SHELL_SYSTEM_UNIT_CLASSES))
7575
.findFirst()
76-
.orElse(null);
76+
.orElse(CAEXFile.SystemUnitClassLib.builder().build());
7777

7878
List<SystemUnitFamilyType> systemUnitFamilyTypeShells = systemUnitClassLib.getSystemUnitClass().stream()
7979
.filter(x ->x.getSupportedRoleClass().get(0).getRefRoleClassPath().equalsIgnoreCase(ROLE_CLASS_LIB_ASSET_ADMINISTRATION_SHELL))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.core.util.AasUtils;
24+
import io.adminshell.aas.v3.dataformat.mapping.MappingException;
25+
import io.adminshell.aas.v3.model.IdentifierKeyValuePair;
26+
import java.beans.PropertyDescriptor;
27+
28+
import java.lang.reflect.InvocationTargetException;
29+
import java.util.ArrayList;
30+
import java.util.Collection;
31+
import java.util.List;
32+
import java.util.logging.Level;
33+
import java.util.logging.Logger;
34+
35+
public class IdentifierKeyValuePairCollectionMapper extends DefaultMapper<Collection<IdentifierKeyValuePair>> {
36+
37+
@Override
38+
protected Collection mapCollectionValueProperty(AmlParser parser, MappingContext context) throws MappingException {
39+
Collection result = new ArrayList<>();
40+
CAEXObject current = parser.getCurrent();
41+
AttributeType parent = findAttribute(current, context.getProperty(), context);
42+
if (parent == null) {
43+
return result;
44+
}
45+
List<AttributeType> attributes = findAttributes(parent, x -> x.getName().startsWith("specificAssetId"));
46+
for (AttributeType attribute : attributes) {
47+
parser.setCurrent(attribute);
48+
try {
49+
IdentifierKeyValuePair element = context.getTypeFactory().newInstance(IdentifierKeyValuePair.class);
50+
for (PropertyDescriptor property : AasUtils.getAasProperties(IdentifierKeyValuePair.class)) {
51+
Object propertyValue = context
52+
.with(element)
53+
.with(property)
54+
.withoutType()
55+
.map(property.getReadMethod().getGenericReturnType(), parser);
56+
if (propertyValue != null) {
57+
try {
58+
property.getWriteMethod().invoke(element, propertyValue);
59+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
60+
throw new MappingException(String.format("error setting property value for property %s", property.getName()), ex);
61+
}
62+
}
63+
}
64+
parser.setCurrent(attribute);
65+
result.add(element);
66+
} catch (NoSuchMethodException ex) {
67+
Logger.getLogger(IdentifierKeyValuePairCollectionMapper.class.getName()).log(Level.SEVERE, null, ex);
68+
} catch (InstantiationException ex) {
69+
Logger.getLogger(IdentifierKeyValuePairCollectionMapper.class.getName()).log(Level.SEVERE, null, ex);
70+
} catch (IllegalAccessException ex) {
71+
Logger.getLogger(IdentifierKeyValuePairCollectionMapper.class.getName()).log(Level.SEVERE, null, ex);
72+
} catch (IllegalArgumentException ex) {
73+
Logger.getLogger(IdentifierKeyValuePairCollectionMapper.class.getName()).log(Level.SEVERE, null, ex);
74+
} catch (InvocationTargetException ex) {
75+
Logger.getLogger(IdentifierKeyValuePairCollectionMapper.class.getName()).log(Level.SEVERE, null, ex);
76+
}
77+
}
78+
parser.setCurrent(parent);
79+
return result;
80+
}
81+
82+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import io.adminshell.aas.v3.dataformat.aml.serialization.mappers.ViewMapper;
3939
import io.adminshell.aas.v3.dataformat.aml.model.caex.CAEXFile;
4040
import io.adminshell.aas.v3.dataformat.aml.serialization.mappers.ConceptDescriptionMapper;
41+
import io.adminshell.aas.v3.dataformat.aml.serialization.mappers.IdentifierKeyValuePairCollectionMapper;
4142
import io.adminshell.aas.v3.dataformat.aml.serialization.mappers.PropertyMapper;
4243
import io.adminshell.aas.v3.dataformat.aml.serialization.mappers.RangeMapper;
4344
import io.adminshell.aas.v3.dataformat.aml.serialization.mappers.ReferenceMapper;
@@ -99,6 +100,7 @@ public CAEXFile map(AssetAdministrationShellEnvironment env, AmlSerializationCon
99100
mappingProvider.register(new PropertyMapper());
100101
mappingProvider.register(new RangeMapper());
101102
mappingProvider.register(new ConceptDescriptionMapper());
103+
mappingProvider.register(new IdentifierKeyValuePairCollectionMapper());
102104
MappingContext context = new MappingContext(
103105
mappingProvider,
104106
classNamingStrategy,
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.serialization.mappers;
17+
18+
import io.adminshell.aas.v3.dataformat.aml.serialization.DefaultMapper;
19+
import io.adminshell.aas.v3.dataformat.aml.serialization.AmlGenerator;
20+
import io.adminshell.aas.v3.dataformat.aml.serialization.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.AssetInformation;
25+
import io.adminshell.aas.v3.model.IdentifierKeyValuePair;
26+
import java.beans.PropertyDescriptor;
27+
import java.lang.reflect.InvocationTargetException;
28+
import java.util.ArrayList;
29+
import java.util.Collection;
30+
import java.util.List;
31+
32+
public class IdentifierKeyValuePairCollectionMapper extends DefaultMapper<Collection<IdentifierKeyValuePair>> {
33+
34+
private static final String ATTRIBUTE_NAME = "specificAssetId";
35+
36+
@Override
37+
public void map(Collection<IdentifierKeyValuePair> value, AmlGenerator generator, MappingContext context) throws MappingException {
38+
if (value == null || context == null || value.isEmpty()) {
39+
return;
40+
}
41+
AttributeType.Builder wrapperBuilder = AttributeType.builder()
42+
.withName(ATTRIBUTE_NAME)
43+
.withRefSemantic(generator.refSemantic(AssetInformation.class, ATTRIBUTE_NAME));
44+
List<AttributeType> attributes = new ArrayList<>();
45+
for (IdentifierKeyValuePair element : value) {
46+
AttributeType.Builder builder = AttributeType.builder()
47+
.withName(ATTRIBUTE_NAME + (value.size() > 1 ? "_" + (attributes.size() + 1) : ""));
48+
for (PropertyDescriptor property : AasUtils.getAasProperties(element.getClass())) {
49+
if (!skipProperty(property)) {
50+
context.with(property)
51+
.map(property.getReadMethod().getGenericReturnType(),
52+
getElemenetPropertyValue(element, property, context),
53+
generator.with(builder));
54+
}
55+
}
56+
attributes.add(builder.build());
57+
}
58+
attributes.forEach(x -> wrapperBuilder.addAttribute(x));
59+
generator.add(wrapperBuilder.build());
60+
}
61+
62+
protected Object getElemenetPropertyValue(IdentifierKeyValuePair elemenet, PropertyDescriptor property, MappingContext context) throws MappingException {
63+
try {
64+
return property.getReadMethod().invoke(elemenet);
65+
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
66+
throw new MappingException("failed to get property value for property " + property.getName(), ex);
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)