Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AAS Part 2 / API Model Classes #161

Merged
merged 103 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
13ee184
upgrade to latest generated java model and adding toString method
sebbader-sap Jun 16, 2023
d868f19
Update dataformat-aasx project
emildinchev Jun 27, 2023
f339157
Update dataformat-core
emildinchev Jun 27, 2023
c62e54d
Update dataformat-core project
emildinchev Jun 29, 2023
ddc62e2
Update dataformat-json project
emildinchev Jun 29, 2023
2bdb3bb
Create dataformat-rdf project
emildinchev Jun 29, 2023
3037e71
Update dataformat-xml project
emildinchev Jun 29, 2023
7e1b1c4
Update model project
emildinchev Jun 29, 2023
61258fa
Update model project
emildinchev Jun 30, 2023
534bbec
Update model project
emildinchev Jun 30, 2023
78c8cc3
Revert the changed files
emildinchev Jul 3, 2023
f44bd1a
Remove dataformat-rdf project
emildinchev Jul 3, 2023
a30a902
fix compile errors
sebbader-sap Jul 3, 2023
93a10e1
Merge branch 'generated-v3-part2' of https://github.com/sap-contribut…
sebbader-sap Jul 3, 2023
651a383
fix compile errors
sebbader-sap Jul 3, 2023
c50a4ac
Adapt the copyright notice
emildinchev Jul 3, 2023
4dcdcda
Adapt the copyright notice
emildinchev Jul 3, 2023
8471132
add next iteration of generated part 1 classes
sebbader-sap Jul 3, 2023
2ca2599
Merge branch 'generated-v3-part2' of https://github.com/sap-contribut…
sebbader-sap Jul 3, 2023
49e6e23
Fix the tests in dataformat-core
emildinchev Jul 4, 2023
3678a6e
Fix the compilation errors in XML-Serializer Project
emildinchev Jul 4, 2023
b1ddf4b
Fix Some XML Serialization Tests
emildinchev Jul 4, 2023
1d8e192
Fix some XML Serialization Tests
emildinchev Jul 4, 2023
30ee673
Fix the dataformat-xml project
emildinchev Jul 5, 2023
18decbf
Fix the dataformat-json project
emildinchev Jul 6, 2023
b0c17e6
Adapt the mixins
emildinchev Jul 7, 2023
6326dae
Revert some changes in the comments
emildinchev Jul 7, 2023
74811fb
Adapt dataformat-core
emildinchev Jul 7, 2023
382fd3d
Adapt dataformat-json project
emildinchev Jul 7, 2023
5c7bff0
Update PropertyMixin.java
emildinchev Jul 7, 2023
32df45a
Merge pull request #1 from sap-contributions/generated-v3-part2
emildinchev Jul 11, 2023
4fa5d0f
fix: enable more than one data specification content (#5)
tschultebahrenberg-sap Jul 27, 2023
d77046b
add copyright header
sebbader-sap Jul 28, 2023
953c7f4
fix v3.0.1 compliance of descriptors
sebbader-sap Jul 28, 2023
fff595c
fix v3.0.1 compliance of descriptors
sebbader-sap Jul 28, 2023
a4ceded
add v3.0.1 classes of new model generator run
sebbader-sap Jul 28, 2023
536e359
update part 2 classes
sebbader-sap Jul 28, 2023
dc380d2
remove the copy constructor logic
sebbader-sap Jul 28, 2023
c60401e
add SecurityAttributeObject
sebbader-sap Nov 6, 2023
8fcabbb
Merge branch 'main' into generated-v3-part2
sebbader-sap Nov 7, 2023
a7130e7
fix wrong extensions declaration in the submodel json mixin
sebbader-sap Nov 7, 2023
a843f58
Remove Roundtrips in JsonSerializer
MS-SAP Nov 9, 2023
12e0f63
Remove unused ModelTypeProcessor and JsonTreeProcessor Classes
MS-SAP Nov 9, 2023
f4f618c
Merge pull request #8 from MS-SAP/generated-v3-part2
MS-SAP Nov 9, 2023
db6f08e
Remove implemented Interfaces from JsonDeserializer
MS-SAP Nov 9, 2023
6bbcdb2
Merge branch 'sap-contributions:generated-v3-part2' into generated-v3…
MS-SAP Nov 9, 2023
7d03c07
Remove Interfaces from JsonDeserializer (#9)
MS-SAP Nov 9, 2023
337b952
Delete all *Value Classes
MS-SAP Nov 20, 2023
c82004e
Merge branch 'sap-contributions:generated-v3-part2' into generated-v3…
MS-SAP Nov 20, 2023
4ae7bc3
Merge pull request #10 from MS-SAP/generated-v3-part2
MS-SAP Nov 20, 2023
ae14b87
rerun of the generator but without the *Value classes
sebbader-sap Nov 21, 2023
73c5368
Merge commit '11836d299721472aa1ae279782e98ba9e4c57b07' into generate…
sebbader-sap Nov 21, 2023
a33bcc5
clean up
sebbader-sap Nov 21, 2023
30ca328
clean up
sebbader-sap Nov 21, 2023
58bd8e6
fix securityattributes type enum bug
sebbader-sap Nov 28, 2023
7c74c95
remove unnecessary roundtrips in the json deserializer
sebbader-sap Dec 12, 2023
4203e17
Rename EnumSerializer to AasEnumSerializer
emildinchev Jan 15, 2024
7a2b5f1
Restore the old state
emildinchev Jan 16, 2024
45a6680
Add some more tests
emildinchev Jan 16, 2024
816327e
Add unit tests for the JsonDeserializer
emildinchev Jan 17, 2024
cbfc4d2
Rename EnumSerializer
emildinchev Jan 18, 2024
1501411
Result of Code Generation Run (#11)
sebbader-sap Jan 19, 2024
6a8020a
Merge branch 'main' into generated-v3-part2
sebbader-sap Jan 23, 2024
a66a361
fix: improve serialization (#13)
emildinchev Jan 23, 2024
90df134
Update JsonSubmodelDescriptorDeserializerTest.java
emildinchev Jan 23, 2024
5916dda
Update JsonSubmodelDescriptorSerializerTest.java
emildinchev Jan 23, 2024
5328ad3
Merge branch 'main' into generated-v3-part2
sebbader-sap Jan 24, 2024
fbeba1d
Fix the build
emildinchev Jan 24, 2024
d05c2a2
Use only generic methods
emildinchev Jan 25, 2024
f7e3052
Update JsonDeserializerTest.java
emildinchev Jan 25, 2024
517fd75
Improve the serialization tests
emildinchev Jan 25, 2024
904c080
Restore the mixins with JsonInclude.annotations
emildinchev Jan 25, 2024
70794e3
Revert some changes
emildinchev Jan 25, 2024
28d1a71
Add copyright headers
emildinchev Jan 25, 2024
d0b094d
Improve the javadoc
emildinchev Jan 25, 2024
f150ea7
Merge pull request #14 from sap-contributions/fix-address-remarks-pr161
emildinchev Jan 26, 2024
ff67d0f
Revert changes in AASXDeserializer
emildinchev Jan 26, 2024
d64960b
Update AASXSerializer.java
emildinchev Jan 26, 2024
3f82f25
Update AASXUtils.java
emildinchev Jan 26, 2024
8a437c9
Update AasUtils.java
emildinchev Jan 26, 2024
e36d51d
Update EnumSerializer.java
emildinchev Jan 26, 2024
e885fc9
Add new test
emildinchev Jan 26, 2024
dc47ba4
Update JsonDeserializer.java
emildinchev Jan 26, 2024
70e8ab4
Update JsonMapperFactory.java
emildinchev Jan 26, 2024
2ee9067
Update JsonSerializer.java
emildinchev Jan 26, 2024
ba185f1
Update SimpleAbstractTypeResolverFactory.java
emildinchev Jan 26, 2024
9bc5cae
Fix the mixins
emildinchev Jan 26, 2024
16e985f
Improve serialization tests
emildinchev Jan 26, 2024
2408ccd
Update JsonSerializerTest.java
emildinchev Jan 26, 2024
941fe76
Update EmbeddedDataSpecificationsDeserializer.java
emildinchev Jan 26, 2024
8574255
revert some changes
emildinchev Jan 26, 2024
6412ce7
Delete LangString.java
emildinchev Jan 26, 2024
f95d045
Fix testSerializeCustomDataSpecification
emildinchev Jan 31, 2024
545d9f1
add testReadCustomDataSpecification
emildinchev Jan 31, 2024
399cd4a
Remove TestDataHelper
emildinchev Jan 31, 2024
bfa69e3
Address the problem with the default QualifierKind
emildinchev Feb 1, 2024
c3ecd3c
Remove partial data validation
emildinchev Feb 1, 2024
4a21f7e
Add tests for OperationRequest
emildinchev Feb 1, 2024
ddad0ba
Refactoring of the tests
emildinchev Feb 1, 2024
c55601f
Refactoring of the tests
emildinchev Feb 2, 2024
fa2f191
Refactoring of the tests
emildinchev Feb 2, 2024
99b6c80
Refactoring of the tests
emildinchev Feb 2, 2024
ced05f5
Address review remarks
emildinchev Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
* Copyright (c) 2023 SAP SE
* Copyright (C) 2023 SAP SE or an SAP affiliate company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,7 @@
import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd;
import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeIec61360;
import org.eclipse.digitaltwin.aas4j.v3.model.Direction;
import org.eclipse.digitaltwin.aas4j.v3.model.SecurityTypeEnum;
import org.eclipse.digitaltwin.aas4j.v3.model.StateOfEvent;

import java.io.IOException;
Expand Down Expand Up @@ -52,6 +53,8 @@ public void serialize(Enum value, JsonGenerator gen, SerializerProvider provider
}
} else if (value instanceof DataTypeIec61360) {
gen.writeString(value.name().toUpperCase());
} else if (value instanceof SecurityTypeEnum) {
gen.writeString(value.name().toUpperCase());
} else if (value instanceof Direction || value instanceof StateOfEvent) {
gen.writeString(value.name().toLowerCase());
} else if (ReflectionHelper.ENUMS.contains(value.getClass())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Examples {
.id("something_142922d6")
.extensions(new DefaultExtension.Builder()
.name("something_aae6caf4")
.valueType(DataTypeDefXsd.STRING)
.build())
.assetInformation(new DefaultAssetInformation.Builder()
.assetKind(AssetKind.NOT_APPLICABLE)
Expand Down Expand Up @@ -86,7 +87,6 @@ public class Examples {
.build())
.build();


public static final Environment ENVIRONMENT_WITH_DUMMYDATASPEC = new DefaultEnvironment.Builder()
.submodels(
new DefaultSubmodel.Builder()
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.eclipse.digitaltwin.aas4j.v3.dataformat.json;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
Expand All @@ -27,194 +25,145 @@
import java.util.List;

import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException;
import org.eclipse.digitaltwin.aas4j.v3.model.Environment;
import org.eclipse.digitaltwin.aas4j.v3.model.Referable;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;

/**
* Class for serializing an instance of AssetAdministrationShellEnvironment or Referables to
* JSON.
* Class for serializing of AAS instances.
*/
public class JsonSerializer {

protected JsonMapper mapper;

private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;

public JsonSerializer() {
mapper = new JsonMapperFactory().create(new SimpleAbstractTypeResolverFactory().create());
}

/**
* Serializes a given instance of AssetAdministrationShellEnvironment to string
* Generic method to serialize a given AAS instance to a string
*
* @param aasEnvironment the AssetAdministrationShellEnvironment to serialize
* @return the string representation of the environment
* @param aasInstance the AAS instance to serialize
* @return the string representation
* @throws SerializationException if serialization fails
*/
public String write(Environment aasEnvironment) throws SerializationException {
public String write(Object aasInstance) throws SerializationException {
try {
return mapper.writeValueAsString(aasEnvironment);
return mapper.writeValueAsString(aasInstance);
} catch (JsonProcessingException ex) {
throw new SerializationException("error serializing AssetAdministrationShellEnvironment", ex);
throw new SerializationException(
String.format("error serializing %s", aasInstance.getClass().getSimpleName()), ex);
}
}

/**
* Converts a given instance of AssetAdministrationShellEnvironment as JSON node.
*
* @param aasEnvironment the AssetAdministrationShellEnvironment to serialize
* @return the JSON node representation of the environment
*/
public JsonNode toNode(Environment aasEnvironment) {
return mapper.valueToTree(aasEnvironment);
}

/**
* Serializes a given instance of Environment to an OutputStream using DEFAULT_CHARSET
*
* @param out the Outputstream to serialize to
* @param aasEnvironment the Environment to serialize
* @throws IOException if writing to the stream fails
* Generic method to serialize a collection.
* @param collection the collection to serialize. Not null.
* @return the string representation of the collection.
* @throws SerializationException if serialization fails
*/
void write(OutputStream out, Environment aasEnvironment) throws IOException, SerializationException {
write(out, DEFAULT_CHARSET, aasEnvironment);
}
public String writeList(Collection<?> collection) throws SerializationException {
if (collection == null || collection.isEmpty()) {
return write(collection);
}

/**
* Serializes a given instance of Environment to an OutputStream using given charset
*
* @param out the Outputstream to serialize to
* @param charset the Charset to use for serialization
* @param aasEnvironment the Environment to serialize
* @throws IOException if writing to the stream fails
* @throws SerializationException if serialization fails
*/
void write(OutputStream out, Charset charset, Environment aasEnvironment)
throws IOException, SerializationException {
try (OutputStreamWriter writer = new OutputStreamWriter(out, charset)) {
writer.write(write(aasEnvironment));
Class clazz = collection.iterator().next().getClass();
try {
return mapper.writerFor(mapper.getTypeFactory().constructCollectionType(List.class, clazz))
.writeValueAsString(collection);
} catch (JsonProcessingException ex) {
throw new SerializationException("error serializing list of " + clazz.getSimpleName(), ex);
}
}

// Note that the AAS also defines a file class
/**
* Serializes a given instance of Environment to a java.io.File using DEFAULT_CHARSET
* Generic method to convert a given AAS instance to a JSON node
*
* @param file the java.io.File to serialize to
* @param charset the Charset to use for serialization
* @param aasEnvironment the Environment to serialize
* @throws FileNotFoundException if the fail does not exist
* @throws IOException if writing to the file fails
* @throws SerializationException if serialization fails
* @param aasInstance the AAS instance to serialize
* @return the JSON node representation
* @throws IllegalArgumentException
*/
void write(java.io.File file, Charset charset, Environment aasEnvironment)
throws FileNotFoundException, IOException, SerializationException {
try (OutputStream out = new FileOutputStream(file)) {
write(out, charset, aasEnvironment);
}
public JsonNode toNode(Object aasInstance) {
return mapper.valueToTree(aasInstance);
}

/**
* Serializes a given instance of Environment to a java.io.File using given charset
* Generic method to convert a collection of AAS instances to a JSON array
*
* @param file the java.io.File to serialize to
* @param aasEnvironment the Environment to serialize
* @throws FileNotFoundException if the fail does not exist
* @throws IOException if writing to the file fails
* @throws SerializationException if serialization fails
* @param aasInstances the list of AAS instances to convert
* @return the JSON array representation
* @throws IllegalArgumentException
*/
void write(java.io.File file, Environment aasEnvironment)
throws FileNotFoundException, IOException, SerializationException {
write(file, DEFAULT_CHARSET, aasEnvironment);
public JsonNode toArrayNode(Collection<?> aasInstances) {
if(aasInstances == null) {
return JsonNodeFactory.instance.nullNode();
}
ArrayNode result = JsonNodeFactory.instance.arrayNode();
for (Object obj : aasInstances) {
result.add(toNode(obj));
}
return result;
}

/**
* Serializes a given instance of a Referable to string
* Generic method to serialize a given AAS instance to an output stream using given charset
*
* @param referable the referable to serialize
* @return the string representation of the referable
* @param out the output stream to serialize to
* @param charset the charset to use for serialization
* @param aasInstance the AAS instance to serialize
* @throws SerializationException if serialization fails
*/
public String write(Referable referable) throws SerializationException {
public void write(OutputStream out, Charset charset, Object aasInstance) throws SerializationException {
try {
return mapper.writeValueAsString(referable);
} catch (JsonProcessingException ex) {
throw new SerializationException("error serializing Referable", ex);
mapper.writeValue(new OutputStreamWriter(out, charset), aasInstance);
} catch (IOException ex) {
throw new SerializationException("error serializing " + aasInstance.getClass().getSimpleName() , ex);
}
}

/**
* Converts a given instance of a Referable to a JSON node.
* Generic method to serialize a given AAS instance to an output stream using UTF-8 charset
*
* @param referable the referable to serialize
* @return the JSON node representation of the referable
* @param out the output stream to serialize to
* @param aasInstance the AAS instance to serialize
* @throws SerializationException if serialization fails
*/
public JsonNode toNode(Referable referable) {
return mapper.valueToTree(referable);
public void write(OutputStream out, Object aasInstance) throws SerializationException {
write(out, StandardCharsets.UTF_8, aasInstance);
}

/**
* Generic method to serialize a collection of AAS instances to an output stream using given charset
*
* @param referables the referables to serialize
* @return the string representation of the list of referables
* @param out the output stream to serialize to
* @param charset the charset to use for serialization
* @param collection the collection of AAS instances to serialize
* @throws SerializationException if serialization fails
*/
public String write(Collection<? extends Referable> referables) throws SerializationException {
if (referables == null) {
return null;
} else if (referables.isEmpty()) {
return mapper.createArrayNode().toString();
}

try {
return mapper.writerFor(mapper.getTypeFactory().constructCollectionType(List.class, referables.iterator().next().getClass()))
.writeValueAsString(referables);
} catch (JsonProcessingException ex) {
throw new SerializationException("error serializing list of Referables", ex);
public void writeList(OutputStream out, Charset charset, Collection<?> collection) throws SerializationException {
if (collection == null || collection.isEmpty()) {
write(out, charset, collection);
} else {
Class clazz = collection.iterator().next().getClass();
try {
mapper.writerFor(mapper.getTypeFactory().constructCollectionType(List.class, clazz))
.writeValue(new OutputStreamWriter(out, charset), collection);
} catch (IOException ex) {
throw new SerializationException("error serializing list of " + clazz.getSimpleName(), ex);
}
}
}

/**
* Generic method to serialize a collection of AAS instances to an output stream using UTF-8 charset
*
* @param referables the referables to serialize
* @return the string representation of the list of referables
* @param out the output stream to serialize to
* @param collection the collection of AAS instances to serialize
* @throws SerializationException if serialization fails
*/
public JsonNode toNode(Collection<? extends Referable> referables) {
if (referables == null) {
return null;
} else if (referables.isEmpty()) {
return mapper.createArrayNode();
}
return mapper.valueToTree(referables);
}

public String writeReferable(Referable referable) throws SerializationException {
try {
return mapper.writeValueAsString(mapper.valueToTree(referable));
} catch (JsonProcessingException ex) {
throw new SerializationException("error serializing Referable", ex);
}
}

public String writeReferables(List<Referable> referables) throws SerializationException {
if(referables.isEmpty()){
return "[]";
}

try {
ObjectWriter objectWriter = mapper.writerFor(mapper.getTypeFactory().constructCollectionType(List.class, referables.get(0).getClass()));
String json = objectWriter.writeValueAsString(referables);

return mapper.writeValueAsString(this.mapper.readTree(json));

} catch (JsonProcessingException ex) {
throw new SerializationException("error serializing list of Referables", ex);
}
public void writeList(OutputStream out, Collection<?> collection) throws SerializationException {
writeList(out, StandardCharsets.UTF_8, collection);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package org.eclipse.digitaltwin.aas4j.v3.dataformat.json.mixins;

import com.fasterxml.jackson.annotation.JsonInclude;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation;

public interface AssetAdministrationShellMixin {
import com.fasterxml.jackson.annotation.JsonInclude;

public interface AssetAdministrationShellMixin {
@JsonInclude(JsonInclude.Include.ALWAYS)
mjacoby marked this conversation as resolved.
Show resolved Hide resolved
public AssetInformation getAssetInformation();
}
AssetInformation getAssetInformation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@
*/
package org.eclipse.digitaltwin.aas4j.v3.dataformat.json.mixins;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind;

public interface AssetInformationMixin {
import com.fasterxml.jackson.annotation.JsonInclude;

public interface AssetInformationMixin {
@JsonInclude(JsonInclude.Include.ALWAYS)
mjacoby marked this conversation as resolved.
Show resolved Hide resolved
public AssetKind getAssetKind();

@JsonProperty("globalAssetId")
public String getGlobalAssetId();

@JsonProperty("globalAssetId")
public void setGlobalAssetId(String globalAssetId);
AssetKind getAssetKind();
}
Loading