Skip to content

Commit

Permalink
Merge pull request #14 from sap-contributions/fix-address-remarks-pr161
Browse files Browse the repository at this point in the history
fix: address remarks pr161
  • Loading branch information
emildinchev authored Jan 26, 2024
2 parents fbeba1d + d0b094d commit f150ea7
Show file tree
Hide file tree
Showing 40 changed files with 1,133 additions and 1,393 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2024 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
* 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 Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.SerializationException;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShellDescriptor;
import org.eclipse.digitaltwin.aas4j.v3.model.Environment;
Expand All @@ -43,148 +45,15 @@
*/
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 AAS environment to a string
* Generic method to serialize a given AAS instance to a string
*
* @param aasEnvironment the AAS environment to serialize
* @return the string representation of the environment
* @throws SerializationException if serialization fails
*/
public String write(Environment aasEnvironment) throws SerializationException {
return write((Object)aasEnvironment);
}

/**
* Converts a given instance of AAS environment to a JSON node
*
* @param aasEnvironment the AAS environment to serialize
* @return the JSON node representation
* @throws IllegalArgumentException
*/
public JsonNode toNode(Environment aasEnvironment) {
return toNode((Object)aasEnvironment);
}

/**
* Serializes a given AAS environment to an output stream using given charset
*
* @param out the output stream to serialize to
* @param aasEnvironment the AAS environment to serialize
* @throws SerializationException if serialization fails
*/
void write(OutputStream out, Environment aasEnvironment) throws SerializationException {
write(out, DEFAULT_CHARSET, (Object)aasEnvironment);
}

/**
* Serializes a given AAS environment to an output stream using given charset
*
* @param out the output stream to serialize to
* @param charset the charset to use for serialization
* @param aasEnvironment the AAS environment to serialize
* @throws SerializationException if serialization fails
*/
void write(OutputStream out, Charset charset, Environment aasEnvironment) throws SerializationException {
write(out, charset, (Object)aasEnvironment);
}

/**
* Serializes a given instance of AAS 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 AAS environment to serialize
* @throws FileNotFoundException if the fail does not exist
* @throws SerializationException if serialization fails
*/
void write(File file, Charset charset, Environment aasEnvironment)
throws FileNotFoundException, SerializationException {
write(new FileOutputStream(file), 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 SerializationException if serialization fails
*/
void write(File file, Environment aasEnvironment)
throws FileNotFoundException, SerializationException {
write(file, DEFAULT_CHARSET, aasEnvironment);
}

/**
* Serializes a given instance of a Referable to string
*
* @param referable the referable to serialize
* @return the string representation of the referable
* @throws SerializationException if serialization fails
*/
public String write(Referable referable) throws SerializationException {
return write((Object)referable);
}

/**
* Converts a given instance of a Referable to a JSON node.
*
* @param referable the referable to serialize
* @return the JSON node representation of the referable
*/
public JsonNode toNode(Referable referable) {
return toNode((Object)referable);
}

/**
* Serializes a given collection of referables to string
* @param referables the collection of referables to serialize
* @return the string representation of the collection
* @throws SerializationException if serialization fails
*/
public String write(Collection<? extends Referable> referables) throws SerializationException {
return writeList(referables);
}

/**
* Converts a collection of referables to a JSON node.
* @param referables the referables to serialize
* @return the string representation of the list of referables
*/
public JsonNode toNode(Collection<? extends Referable> referables) {
return toNode((Object)referables);
}

/**
* Serializes a referable to string.
* @param referable the referable to serialize.
* @return the string representation.
* @throws SerializationException
*/
public String writeReferable(Referable referable) throws SerializationException {
return write(referable);
}

/**
* Serializes a collection of referables
* @param referables the collection to serialize
* @return the string representation.
* @throws SerializationException
*/
public String writeReferables(List<Referable> referables) throws SerializationException {
return write(referables);
}

/**
* Generic method to serialize a given object to a string
*
* @param aasInstance the object to serialize
* @param aasInstance the AAS instance to serialize
* @return the string representation
* @throws SerializationException if serialization fails
*/
Expand All @@ -193,14 +62,14 @@ public String write(Object aasInstance) throws SerializationException {
return mapper.writeValueAsString(aasInstance);
} catch (JsonProcessingException ex) {
throw new SerializationException(
String.format("error serializing %s", aasInstance.getClass().getSimpleName()), ex);
String.format("error serializing %s", aasInstance.getClass().getSimpleName()), ex);
}
}

