This is an automated email from the ASF dual-hosted git repository. bossenti pushed a commit to branch dev in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git
commit 066ea0451b939861ca9a1db3f728fb0b4d6ca3e2 Author: bossenti <[email protected]> AuthorDate: Tue Apr 20 16:36:11 2021 +0200 [STREAMPIPES-345] implement method to retrieve data types from server --- .../streampipes/connect/adapters/opcua/OpcUa.java | 4 ++-- .../connect/adapters/opcua/utils/OpcUaUtil.java | 26 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/opcua/OpcUa.java b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/opcua/OpcUa.java index fadad08..9bbe76e 100644 --- a/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/opcua/OpcUa.java +++ b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/opcua/OpcUa.java @@ -19,7 +19,7 @@ package org.apache.streampipes.connect.adapters.opcua; -import static org.apache.streampipes.connect.adapters.opcua.utils.OpcUaUtil.updateDataTypes; +import static org.apache.streampipes.connect.adapters.opcua.utils.OpcUaUtil.retrieveDataTypesFromServer; import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint; import static org.eclipse.milo.opcua.stack.core.util.ConversionUtil.toList; @@ -323,7 +323,7 @@ public class OpcUa { /* In case a node with sub-nodes is queried, the data types are not detected appropriately. This has to be performed separately. */ - updateDataTypes(client, discoveredNodes); + retrieveDataTypesFromServer(client, discoveredNodes); } return discoveredNodes; diff --git a/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/opcua/utils/OpcUaUtil.java b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/opcua/utils/OpcUaUtil.java index 55aecb3..3614762 100644 --- a/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/opcua/utils/OpcUaUtil.java +++ b/streampipes-connect-adapters/src/main/java/org/apache/streampipes/connect/adapters/opcua/utils/OpcUaUtil.java @@ -11,11 +11,13 @@ import org.apache.streampipes.model.schema.EventSchema; import org.apache.streampipes.model.staticproperty.Option; import org.apache.streampipes.sdk.builder.PrimitivePropertyBuilder; import org.apache.streampipes.sdk.extractor.StaticPropertyExtractor; +import org.eclipse.milo.opcua.sdk.client.OpcUaClient; +import org.eclipse.milo.opcua.stack.core.UaException; import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId; +import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger; import java.net.URI; -import java.util.ArrayList; -import java.util.List; +import java.util.*; /*** * Collection of several utility functions in context of OPC UA @@ -133,6 +135,26 @@ public class OpcUaUtil { return key; } + /** + * connects to each node individually and updates the data type in accordance to the data from the server. + * @param opcNodes List of opcNodes where the data type is not determined appropriately + */ + public static void retrieveDataTypesFromServer(OpcUaClient client, List<OpcNode> opcNodes) throws AdapterException { + + for (OpcNode opcNode : opcNodes) { + try { + UInteger dataTypeId = (UInteger) client.getAddressSpace().getVariableNode(opcNode.getNodeId()).getDataType().getIdentifier(); + OpcUaTypes.getType(dataTypeId); + opcNode.setType(OpcUaTypes.getType(dataTypeId)); + } catch (UaException e) { + throw new AdapterException("Could not guess schema for opc node! " + e.getMessage()); + } + } + + + + } + /*** * Enum for all possible labels in the context of OPC UA adapters */
