Skip to content

Commit

Permalink
Adds further compatibility with AASX Package Explorer & fine-tunes wa…
Browse files Browse the repository at this point in the history
…rning messages (#278)

* Adds further compatibility with AASX Package Explorer & fine-tunes warning messages

Signed-off-by: Frank Schnicke <frank.schnicke@iese.fraunhofer.de>

* Adresses review remarks

Signed-off-by: Frank Schnicke <frank.schnicke@iese.fraunhofer.de>

---------

Signed-off-by: Frank Schnicke <frank.schnicke@iese.fraunhofer.de>
  • Loading branch information
FrankSchnicke authored Apr 10, 2024
1 parent 95172c5 commit e240ddc
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

Expand All @@ -47,7 +46,7 @@ public DataElementsDeserializer() {
public List<DataElement> deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
TreeNode treeNode = DeserializationHelper.getRootTreeNode(parser);
if (treeNode instanceof TextNode) {
return Collections.emptyList();
return new ArrayList<>();
}

ObjectNode node = (ObjectNode) treeNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.slf4j.Logger;
Expand All @@ -30,6 +29,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;

/**
* Custom deserializer for lists without individual list entry wrappers for parametrized classes.
Expand Down Expand Up @@ -57,7 +57,7 @@ public List<T> deserialize(JsonParser parser, DeserializationContext ctxt) throw
return createEntriesFromArrayNode((ArrayNode) langStringNode, parser);
}
} catch (ClassCastException e) {
logger.info("Found empty list items (e.g., '<preferredName />' of dataSpecificationIec61360) in XML. This is most likely an error.");
logger.info("Found empty list item (e.g., '<preferredName />' of dataSpecificationIec61360) in XML. This is most likely an error.");
return new ArrayList<T>();
}
}
Expand All @@ -73,6 +73,6 @@ private List<T> createEntriesFromArrayNode(ArrayNode langStringsNode, JsonParser

private List<T> createEntriesFromObjectNode(JsonNode langStringNode, JsonParser parser) throws IOException {
T entry = nodeDeserializer.readValue(langStringNode, parser);
return Collections.singletonList(entry);
return Lists.newArrayList(entry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,46 @@
*/
package org.eclipse.digitaltwin.aas4j.v3.dataformat.xml.internal.deserialization;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Lists;


public class OperationVariableDeserializer extends JsonDeserializer<List<OperationVariable>> {
private static Logger logger = LoggerFactory.getLogger(OperationVariableDeserializer.class);

@Override
public List<OperationVariable> deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectNode node = DeserializationHelper.getRootObjectNode(parser);
try {
ObjectNode node = DeserializationHelper.getRootObjectNode(parser);

if (!node.has("operationVariable")) {
return Collections.emptyList();
if (!node.has("operationVariable")) {
return new ArrayList<>();
}
JsonNode operationVariableNode = node.get("operationVariable");
if (operationVariableNode.isArray()) {
return createOperationVariablesFromArrayNode(parser, node);
} else {
OperationVariable operationVariable = DeserializationHelper.createInstanceFromNode(parser, operationVariableNode, OperationVariable.class);
return Lists.newArrayList(operationVariable);
}
} catch (ClassCastException e) {
logger.info("Found empty list item in Operation (e.g., '<outputVariables />') in XML. This is most likely an error.");
return new ArrayList<>();
}
JsonNode operationVariableNode = node.get("operationVariable");
if (operationVariableNode.isArray()) {
return createOperationVariablesFromArrayNode(parser, node);
} else {
OperationVariable operationVariable = DeserializationHelper.createInstanceFromNode(parser, operationVariableNode, OperationVariable.class);
return Collections.singletonList(operationVariable);
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,46 @@
*/
package org.eclipse.digitaltwin.aas4j.v3.dataformat.xml.internal.deserialization;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.digitaltwin.aas4j.v3.model.Qualifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.eclipse.digitaltwin.aas4j.v3.model.Qualifier;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

import com.google.common.collect.Lists;

public class QualifierDeserializer extends JsonDeserializer<List<Qualifier>> {

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

@Override
public List<Qualifier> deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectNode node = DeserializationHelper.getRootObjectNode(parser);
try {
ObjectNode node = DeserializationHelper.getRootObjectNode(parser);

if (!node.has("qualifier")) {
return Collections.emptyList();
}
JsonNode qualifierNode = node.get("qualifier");
if (qualifierNode.isArray()) {
return createConstraintsFromArrayNode(parser, node);
} else {
Qualifier qualifier = DeserializationHelper.createInstanceFromNode(parser, qualifierNode, Qualifier.class);
return Collections.singletonList(qualifier);
if (!node.has("qualifier")) {
return new ArrayList<>();
}
JsonNode qualifierNode = node.get("qualifier");
if (qualifierNode.isArray()) {
return createConstraintsFromArrayNode(parser, node);
} else {
Qualifier qualifier = DeserializationHelper.createInstanceFromNode(parser, qualifierNode,
Qualifier.class);
return Lists.newArrayList(qualifier);
}
} catch (ClassCastException e) {
logger.info("Found empty list item of qualifiers ('<qualifiers />') in XML. This is most likely an error.");
return new ArrayList<Qualifier>();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@
*/
package org.eclipse.digitaltwin.aas4j.v3.dataformat.xml.internal.deserialization;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

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

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Lists;

public class ReferencesDeserializer extends JsonDeserializer<List<Reference>> {

@Override
public List<Reference> deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
TreeNode treeNode = DeserializationHelper.getRootTreeNode(parser);
treeNode = treeNode.get("reference");
treeNode = treeNode.get("reference");
if (treeNode.isArray()) {
return createReferencesFromArray(parser, (ArrayNode) treeNode);
} else {
Expand All @@ -44,7 +45,7 @@ public List<Reference> deserialize(JsonParser parser, DeserializationContext ctx

private List<Reference> createReferencesFromObjectNode(JsonParser parser, ObjectNode node) throws IOException {
Reference reference = createReference(parser, node);
return Collections.singletonList(reference);
return Lists.newArrayList(reference);
}

private List<Reference> createReferencesFromArray(JsonParser parser, ArrayNode arrayNode) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

Expand All @@ -48,14 +47,14 @@ public SubmodelElementsDeserializer() {
public List<SubmodelElement> deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
TreeNode treeNode = DeserializationHelper.getRootTreeNode(parser);
if (treeNode instanceof TextNode) {
return Collections.emptyList();
return new ArrayList<>();
} else {
return createSubmodelElements(parser, ctxt, treeNode);
}
}

private List<SubmodelElement> createSubmodelElements(JsonParser parser, DeserializationContext ctxt, TreeNode treeNode) throws IOException, JsonProcessingException {
if (treeNode.isArray()) {
if (treeNode.isArray()) {
return getSubmodelElementsFromArrayNode(parser, ctxt, (ArrayNode) treeNode);
} else {
return getSubmodelElementsFromObjectNode(parser, ctxt, (JsonNode) treeNode);
Expand Down Expand Up @@ -100,7 +99,7 @@ private List<SubmodelElement> getSubmodelElementsFromArrayNode(JsonParser parser

private SubmodelElement getSubmodelElementFromJsonNode(JsonParser parser, DeserializationContext ctxt, JsonNode nodeSubmodelElement) throws IOException, JsonProcessingException {
JsonParser parserReference = parser.getCodec().getFactory().getCodec().treeAsTokens(nodeSubmodelElement);
return deserializer.deserialize(parserReference, ctxt);
return deserializer.deserialize(parserReference, ctxt);
}

}

0 comments on commit e240ddc

Please sign in to comment.