Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class AASFull {
public static final ConceptDescription CONCEPT_DESCRIPTION_4 = createConceptDescription4();
public static final Environment ENVIRONMENT = createEnvironment();
public static final String AAS_3_1_DATA_SPECIFICATION_IEC_61360 =
"https://admin-shell.io/aas/3/1/DataSpecificationIec61360";
"https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the latest documentation of IDTA-01003-a - Data Specification IEC61360, the schema for IEC61360 is included as embedded data specification in the release of IDTA-01001-3-1 or its bugfix releases.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to look up the link again (I should add that to the commit): https://industrialdigitaltwin.io/aas-specifications/IDTA-01003-a/v3.1.1/specification.html Your thoughts?


public static AssetAdministrationShell createAAS1() {
return new DefaultAssetAdministrationShell.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public class AASSimple {
private static final String SUBMODEL_OPERATIONAL_DATA_PROPERTY_VALUE = "4370";
private static final String SUBMODEL_OPERATIONAL_DATA_PROPERTY_VALUETYPE = "integer";
public static final String AAS_3_1_DATA_SPECIFICATION_IEC_61360 =
"https://admin-shell.io/aas/3/1/DataSpecificationIec61360";
"https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above


public AASSimple() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public class Examples {
new DefaultKey.Builder()
.type(KeyTypes.GLOBAL_REFERENCE)
.value(
"https://admin-shell.io/aas/3/1/DataSpecificationIec61360")
"https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

.build())
.build())
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dataSpecification" : {
"keys" : [ {
"type" : "GlobalReference",
"value" : "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value" : "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

} ],
"type" : "ExternalReference"
},
Expand Down
10 changes: 5 additions & 5 deletions dataformat-json/src/test/resources/Environment-Invalid.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above regarding 'DataSpecificationIec61360'

Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "GlobalReference"
Expand Down Expand Up @@ -261,7 +261,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "GlobalReference"
Expand Down Expand Up @@ -316,7 +316,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "GlobalReference"
Expand Down Expand Up @@ -370,7 +370,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "GlobalReference"
Expand Down Expand Up @@ -432,7 +432,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "GlobalReference"
Expand Down
2 changes: 1 addition & 1 deletion dataformat-json/src/test/resources/Example-Full.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above regarding 'DataSpecificationIec61360'

Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down
10 changes: 5 additions & 5 deletions dataformat-json/src/test/resources/Example-Simple.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above regarding 'DataSpecificationIec61360'

Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down Expand Up @@ -135,7 +135,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down Expand Up @@ -186,7 +186,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down Expand Up @@ -247,7 +247,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down Expand Up @@ -313,7 +313,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down
4 changes: 2 additions & 2 deletions dataformat-json/src/test/resources/MotorAAS-Reduced.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above regarding 'DataSpecificationIec61360'

Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down Expand Up @@ -192,7 +192,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down
10 changes: 5 additions & 5 deletions dataformat-json/src/test/resources/MotorAAS.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above regarding 'DataSpecificationIec61360'

Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down Expand Up @@ -246,7 +246,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down Expand Up @@ -299,7 +299,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down Expand Up @@ -352,7 +352,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down Expand Up @@ -414,7 +414,7 @@
"keys": [
{
"type": "GlobalReference",
"value": "https://admin-shell.io/aas/3/1/DataSpecificationIec61360"
"value": "https://admin-shell.io/DataSpecificationTemplates/DataSpecificationIec61360/3"
}
],
"type": "ExternalReference"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String[] findSerializationPropertyOrder(AnnotatedClass ac) {
"kind",
"semanticId",
"qualifiers",
"embeddedDataSpecification",
"embeddedDataSpecifications",
"dataSpecifications",
"isCaseOf",
"security",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.util.ReflectionHelper;
import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EmbeddedDataSpecificationsDeserializer
extends JsonDeserializer<DataSpecificationContent> {

private static final Logger logger =
LoggerFactory.getLogger(EmbeddedDataSpecificationsDeserializer.class);

@Override
public DataSpecificationContent deserialize(JsonParser parser, DeserializationContext ctxt)
throws IOException {
Expand All @@ -42,24 +49,103 @@ public DataSpecificationContent deserialize(JsonParser parser, DeserializationCo

private DataSpecificationContent createEmbeddedDataSpecificationsFromContent(
JsonParser parser, JsonNode node) throws IOException {
String class_name = node.fieldNames().next();
JsonNode contentNode = node;
if (contentNode.isObject() && contentNode.has("dataSpecificationContent")) {
contentNode = contentNode.get("dataSpecificationContent");
}
if (contentNode == null || contentNode.isNull()) {
return null;
}

Set<Class<?>> subtypes = ReflectionHelper.SUBTYPES.get(DataSpecificationContent.class);
if (subtypes == null || subtypes.isEmpty()) {
throw new IOException("No known subtypes of DataSpecificationContent registered");
}
if (contentNode.isObject()) {
Iterator<Map.Entry<String, JsonNode>> fields = contentNode.fields();
while (fields.hasNext()) {
Map.Entry<String, JsonNode> field = fields.next();
DataSpecificationContent content =
tryDeserializeDataSpecification(parser, field.getKey(), field.getValue(), subtypes);
if (content != null) {
return content;
}
}
}

DataSpecificationContent direct = tryDeserializeFromNode(parser, contentNode, subtypes);
if (direct != null) {
return direct;
}

throw new IOException(
"Was expecting a known subclass of DataSpecificationContent but found " + contentNode);
}

private DataSpecificationContent tryDeserializeDataSpecification(
JsonParser parser, String fieldName, JsonNode fieldValue, Set<Class<?>> subtypes)
throws IOException {
Iterator<Class<?>> iter = subtypes.iterator();
while (iter.hasNext()) {
Class clazz = iter.next();
if (clazz.getSimpleName().toLowerCase().contains(class_name.toLowerCase())) {
Class<?> clazz = iter.next();
if (matchesType(fieldName, clazz)) {
try {
JsonNode nodeContent = node.get(class_name);
return (DataSpecificationContent)
DeserializationHelper.createInstanceFromNode(parser, nodeContent, clazz);
DeserializationHelper.createInstanceFromNode(parser, fieldValue, clazz);
} catch (Exception e) {
// do nothing and try next in list
if (logger.isDebugEnabled()) {
logger.debug(
"Failed to deserialize field '{}' as {}: {}",
fieldName,
clazz.getSimpleName(),
e.getMessage());
}
}
}
}
;
return null;
}

throw new IOException(
"Was expecting a known subclass of DataSpecificationContent but found " + class_name);
private DataSpecificationContent tryDeserializeFromNode(
JsonParser parser, JsonNode node, Set<Class<?>> subtypes) throws IOException {
for (Class<?> clazz : subtypes) {
try {
return (DataSpecificationContent)
DeserializationHelper.createInstanceFromNode(parser, node, clazz);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug(
"Failed to deserialize node as {}: {}", clazz.getSimpleName(), e.getMessage());
}
}
}
return null;
}

private boolean matchesType(String fieldName, Class<?> clazz) {
String normalizedField = normalize(fieldName);
return matchesType(normalizedField, clazz, new HashSet<>());
}

private boolean matchesType(String normalizedFieldName, Class<?> clazz, Set<Class<?>> visited) {
if (clazz == null || !visited.add(clazz)) {
return false;
}
if (normalizedFieldName.equals(normalize(clazz.getSimpleName()))) {
return true;
}
for (Class<?> iface : clazz.getInterfaces()) {
if (matchesType(normalizedFieldName, iface, visited)) {
return true;
}
}
return matchesType(normalizedFieldName, clazz.getSuperclass(), visited);
}

private String normalize(String value) {
if (value == null) {
return "";
}
return value.toLowerCase().replace("dataspecification", "").replaceAll("[^a-z0-9]", "");
}
}
Loading