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

Fix de-/serialization for AAS with extension(s) #136

Merged
merged 10 commits into from
Jul 11, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2023 jab.
*
* 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.AssetKind;
import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXSD;
import org.eclipse.digitaltwin.aas4j.v3.model.Environment;
import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes;
import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEnvironment;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultExtension;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference;

public class Examples {

public static final Environment EXTENSION_MINIMAL = new DefaultEnvironment.Builder()
.assetAdministrationShells(new DefaultAssetAdministrationShell.Builder()
.id("something_142922d6")
.extensions(new DefaultExtension.Builder()
.name("something_aae6caf4")
.build())
.assetInformation(new DefaultAssetInformation.Builder()
.assetKind(AssetKind.NOT_APPLICABLE)
.globalAssetID("something_eea66fa1")
.build())
.build())
.build();

public static final Environment EXTENSION_MAXIMAL = new DefaultEnvironment.Builder()
.assetAdministrationShells(new DefaultAssetAdministrationShell.Builder()
.id("something_142922d6")
.extensions(new DefaultExtension.Builder()
.name("something_aae6caf4")
.value("10233")
.valueType(DataTypeDefXSD.UNSIGNED_SHORT)
.refersTo(new DefaultReference.Builder()
.keys(new DefaultKey.Builder()
.type(KeyTypes.SUBMODEL)
.value("urn:another-example01:f7faa581")
.build())
.type(ReferenceTypes.MODEL_REFERENCE)
.build())
.semanticID(new DefaultReference.Builder()
.keys(new DefaultKey.Builder()
.type(KeyTypes.GLOBAL_REFERENCE)
.value("urn:another-company07:4d1bd2cb")
.build())
.type(ReferenceTypes.EXTERNAL_REFERENCE)
.build())
.supplementalSemanticIds(new DefaultReference.Builder()
.keys(new DefaultKey.Builder()
.type(KeyTypes.GLOBAL_REFERENCE)
.value("urn:an-example13:be48ff29")
.build())
.type(ReferenceTypes.EXTERNAL_REFERENCE)
.build())
.build())
.assetInformation(new DefaultAssetInformation.Builder()
.assetKind(AssetKind.NOT_APPLICABLE)
.globalAssetID("something_eea66fa1")
.build())
.build())
.build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

public interface HasExtensionsMixin {

@JsonProperty("extension")
@JsonProperty("extensions")
public List<Extension> getExtensions();

@JsonProperty("extension")
@JsonProperty("extensions")
public void setExtensions(List<Extension> extensions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,25 @@
import java.util.Collections;
import java.util.List;

import org.eclipse.digitaltwin.aas4j.v3.dataformat.DeserializationException;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.util.Examples;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.Environment;
import org.eclipse.digitaltwin.aas4j.v3.model.Property;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty;
import org.eclipse.digitaltwin.aas4j.v3.model.Referable;
import org.eclipse.digitaltwin.aas4j.v3.model.Submodel;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList;
import org.junit.Test;

import org.eclipse.digitaltwin.aas4j.v3.dataformat.DeserializationException;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.util.Examples;
import org.eclipse.digitaltwin.aas4j.v3.model.Environment;
import org.eclipse.digitaltwin.aas4j.v3.model.Property;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty;

import org.junit.Assert;


public class JsonReferableDeserializerTest {

@Test
Expand Down Expand Up @@ -115,4 +119,18 @@ public void testPropertyFromNode() throws Exception {
Property actual = new JsonDeserializer().readReferable(input, Property.class);
assertEquals(expected, actual);
}

@Test
public void testExtensionMinimal() throws Exception {
Environment expected = Examples.EXTENSION_MINIMAL.getModel();
Environment actual = new JsonDeserializer().read(Examples.EXTENSION_MINIMAL.fileContentStream());
assertEquals(expected, actual);
}

@Test
public void testExtensionMaximal() throws Exception {
Environment expected = Examples.EXTENSION_MAXIMAL.getModel();
Environment actual = new JsonDeserializer().read(Examples.EXTENSION_MAXIMAL.fileContentStream());
assertEquals(expected, actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testSerializeAAS() throws IOException, SerializationException, JSONE
}

@Test
public void testSerializeWithAssetInformation() throws SerializationException, JSONException, IOException {
public void testSerializeAASWithAssetInformation() throws SerializationException, JSONException, IOException {
compare(Examples.ASSET_ADMINISTRATION_SHELL_WITH_ASSET_INFORMATION);
}

Expand Down Expand Up @@ -105,6 +105,16 @@ public void testSerializePropertyToNode() throws IOException, SerializationExcep
Assert.assertEquals(expected, actual);
}

@Test
public void testSerializeExtensionMinimal() throws SerializationException, JSONException, IOException {
compare(Examples.EXTENSION_MINIMAL);
}

@Test
public void testSerializeExtensionMaximal() throws SerializationException, JSONException, IOException {
compare(Examples.EXTENSION_MAXIMAL);
}

@SuppressWarnings("unchecked")
private void compare(ExampleData<?> exampleData) throws IOException, SerializationException, JSONException {
String expected = exampleData.fileContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection;
import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.*;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetInformation;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultConceptDescription;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEnvironment;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultResource;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSpecificAssetID;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementList;

public class Examples {

public static final ExampleData<Environment> EXAMPLE_FULL = ExampleData.of(AASFull.createEnvironment(), "Example-Full.json");
public static final ExampleData<Environment> EXAMPLE_FULL = ExampleData.of(AASFull.createEnvironment(), "Example-Full.json");

public static final ExampleData<Environment> EXAMPLE_SIMPLE = ExampleData.of(AASSimple.createEnvironment(), "Example-Simple.json");
public static final ExampleData<Environment> EXAMPLE_SIMPLE = ExampleData.of(AASSimple.createEnvironment(), "Example-Simple.json");

public static final ExampleData<Environment> ENVIRONMENT_EMPTY = ExampleData.of(new DefaultEnvironment.Builder().build(), "Environment-Empty.json");

Expand Down Expand Up @@ -70,8 +78,8 @@ public class Examples {
.build(),
"AssetAdministrationShell-WithAssetInformation.json");

public static final ExampleData<AssetAdministrationShell> ASSET_ADMINISTRATION_SHELL = ExampleData.of(AASFull.createEnvironment().getAssetAdministrationShells().get(0), "AssetAdministrationShell.json");
public static final ExampleData<AssetAdministrationShell> ASSET_ADMINISTRATION_SHELL = ExampleData.of(AASFull.createEnvironment().getAssetAdministrationShells().get(0), "AssetAdministrationShell.json");

public static final ExampleData<ConceptDescription> CONCEPT_DESCRIPTION_DATA_SPECIFICATION_PHYSICAL_UNIT = ExampleData.of(
new DefaultConceptDescription.Builder()
.id("https://example.org/ConceptDescription")
Expand All @@ -83,28 +91,28 @@ public class Examples {
.value("https://admin-shell.io/DataSpecificationTemplates/DataSpecificationPhysicalUnit/3/0/RC02")
.build())
.build())
// .dataSpecificationContent(new DefaultDataSpecificationPhysicalUnit.Builder()
// .conversionFactor("1.0")
// .eceCode("ece-code")
// .eceName("ece-name")
// .definition(new DefaultLangString.Builder()
// .language("en")
// .text("definition-en")
// .build())
// .definition(new DefaultLangString.Builder()
// .language("de")
// .text("definition-de")
// .build())
// .nistName("nist-name")
// .dinNotation("din-notation")
// .siName("si-name")
// .registrationAuthorityId("registration-authority-id")
// .siNotation("si-notation")
// .sourceOfDefinition("source-of-definition")
// .supplier("supplier")
// .unitName("unit-name")
// .unitSymbol("unit-symbol")
// .build())
// .dataSpecificationContent(new DefaultDataSpecificationPhysicalUnit.Builder()
// .conversionFactor("1.0")
// .eceCode("ece-code")
// .eceName("ece-name")
// .definition(new DefaultLangString.Builder()
// .language("en")
// .text("definition-en")
// .build())
// .definition(new DefaultLangString.Builder()
// .language("de")
// .text("definition-de")
// .build())
// .nistName("nist-name")
// .dinNotation("din-notation")
// .siName("si-name")
// .registrationAuthorityId("registration-authority-id")
// .siNotation("si-notation")
// .sourceOfDefinition("source-of-definition")
// .supplier("supplier")
// .unitName("unit-name")
// .unitSymbol("unit-symbol")
// .build())
.build())
.build(),
"ConceptDescription-DataSpecificationPhysicalUnit.json");
Expand All @@ -113,24 +121,28 @@ public class Examples {
List.of(AASFull.createEnvironment().getSubmodels().get(0).getSubmodelElements().get(0),
AASFull.createEnvironment().getSubmodels().get(0).getSubmodelElements().get(1)),
"SubmodelElement-List.json");

public static final ExampleData<List<Submodel>> SUBMODEL_LIST_OF = ExampleData.of(
List.of(AASFull.createEnvironment().getSubmodels().get(0),
AASFull.createEnvironment().getSubmodels().get(1)),
"Submodel-List.json");

public static final ExampleData<Submodel> SUBMODEL = ExampleData.of(AASFull.createEnvironment().getSubmodels().get(0), "Submodel.json");
public static final ExampleData<Submodel> SUBMODEL = ExampleData.of(AASFull.createEnvironment().getSubmodels().get(0), "Submodel.json");

public static final ExampleData<SubmodelElement> SUBMODEL_ELEMENT = ExampleData.of(AASFull.createEnvironment().getSubmodels().get(0).getSubmodelElements().get(0), "SubmodelElement.json");
public static final ExampleData<SubmodelElement> SUBMODEL_ELEMENT = ExampleData.of(AASFull.createEnvironment().getSubmodels().get(0).getSubmodelElements().get(0), "SubmodelElement.json");

public static final ExampleData<SubmodelElementCollection> SUBMODEL_ELEMENT_COLLECTION = ExampleData.of((SubmodelElementCollection) AASFull.createEnvironment().getSubmodels().get(6).getSubmodelElements().get(6),
"SubmodelElementCollection.json");
public static final ExampleData<SubmodelElementCollection> SUBMODEL_ELEMENT_COLLECTION = ExampleData.of((SubmodelElementCollection) AASFull.createEnvironment().getSubmodels().get(6).getSubmodelElements().get(6),
"SubmodelElementCollection.json");

public static final ExampleData<SubmodelElementList> SUBMODEL_ELEMENT_LIST_EMPTY = ExampleData.of(
new DefaultSubmodelElementList.Builder()
.idShort("submodelElementList")
.orderRelevant(true)
.build(), "SubmodelElementList-Empty.json");

public static final ExampleData<SubmodelElementList> SUBMODEL_ELEMENT_LIST = ExampleData.of((SubmodelElementList) AASFull.createEnvironment().getSubmodels().get(6).getSubmodelElements().get(5), "SubmodelElementList.json");

public static final ExampleData<SubmodelElementList> SUBMODEL_ELEMENT_LIST = ExampleData.of((SubmodelElementList) AASFull.createEnvironment().getSubmodels().get(6).getSubmodelElements().get(5), "SubmodelElementList.json");

public static final ExampleData<Environment> EXTENSION_MINIMAL = ExampleData.of(org.eclipse.digitaltwin.aas4j.v3.dataformat.core.Examples.EXTENSION_MINIMAL, "admin-shell-io/Extension/Minimal.json");

public static final ExampleData<Environment> EXTENSION_MAXIMAL = ExampleData.of(org.eclipse.digitaltwin.aas4j.v3.dataformat.core.Examples.EXTENSION_MAXIMAL, "admin-shell-io/Extension/Maximal.json");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"assetAdministrationShells": [
{
"assetInformation": {
"assetKind": "NotApplicable",
"globalAssetId": "something_eea66fa1"
},
"extensions": [
{
"name": "something_aae6caf4",
"refersTo": [
{
"keys": [
{
"type": "Submodel",
"value": "urn:another-example01:f7faa581"
}
],
"type": "ModelReference"
}
],
"semanticId": {
"keys": [
{
"type": "GlobalReference",
"value": "urn:another-company07:4d1bd2cb"
}
],
"type": "ExternalReference"
},
"supplementalSemanticIds": [
{
"keys": [
{
"type": "GlobalReference",
"value": "urn:an-example13:be48ff29"
}
],
"type": "ExternalReference"
}
],
"value": "10233",
"valueType": "xs:unsignedShort"
}
],
"id": "something_142922d6",
"modelType": "AssetAdministrationShell"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"assetAdministrationShells": [
{
"assetInformation": {
"assetKind": "NotApplicable",
"globalAssetId": "something_eea66fa1"
},
"extensions": [
{
"name": "something_aae6caf4"
}
],
"id": "something_142922d6",
"modelType": "AssetAdministrationShell"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The files contained in this directory are taken without any modification from https://github.com/admin-shell-io/aas-specs/ where they are made available under the CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/).
Loading