diff --git a/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/JsonDeserializer.java b/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/JsonDeserializer.java index 27a3c2d7..11370fca 100644 --- a/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/JsonDeserializer.java +++ b/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/JsonDeserializer.java @@ -15,9 +15,11 @@ */ package io.adminshell.aas.v3.dataformat.json; +import java.util.List; import java.util.Map; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver; @@ -31,11 +33,12 @@ import io.adminshell.aas.v3.dataformat.json.modeltype.ModelTypeProcessor; import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment; import io.adminshell.aas.v3.model.EmbeddedDataSpecification; +import io.adminshell.aas.v3.model.Referable; /** * Class for deserializing/parsing AAS JSON documents. */ -public class JsonDeserializer implements Deserializer { +public class JsonDeserializer implements Deserializer, ReferableDeserializer { protected JsonMapper mapper; protected SimpleAbstractTypeResolver typeResolver; @@ -99,4 +102,23 @@ public void useImplementation(Class aasInterface, Class impl typeResolver.addMapping(aasInterface, implementation); buildMapper(); } + + @Override + public T readReferable(String referable, Class outputClass) throws DeserializationException { + try { + return mapper.treeToValue(ModelTypeProcessor.preprocess(referable), outputClass); + } catch (JsonProcessingException ex) { + throw new DeserializationException("error deserializing Referable", ex); + } + } + + @Override + public List readReferables(String referables, Class outputClass) throws DeserializationException { + try { + String parsed = mapper.writeValueAsString(ModelTypeProcessor.preprocess(referables)) ; + return mapper.readValue(parsed,new TypeReference>(){}); + } catch (JsonProcessingException ex) { + throw new DeserializationException("error deserializing list of Referable", ex); + } + } } diff --git a/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/JsonSerializer.java b/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/JsonSerializer.java index e95edf2c..81109dcb 100644 --- a/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/JsonSerializer.java +++ b/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/JsonSerializer.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.module.SimpleModule; @@ -30,12 +31,15 @@ import io.adminshell.aas.v3.dataformat.core.serialization.EmbeddedDataSpecificationSerializer; import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment; import io.adminshell.aas.v3.model.EmbeddedDataSpecification; +import io.adminshell.aas.v3.model.Referable; + +import java.util.List; /** - * Class for serializing an instance of AssetAdministrationShellEnvironment to + * Class for serializing an instance of AssetAdministrationShellEnvironment or Referables to * JSON. */ -public class JsonSerializer implements Serializer { +public class JsonSerializer implements Serializer, ReferableSerializer { protected JsonMapper mapper; @@ -74,4 +78,27 @@ public String write(AssetAdministrationShellEnvironment aasEnvironment) throws S throw new SerializationException("error serializing AssetAdministrationShellEnvironment", ex); } } + + @Override + public String write(Referable referable) throws SerializationException { + try { + return mapper.writeValueAsString(ModelTypeProcessor.postprocess(mapper.valueToTree(referable))); + } catch (JsonProcessingException ex) { + throw new SerializationException("error serializing Referable", ex); + } + } + + @Override + public String write(List referables) throws SerializationException { + if(referables.isEmpty()){ + return null; + } + try { + ObjectWriter objectWriter = mapper.writerFor(mapper.getTypeFactory().constructCollectionType(List.class, referables.get(0).getClass())); + String json = objectWriter.writeValueAsString(referables); + return mapper.writeValueAsString(ModelTypeProcessor.postprocess(this.mapper.readTree(json))); + } catch (JsonProcessingException ex) { + throw new SerializationException("error serializing list of Referables", ex); + } + } } diff --git a/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/ReferableDeserializer.java b/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/ReferableDeserializer.java new file mode 100644 index 00000000..616d0706 --- /dev/null +++ b/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/ReferableDeserializer.java @@ -0,0 +1,54 @@ +/* + * 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 io.adminshell.aas.v3.dataformat.json; + +import io.adminshell.aas.v3.dataformat.DeserializationException; +import io.adminshell.aas.v3.model.Referable; + +import java.util.List; + +/** + * Deserializer Interface for deserialization of referables + */ +public interface ReferableDeserializer { + + /** + * Deserializes a given string into an instance of + * the given Referable + * + * @param referable a string representation of the + * Referable + * @param outputClass most specific class of the given Referable + * @param type of the returned element + * @return an instance of the referable + * @throws DeserializationException + */ + T readReferable(String referable, Class outputClass) throws DeserializationException; + + /** + * Deserializes a given string into an instance of + * a list of the given Referables + * + * @param referables a string representation of an + * array of Referables + * @param outputClass most specific class of the given Referable + * @param type of the returned element + * @return an instance of a list of the referables + * @throws DeserializationException + */ + List readReferables(String referables, Class outputClass) throws DeserializationException; + +} diff --git a/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/ReferableSerializer.java b/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/ReferableSerializer.java new file mode 100644 index 00000000..009429c9 --- /dev/null +++ b/dataformat-json/src/main/java/io/adminshell/aas/v3/dataformat/json/ReferableSerializer.java @@ -0,0 +1,45 @@ +/* + * 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 io.adminshell.aas.v3.dataformat.json; + +import io.adminshell.aas.v3.dataformat.SerializationException; +import io.adminshell.aas.v3.model.Referable; + +import java.util.List; + +/** + * Serializer Interface for serialization of referables + */ +public interface ReferableSerializer { + + /** + * 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 + */ + String write(Referable referable) throws SerializationException; + + /** + * + * @param referables the referables to serialize + * @return the string representation of the list of referables + * @throws SerializationException if serialization fails + */ + String write(List referables) throws SerializationException; + +} diff --git a/dataformat-json/src/test/java/io/adminshell/aas/v3/dataformat/json/JsonReferableDeserializerTest.java b/dataformat-json/src/test/java/io/adminshell/aas/v3/dataformat/json/JsonReferableDeserializerTest.java new file mode 100644 index 00000000..47f4edeb --- /dev/null +++ b/dataformat-json/src/test/java/io/adminshell/aas/v3/dataformat/json/JsonReferableDeserializerTest.java @@ -0,0 +1,119 @@ +/* + * 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 io.adminshell.aas.v3.dataformat.json; + +import io.adminshell.aas.v3.dataformat.DeserializationException; +import io.adminshell.aas.v3.dataformat.Deserializer; +import io.adminshell.aas.v3.model.*; +import io.adminshell.aas.v3.model.impl.DefaultProperty; +import io.adminshell.aas.v3.model.impl.DefaultSubmodel; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class JsonReferableDeserializerTest { + + private static final Logger logger = LoggerFactory.getLogger(JsonReferableDeserializerTest.class); + + @Test + public void testReadAAS() throws IOException, DeserializationException { + File fileExpected = new File("src/test/resources/assetAdministrationShell.json"); + String expected = Files.readString(fileExpected.toPath()); + AssetAdministrationShell aas = new JsonDeserializer().readReferable(expected, AssetAdministrationShell.class); + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + AssetAdministrationShell aasExpected = environment.getAssetAdministrationShells().get(0); + + assertEquals(aasExpected, aas); + } + + @Test + public void testReadAASs() throws IOException, DeserializationException { + File fileExpected = new File("src/test/resources/assetAdministrationShellList.json"); + String expected = Files.readString(fileExpected.toPath()); + List aas = new JsonDeserializer().readReferables(expected, AssetAdministrationShell.class); + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + List aasExpected = Arrays.asList(environment.getAssetAdministrationShells().get(0) + ,environment.getAssetAdministrationShells().get(1)) ; + + assertEquals(aasExpected, aas); + } + + @Test + public void testReadSubmodel() throws IOException, DeserializationException { + File fileExpected = new File("src/test/resources/submodel.json"); + String expected = Files.readString(fileExpected.toPath()); + Submodel submodel = new JsonDeserializer().readReferable(expected,Submodel.class); + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + Submodel submodelExpected = environment.getSubmodels().get(0); + + assertEquals(submodelExpected, submodel); + } + + @Test + public void testReadSubmodels() throws IOException, DeserializationException { + File fileExpected = new File("src/test/resources/submodelList.json"); + String expected = Files.readString(fileExpected.toPath()); + List submodels = new JsonDeserializer().readReferables(expected,Submodel.class); + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + List submodelsExpected = Arrays.asList(environment.getSubmodels().get(0),environment.getSubmodels().get(1)); + + assertEquals(submodelsExpected, submodels); + } + + @Test + public void testReadSubmodelElement() throws IOException, DeserializationException { + File fileExpected = new File("src/test/resources/submodelElement.json"); + String expected = Files.readString(fileExpected.toPath()); + SubmodelElement submodelElement = new JsonDeserializer().readReferable(expected,SubmodelElement.class); + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + SubmodelElement submodelElementExpected = environment.getSubmodels().get(0).getSubmodelElements().get(0); + + assertEquals(submodelElementExpected, submodelElement); + } + + @Test + public void testReadSubmodelElements() throws IOException, DeserializationException { + File fileExpected = new File("src/test/resources/submodelElementList.json"); + String expected = Files.readString(fileExpected.toPath()); + List submodelElements = new JsonDeserializer().readReferables(expected,SubmodelElement.class); + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + List submodelElementsExpected = Arrays.asList( + environment.getSubmodels().get(0).getSubmodelElements().get(0), + environment.getSubmodels().get(0).getSubmodelElements().get(1)); ; + + assertEquals(submodelElementsExpected, submodelElements); + } + + @Test + public void testReadSubmodelElementCollection() throws IOException, DeserializationException { + File fileExpected = new File("src/test/resources/submodelElementCollection.json"); + String expected = Files.readString(fileExpected.toPath()); + SubmodelElementCollection submodelElementCollection = new JsonDeserializer().readReferable(expected,SubmodelElementCollection.class); + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + SubmodelElement submodelElementCollectionExpected = environment.getSubmodels().get(6).getSubmodelElements().get(5); ; + + assertEquals(submodelElementCollectionExpected, submodelElementCollection); + } + +} diff --git a/dataformat-json/src/test/java/io/adminshell/aas/v3/dataformat/json/JsonReferableSerializerTest.java b/dataformat-json/src/test/java/io/adminshell/aas/v3/dataformat/json/JsonReferableSerializerTest.java new file mode 100644 index 00000000..aca1509d --- /dev/null +++ b/dataformat-json/src/test/java/io/adminshell/aas/v3/dataformat/json/JsonReferableSerializerTest.java @@ -0,0 +1,102 @@ +/* + * 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 io.adminshell.aas.v3.dataformat.json; + +import io.adminshell.aas.v3.dataformat.SerializationException; +import io.adminshell.aas.v3.model.*; +import org.json.JSONException; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; + +public class JsonReferableSerializerTest { + + private static final Logger logger = LoggerFactory.getLogger(JsonReferableSerializerTest.class); + + @Test + public void testSerializeAAS() throws IOException, SerializationException, JSONException { + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + AssetAdministrationShell assetAdministrationShell = environment.getAssetAdministrationShells().get(0); + compare("src/test/resources/assetAdministrationShell.json",assetAdministrationShell); + } + + @Test + public void testSerializeAASs() throws IOException, SerializationException, JSONException { + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + compare("src/test/resources/assetAdministrationShellList.json", + environment.getAssetAdministrationShells().get(0), environment.getAssetAdministrationShells().get(1)); + } + + @Test + public void testSerializeSubmodel() throws IOException, SerializationException, JSONException { + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + Submodel submodel = environment.getSubmodels().get(0); + compare("src/test/resources/submodel.json",submodel); + } + + @Test + public void testSerializeSubmodels() throws IOException, SerializationException, JSONException { + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + compare("src/test/resources/submodelList.json", environment.getSubmodels().get(0), environment.getSubmodels().get(1)); + } + + @Test + public void testSerializeSubmodelelement() throws IOException, SerializationException, JSONException { + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + SubmodelElement submodelElement = environment.getSubmodels().get(0).getSubmodelElements().get(0); + compare("src/test/resources/submodelElement.json",submodelElement); + } + + @Test + public void testSerializeSubmodelelements() throws IOException, SerializationException, JSONException { + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + SubmodelElement submodelElement0 = environment.getSubmodels().get(0).getSubmodelElements().get(0); + SubmodelElement submodelElement1 = environment.getSubmodels().get(0).getSubmodelElements().get(1); + compare("src/test/resources/submodelElementList.json",submodelElement0,submodelElement1); + } + + @Test + public void testSerializeSubmodelelementCollection() throws IOException, SerializationException, JSONException { + AssetAdministrationShellEnvironment environment = AASFull.ENVIRONMENT; + SubmodelElement submodelElementCollection = environment.getSubmodels().get(6).getSubmodelElements().get(5); + compare("src/test/resources/submodelElementCollection.json",submodelElementCollection); + } + + private void compare(String filePathForExpected, Referable... referable) throws IOException, SerializationException, JSONException { + File fileExpected = new File(filePathForExpected); + String expected = Files.readString(fileExpected.toPath()); + String actual; + if(referable.length>1){ + actual = new JsonSerializer().write(List.of(referable)); + } else { + actual = new JsonSerializer().write(Arrays.stream(referable).findFirst().get()); + } + logger.info(actual); + + JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE); + JSONAssert.assertEquals(actual, expected, JSONCompareMode.NON_EXTENSIBLE); + + } + +} diff --git a/dataformat-json/src/test/java/io/adminshell/aas/v3/dataformat/json/JsonSerializerTest.java b/dataformat-json/src/test/java/io/adminshell/aas/v3/dataformat/json/JsonSerializerTest.java index cf50d74c..a3e5cec2 100644 --- a/dataformat-json/src/test/java/io/adminshell/aas/v3/dataformat/json/JsonSerializerTest.java +++ b/dataformat-json/src/test/java/io/adminshell/aas/v3/dataformat/json/JsonSerializerTest.java @@ -47,7 +47,7 @@ public class JsonSerializerTest { @Test public void testSerializeNull() throws JsonProcessingException, IOException, SerializationException { - assertEquals("null", new JsonSerializer().write(null)); + assertEquals("null", new JsonSerializer().write((AssetAdministrationShellEnvironment) null)); } @Test diff --git a/dataformat-json/src/test/resources/assetAdministrationShell.json b/dataformat-json/src/test/resources/assetAdministrationShell.json new file mode 100644 index 00000000..8d7888f3 --- /dev/null +++ b/dataformat-json/src/test/resources/assetAdministrationShell.json @@ -0,0 +1,91 @@ +{ + "idShort": "TestAssetAdministrationShell", + "description": [ + { + "language": "en-us", + "text": "An Example Asset Administration Shell for the test application" + }, + { + "language": "de", + "text": "Ein Beispiel-Verwaltungsschale für eine Test-Anwendung" + } + ], + "modelType": + { + "name": "AssetAdministrationShell" + }, + "identification": + { + "id": "https://acplt.org/Test_AssetAdministrationShell", + "idType": "Iri" + }, + "administration": + { + "version": "0.9", + "revision": "0" + }, + "derivedFrom": + { + "keys": [ + { + "type": "AssetAdministrationShell", + "idType": "Iri", + "value": "https://acplt.org/TestAssetAdministrationShell2" + } + ] + }, + "assetInformation": + { + "assetKind": "Instance", + "globalAssetId": + { + "keys": [ + { + "type": "Asset", + "idType": "Iri", + "value": "https://acplt.org/Test_Asset" + } + ] + }, + "billOfMaterial": [ + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial" + } + ] + } + ] + }, + "submodels": [ + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "https://acplt.org/Test_Submodel" + } + ] + }, + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial" + } + ] + }, + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "http://acplt.org/Submodels/Assets/TestAsset/Identification" + } + ] + } + ] +} \ No newline at end of file diff --git a/dataformat-json/src/test/resources/assetAdministrationShellList.json b/dataformat-json/src/test/resources/assetAdministrationShellList.json new file mode 100644 index 00000000..1f85d38f --- /dev/null +++ b/dataformat-json/src/test/resources/assetAdministrationShellList.json @@ -0,0 +1,129 @@ +[ + { + "idShort": "TestAssetAdministrationShell", + "description": [ + { + "language": "en-us", + "text": "An Example Asset Administration Shell for the test application" + }, + { + "language": "de", + "text": "Ein Beispiel-Verwaltungsschale für eine Test-Anwendung" + } + ], + "modelType": { + "name": "AssetAdministrationShell" + }, + "identification": { + "id": "https://acplt.org/Test_AssetAdministrationShell", + "idType": "Iri" + }, + "administration": { + "version": "0.9", + "revision": "0" + }, + "derivedFrom": { + "keys": [ + { + "type": "AssetAdministrationShell", + "idType": "Iri", + "value": "https://acplt.org/TestAssetAdministrationShell2" + } + ] + }, + "assetInformation": { + "assetKind": "Instance", + "globalAssetId": { + "keys": [ + { + "type": "Asset", + "idType": "Iri", + "value": "https://acplt.org/Test_Asset" + } + ] + }, + "billOfMaterial": [ + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial" + } + ] + } + ] + }, + "submodels": [ + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "https://acplt.org/Test_Submodel" + } + ] + }, + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial" + } + ] + }, + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "http://acplt.org/Submodels/Assets/TestAsset/Identification" + } + ] + } + ] + }, + { + "idShort": "", + "modelType": { + "name": "AssetAdministrationShell" + }, + "identification": { + "id": "https://acplt.org/Test_AssetAdministrationShell_Mandatory", + "idType": "Iri" + }, + "assetInformation": { + "assetKind": "Instance", + "globalAssetId": { + "keys": [ + { + "type": "Asset", + "idType": "Iri", + "value": "https://acplt.org/Test_Asset_Mandatory" + } + ] + } + }, + "submodels": [ + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "https://acplt.org/Test_Submodel_Mandatory" + } + ] + }, + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "https://acplt.org/Test_Submodel2_Mandatory" + } + ] + } + ] + } +] \ No newline at end of file diff --git a/dataformat-json/src/test/resources/submodel.json b/dataformat-json/src/test/resources/submodel.json new file mode 100644 index 00000000..e0e28068 --- /dev/null +++ b/dataformat-json/src/test/resources/submodel.json @@ -0,0 +1,157 @@ +{ + "idShort": "Identification", + "description": [ + { + "language": "en-us", + "text": "An example asset identification submodel for the test application" + }, + { + "language": "de", + "text": "Ein Beispiel-Identifikations-Submodel für eine Test-Anwendung" + } + ], + "modelType": + { + "name": "Submodel" + }, + "identification": + { + "id": "http://acplt.org/Submodels/Assets/TestAsset/Identification", + "idType": "Iri" + }, + "administration": + { + "version": "0.9", + "revision": "0" + }, + "semanticId": + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "http://acplt.org/SubmodelTemplates/AssetIdentification" + } + ] + }, + "submodelElements": [ + { + "idShort": "ManufacturerName", + "description": [ + { + "language": "en-us", + "text": "Legally valid designation of the natural or judicial person which is directly responsible for the design, production, packaging and labeling of a product in respect to its being brought into circulation." + }, + { + "language": "de", + "text": "Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist" + } + ], + "modelType": + { + "name": "Property" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "0173-1#02-AAO677#002" + } + ] + }, + "qualifiers": [ + { + "modelType": + { + "name": "Qualifier" + }, + "value": "100", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "int", + "type": "http://acplt.org/Qualifier/ExampleQualifier" + }, + { + "modelType": + { + "name": "Qualifier" + }, + "value": "50", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "int", + "type": "http://acplt.org/Qualifier/ExampleQualifier2" + } + ], + "value": "ACPLT", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "string" + }, + { + "idShort": "InstanceId", + "description": [ + { + "language": "en-us", + "text": "Legally valid designation of the natural or judicial person which is directly responsible for the design, production, packaging and labeling of a product in respect to its being brought into circulation." + }, + { + "language": "de", + "text": "Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist" + } + ], + "modelType": + { + "name": "Property" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://opcfoundation.org/UA/DI/1.1/DeviceType/Serialnumber" + } + ] + }, + "value": "978-8234-234-342", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "string" + } + ] +} \ No newline at end of file diff --git a/dataformat-json/src/test/resources/submodelElement.json b/dataformat-json/src/test/resources/submodelElement.json new file mode 100644 index 00000000..67ea2d3a --- /dev/null +++ b/dataformat-json/src/test/resources/submodelElement.json @@ -0,0 +1,79 @@ +{ + "idShort": "ManufacturerName", + "description": [ + { + "language": "en-us", + "text": "Legally valid designation of the natural or judicial person which is directly responsible for the design, production, packaging and labeling of a product in respect to its being brought into circulation." + }, + { + "language": "de", + "text": "Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist" + } + ], + "modelType": + { + "name": "Property" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "0173-1#02-AAO677#002" + } + ] + }, + "qualifiers": [ + { + "modelType": + { + "name": "Qualifier" + }, + "value": "100", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "int", + "type": "http://acplt.org/Qualifier/ExampleQualifier" + }, + { + "modelType": + { + "name": "Qualifier" + }, + "value": "50", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "int", + "type": "http://acplt.org/Qualifier/ExampleQualifier2" + } + ], + "value": "ACPLT", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "string" +} \ No newline at end of file diff --git a/dataformat-json/src/test/resources/submodelElementCollection.json b/dataformat-json/src/test/resources/submodelElementCollection.json new file mode 100644 index 00000000..5d477ac9 --- /dev/null +++ b/dataformat-json/src/test/resources/submodelElementCollection.json @@ -0,0 +1,153 @@ +{ + "idShort": "ExampleSubmodelCollectionOrdered", + "category": "Parameter", + "description": [ + { + "language": "en-us", + "text": "Example SubmodelElementCollectionOrdered object" + }, + { + "language": "de", + "text": "Beispiel SubmodelElementCollectionOrdered Element" + } + ], + "modelType": + { + "name": "SubmodelElementCollection" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/SubmodelElementCollections/ExampleSubmodelElementCollectionOrdered" + } + ] + }, + "kind": "Template", + "value": [ + { + "idShort": "ExampleProperty", + "category": "Constant", + "description": [ + { + "language": "en-us", + "text": "Example Property object" + }, + { + "language": "de", + "text": "Beispiel Property Element" + } + ], + "modelType": + { + "name": "Property" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/Properties/ExampleProperty" + } + ] + }, + "kind": "Template", + "valueType": "string" + }, + { + "idShort": "ExampleMultiLanguageProperty", + "category": "Constant", + "description": [ + { + "language": "en-us", + "text": "Example MultiLanguageProperty object" + }, + { + "language": "de", + "text": "Beispiel MulitLanguageProperty Element" + } + ], + "modelType": + { + "name": "MultiLanguageProperty" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/MultiLanguageProperties/ExampleMultiLanguageProperty" + } + ] + }, + "kind": "Template" + }, + { + "idShort": "ExampleRange", + "category": "Parameter", + "description": [ + { + "language": "en-us", + "text": "Example Range object" + }, + { + "language": "de", + "text": "Beispiel Range Element" + } + ], + "modelType": + { + "name": "Range" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/Ranges/ExampleRange" + } + ] + }, + "kind": "Template", + "valueType": "int", + "max": "100" + }, + { + "idShort": "ExampleRange2", + "category": "Parameter", + "description": [ + { + "language": "en-us", + "text": "Example Range object" + }, + { + "language": "de", + "text": "Beispiel Range Element" + } + ], + "modelType": + { + "name": "Range" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/Ranges/ExampleRange" + } + ] + }, + "kind": "Template", + "valueType": "int", + "min": "0" + } + ], + "ordered": true +} \ No newline at end of file diff --git a/dataformat-json/src/test/resources/submodelElementList.json b/dataformat-json/src/test/resources/submodelElementList.json new file mode 100644 index 00000000..b120f35e --- /dev/null +++ b/dataformat-json/src/test/resources/submodelElementList.json @@ -0,0 +1,120 @@ +[ + { + "idShort": "ManufacturerName", + "description": [ + { + "language": "en-us", + "text": "Legally valid designation of the natural or judicial person which is directly responsible for the design, production, packaging and labeling of a product in respect to its being brought into circulation." + }, + { + "language": "de", + "text": "Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist" + } + ], + "modelType": + { + "name": "Property" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "0173-1#02-AAO677#002" + } + ] + }, + "qualifiers": [ + { + "modelType": + { + "name": "Qualifier" + }, + "value": "100", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "int", + "type": "http://acplt.org/Qualifier/ExampleQualifier" + }, + { + "modelType": + { + "name": "Qualifier" + }, + "value": "50", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "int", + "type": "http://acplt.org/Qualifier/ExampleQualifier2" + } + ], + "value": "ACPLT", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "string" + }, + { + "idShort": "InstanceId", + "description": [ + { + "language": "en-us", + "text": "Legally valid designation of the natural or judicial person which is directly responsible for the design, production, packaging and labeling of a product in respect to its being brought into circulation." + }, + { + "language": "de", + "text": "Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist" + } + ], + "modelType": + { + "name": "Property" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://opcfoundation.org/UA/DI/1.1/DeviceType/Serialnumber" + } + ] + }, + "value": "978-8234-234-342", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "string" + } +] \ No newline at end of file diff --git a/dataformat-json/src/test/resources/submodelList.json b/dataformat-json/src/test/resources/submodelList.json new file mode 100644 index 00000000..734bdf4b --- /dev/null +++ b/dataformat-json/src/test/resources/submodelList.json @@ -0,0 +1,345 @@ +[ + { + "idShort": "Identification", + "description": [ + { + "language": "en-us", + "text": "An example asset identification submodel for the test application" + }, + { + "language": "de", + "text": "Ein Beispiel-Identifikations-Submodel für eine Test-Anwendung" + } + ], + "modelType": + { + "name": "Submodel" + }, + "identification": + { + "id": "http://acplt.org/Submodels/Assets/TestAsset/Identification", + "idType": "Iri" + }, + "administration": + { + "version": "0.9", + "revision": "0" + }, + "semanticId": + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "http://acplt.org/SubmodelTemplates/AssetIdentification" + } + ] + }, + "submodelElements": [ + { + "idShort": "ManufacturerName", + "description": [ + { + "language": "en-us", + "text": "Legally valid designation of the natural or judicial person which is directly responsible for the design, production, packaging and labeling of a product in respect to its being brought into circulation." + }, + { + "language": "de", + "text": "Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist" + } + ], + "modelType": + { + "name": "Property" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "0173-1#02-AAO677#002" + } + ] + }, + "qualifiers": [ + { + "modelType": + { + "name": "Qualifier" + }, + "value": "100", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "int", + "type": "http://acplt.org/Qualifier/ExampleQualifier" + }, + { + "modelType": + { + "name": "Qualifier" + }, + "value": "50", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "int", + "type": "http://acplt.org/Qualifier/ExampleQualifier2" + } + ], + "value": "ACPLT", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "string" + }, + { + "idShort": "InstanceId", + "description": [ + { + "language": "en-us", + "text": "Legally valid designation of the natural or judicial person which is directly responsible for the design, production, packaging and labeling of a product in respect to its being brought into circulation." + }, + { + "language": "de", + "text": "Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist" + } + ], + "modelType": + { + "name": "Property" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://opcfoundation.org/UA/DI/1.1/DeviceType/Serialnumber" + } + ] + }, + "value": "978-8234-234-342", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "string" + } + ] + }, + { + "idShort": "BillOfMaterial", + "description": [ + { + "language": "en-us", + "text": "An example bill of material submodel for the test application" + }, + { + "language": "de", + "text": "Ein Beispiel-BillofMaterial-Submodel für eine Test-Anwendung" + } + ], + "modelType": + { + "name": "Submodel" + }, + "identification": + { + "id": "http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial", + "idType": "Iri" + }, + "administration": + { + "version": "0.9" + }, + "semanticId": + { + "keys": [ + { + "type": "Submodel", + "idType": "Iri", + "value": "http://acplt.org/SubmodelTemplates/BillOfMaterial" + } + ] + }, + "submodelElements": [ + { + "idShort": "ExampleEntity", + "description": [ + { + "language": "en-us", + "text": "Legally valid designation of the natural or judicial person which is directly responsible for the design, production, packaging and labeling of a product in respect to its being brought into circulation." + }, + { + "language": "de", + "text": "Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist" + } + ], + "modelType": + { + "name": "Entity" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://opcfoundation.org/UA/DI/1.1/DeviceType/Serialnumber" + } + ] + }, + "statements": [ + { + "idShort": "ExampleProperty2", + "category": "Constant", + "description": [ + { + "language": "en-us", + "text": "Example Property object" + }, + { + "language": "de", + "text": "Beispiel Property Element" + } + ], + "modelType": + { + "name": "Property" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/Properties/ExampleProperty" + } + ] + }, + "value": "exampleValue2", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "string" + }, + { + "idShort": "ExampleProperty", + "category": "Constant", + "description": [ + { + "language": "en-us", + "text": "Example Property object" + }, + { + "language": "de", + "text": "Beispiel Property Element" + } + ], + "modelType": + { + "name": "Property" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/Properties/ExampleProperty" + } + ] + }, + "value": "exampleValue", + "valueId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://acplt.org/ValueId/ExampleValueId" + } + ] + }, + "valueType": "string" + } + ], + "entityType": "CoManagedEntity" + }, + { + "idShort": "ExampleEntity2", + "description": [ + { + "language": "en-us", + "text": "Legally valid designation of the natural or judicial person which is directly responsible for the design, production, packaging and labeling of a product in respect to its being brought into circulation." + }, + { + "language": "de", + "text": "Bezeichnung für eine natürliche oder juristische Person, die für die Auslegung, Herstellung und Verpackung sowie die Etikettierung eines Produkts im Hinblick auf das 'Inverkehrbringen' im eigenen Namen verantwortlich ist" + } + ], + "modelType": + { + "name": "Entity" + }, + "semanticId": + { + "keys": [ + { + "type": "GlobalReference", + "idType": "Iri", + "value": "http://opcfoundation.org/UA/DI/1.1/DeviceType/Serialnumber" + } + ] + }, + "entityType": "SelfManagedEntity", + "globalAssetId": + { + "keys": [ + { + "type": "Asset", + "idType": "Iri", + "value": "https://acplt.org/Test_Asset2" + } + ] + } + } + ] + } +] \ No newline at end of file