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

feat: implement value only serialization and deserialization #2

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 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
e5184d4
Create ValueOnlyJsonSerializer
emildinchev Jul 13, 2023
30dfca8
Implement the value-only serialization
emildinchev Jul 17, 2023
836e7ca
Add unit tests for value-only serialization.
emildinchev Jul 17, 2023
7d547d9
Add unit tests for value-only serialization
emildinchev Jul 17, 2023
83e867f
Add a copyright header
emildinchev Jul 18, 2023
ca4165b
Add more tests
emildinchev Jul 18, 2023
1e2f37a
Correct the documentation to make it conformable with maven-javadoc-p…
emildinchev Jul 19, 2023
7ee8ca3
Add methods for valueOnly deserialization
emildinchev Jul 19, 2023
27f34cb
Rename the serializer classes to mappers, as they will be used for th…
emildinchev Jul 19, 2023
adb7040
Extract the method createMapper
emildinchev Jul 19, 2023
41609d2
Revert the changes in the JsonSerializer
emildinchev Jul 19, 2023
e06ebe9
Implement the deserialization
emildinchev Jul 20, 2023
ece1a16
Add some more test data
emildinchev Jul 20, 2023
1ae7ca8
Add unit tests for the update
emildinchev Jul 20, 2023
3499b69
Refactor the unit tests
emildinchev Jul 20, 2023
78e63f3
Fix the test
emildinchev Jul 20, 2023
4b9b34d
Remove unused imports
emildinchev Jul 20, 2023
27f96eb
Update the ValueOnlySerializationException
emildinchev Jul 20, 2023
3960a99
Revert JsonSerializer
emildinchev Jul 20, 2023
8eac11b
Make the exception RuntimeException
emildinchev Jul 20, 2023
70fb63b
Hide the constants
emildinchev Jul 20, 2023
120ad8b
Make AnnotatedRelationshipMapper a subclass of RelationshipMapper
emildinchev Jul 20, 2023
b22b990
Correct the Javadoc
emildinchev Jul 20, 2023
f0ee90d
Update value-only test-files
arnoweiss Jul 21, 2023
809b857
Reduce the class visibility
emildinchev Jul 21, 2023
452375a
Change the methods visibility to package-private.
emildinchev Jul 21, 2023
43a1089
Merge pull request #4 from arnoweiss/feat-value-only-serialization
sebbader-sap Jul 24, 2023
497449e
split ValueOnlyMapper into JsonValueOnlySerialiser and JsonValueOnlyD…
sebbader-sap Jul 25, 2023
5d67f72
remove not applicable copyright headers
sebbader-sap Jul 25, 2023
ff6555b
fix code warnings in valueonly
sebbader-sap Jul 25, 2023
49e2e88
activate valueonly tests again
sebbader-sap Jul 25, 2023
3d36b1e
test: adopt unit tests (#6)
tschultebahrenberg-sap Aug 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
* Copyright (C) 2023 SAP SE or an SAP affiliate company.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.digitaltwin.aas4j.v3.dataformat;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;

import org.eclipse.digitaltwin.aas4j.v3.model.Environment;

/**
* Generic deserializer interface to deserialize a given string, Outputstream or
* java.io.File into an instance of AssetAdministrationShellEnvironment
*/
public interface Deserializer {

/**
* Default charset that will be used when no charset is specified
*/
Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;

/**
* Deserializes a given string into an instance of
* AssetAdministrationShellEnvironment
*
* @param value a string representation of the
* AssetAdministrationShellEnvironment
* @return an instance of AssetAdministrationShellEnvironment
* @throws DeserializationException if deserialization fails
*/
Environment read(String value) throws DeserializationException;

/**
* Deserializes a given InputStream into an instance of
* AssetAdministrationShellEnvironment using DEFAULT_CHARSET
*
* @param src an InputStream containing the string representation of the
* AssetAdministrationShellEnvironment
* @return an instance of AssetAdministrationShellEnvironment
* @throws DeserializationException if deserialization fails
*/
default Environment read(InputStream src) throws DeserializationException {
return read(src, DEFAULT_CHARSET);
}

/**
* Deserializes a given InputStream into an instance of
* AssetAdministrationShellEnvironment using a given charset
*
* @param src An InputStream containing the string representation of the
* AssetAdministrationShellEnvironment
* @param charset the charset to use for deserialization
* @return an instance of AssetAdministrationShellEnvironment
* @throws DeserializationException if deserialization fails
*/
default Environment read(InputStream src, Charset charset) throws DeserializationException {
return read(new BufferedReader(
new InputStreamReader(src, charset))
.lines()
.collect(Collectors.joining(System.lineSeparator())));
}

/**
* Deserializes a given File into an instance of
* AssetAdministrationShellEnvironment using DEFAULT_CHARSET
*
* @param file A java.io.File containing the string representation of the
* AssetAdministrationShellEnvironment
* @param charset the charset to use for deserialization
* @return an instance of AssetAdministrationShellEnvironment
* @throws FileNotFoundException if file is not present
* @throws DeserializationException if deserialization fails
*/
default Environment read(java.io.File file, Charset charset)
throws FileNotFoundException, DeserializationException {
return read(new FileInputStream(file), charset);
}

/**
* Deserializes a given File into an instance of
* AssetAdministrationShellEnvironment using a given charset
*
* @param file a java.io.File containing the string representation of the
* AssetAdministrationShellEnvironment
* @return an instance of AssetAdministrationShellEnvironment
* @throws FileNotFoundException if the file is not present
* @throws DeserializationException if deserialization fails
*/
default Environment read(java.io.File file) throws FileNotFoundException, DeserializationException {
return read(file, DEFAULT_CHARSET);
}

/**
* Enables usage of custom implementation to be used for deserialization
* instead of default implementation, e.g. defining a custom implementation
* of the Submodel interface {@code class
* CustomSubmodel implements Submodel {}} and calling
* {@code useImplementation(Submodel.class, CustomSubmodel.class);} will
* result in all instances of Submodel will be deserialized as
* CustomSubmodel. Subsequent class with the same aasInterface parameter
* will override the effects of all previous calls.
*
* @param <T> the type of the interface to replace
* @param aasInterface the class of the interface to replace
* @param implementation the class implementing the interface that should be
* used for deserialization.
*/
<T> void useImplementation(Class<T> aasInterface, Class<? extends T> implementation);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
* Copyright (C) 2023 SAP SE or an SAP affiliate company.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.digitaltwin.aas4j.v3.dataformat;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import org.eclipse.digitaltwin.aas4j.v3.model.Environment;

/**
* Generic serializer interface to serialize an instance of
* AssetAdministrationShellEnvironment to a string, Outputstream or java.io.File
*/
public interface Serializer {

/**
* Default charset that will be used when no charset is specified
*/
Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;

/**
* Serializes a given instance of AssetAdministrationShellEnvironment to
* string
*
* @param aasEnvironment the AssetAdministrationShellEnvironment to
* serialize
* @return the string representation of the environment
* @throws SerializationException if serialization fails
*/
String write(Environment aasEnvironment) throws SerializationException;

/**
* 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
* @throws SerializationException if serialization fails
*/
default void write(OutputStream out, Environment aasEnvironment) throws IOException, SerializationException {
write(out, DEFAULT_CHARSET, aasEnvironment);
}

/**
* 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
*/
default void write(OutputStream out, Charset charset, Environment aasEnvironment)
throws IOException, SerializationException {
try (OutputStreamWriter writer = new OutputStreamWriter(out, charset)) {
writer.write(write(aasEnvironment));
}
}

// Note that the AAS also defines a file class
/**
* Serializes a given instance of Environment to a
* java.io.File using DEFAULT_CHARSET
*
* @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
*/
default void write(java.io.File file, Charset charset, Environment aasEnvironment)
throws FileNotFoundException, IOException, SerializationException {
try (OutputStream out = new FileOutputStream(file)) {
write(out, charset, aasEnvironment);
}
}

/**
* Serializes a given instance of Environment to a
* java.io.File using given charset
*
* @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
*/
default void write(java.io.File file, Environment aasEnvironment)
throws FileNotFoundException, IOException, SerializationException {
write(file, DEFAULT_CHARSET, aasEnvironment);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
* Copyright (c) 2023 SAP SE
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.digitaltwin.aas4j.v3.dataformat.core;

import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationContent;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;

/**
* Class representing all information required for a (custom) data specification
*/
public class DataSpecificationInfo {

private final Class<? extends DataSpecificationContent> type;
private final Reference reference;
private final String prefix;

public DataSpecificationInfo(Class<? extends DataSpecificationContent> type, Reference reference, String prefix) {
this.type = type;
this.reference = reference;
this.prefix = prefix;
}

public Class<? extends DataSpecificationContent> getType() {
return type;
}

public Reference getReference() {
return reference;
}

public String getPrefix() {
return prefix;
}
}
Loading