/**
* Generic method to convert a given object to a JSON node
* Generic method to convert a given AAS instance to a JSON node
*
* @param aasInstance the object to serialize
* @param aasInstance the AAS instance to serialize
* @return the JSON node representation
* @throws IllegalArgumentException
*/
Expand All @@ -209,11 +78,29 @@ public JsonNode toNode(Object aasInstance) {
}

/**
* Generic method to serialize a given object to an output stream using given charset
* Generic method to convert a collection of AAS instances to a JSON array
*
* @param aasInstances the list of AAS instances to convert
* @return the JSON array representation
* @throws IllegalArgumentException
*/
public ArrayNode toArrayNode(Collection<?> aasInstances) {
if(aasInstances == null) {
return null;
}
ArrayNode result = JsonNodeFactory.instance.arrayNode();
for (Object obj : aasInstances) {
result.add(toNode(obj));
}
return result;
}

/**
* Generic method to serialize a given AAS instance to an output stream using given charset
*
* @param out the output stream to serialize to
* @param charset the charset to use for serialization
* @param aasInstance the object to serialize
* @param aasInstance the AAS instance to serialize
* @throws SerializationException if serialization fails
*/
void write(OutputStream out, Charset charset, Object aasInstance) throws SerializationException {
Expand All @@ -224,6 +111,18 @@ void write(OutputStream out, Charset charset, Object aasInstance) throws Seriali
}
}


/**
* Generic method to serialize a given AAS instance to an output stream using UTF-8 charset
*
* @param out the output stream to serialize to
* @param aasInstance the AAS instance to serialize
* @throws SerializationException if serialization fails
*/
void write(OutputStream out, Object aasInstance) throws SerializationException {
write(out, StandardCharsets.UTF_8, aasInstance);
}

/**
* Generic method to serialize a collection.
* @param collection the collection to serialize
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
*
* 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.json.mixins;

import com.fasterxml.jackson.annotation.JsonInclude;

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

public interface AssetAdministrationShellMixin {

@JsonInclude(JsonInclude.Include.ALWAYS)
AssetInformation getAssetInformation();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
*
* 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.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 {

@JsonInclude(JsonInclude.Include.ALWAYS)
AssetKind getAssetKind();

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

@JsonProperty("globalAssetId")
void setGlobalAssetId(String globalAssetId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
*
* 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.json.mixins;

import com.fasterxml.jackson.annotation.JsonInclude;

public interface BlobMixin {

@JsonInclude(JsonInclude.Include.ALWAYS)
String getMimeType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
*
* 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.json.mixins;

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

import java.util.List;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.eclipse.digitaltwin.aas4j.v3.model.LangStringPreferredNameTypeIec61360;

public interface DataSpecificationIec61360Mixin {

@JsonProperty("levelType")
List<LevelType> getLevelTypes();

@JsonProperty("levelType")
void setLevelTypes(List<LevelType> levelTypes);

@JsonInclude(JsonInclude.Include.ALWAYS)
@JsonProperty("preferredName")
List<LangStringPreferredNameTypeIec61360> getPreferredName();

@JsonProperty("preferredName")
void setPreferredName(List<LangStringPreferredNameTypeIec61360> preferredName);

@JsonProperty("unitId")
Reference getUnitId();

public @JsonProperty("unitId")
void setUnitId(Reference unitId);
}
Loading

0 comments on commit f150ea7

Please sign in to comment.