info.unterrainer.commons.opcuabrowser.dtos.BrowseNode Maven / Gradle / Ivy
The newest version!
package info.unterrainer.commons.opcuabrowser.dtos;
import java.util.concurrent.ExecutionException;
import org.eclipse.milo.opcua.sdk.client.nodes.UaNode;
import org.eclipse.milo.opcua.sdk.core.nodes.Node;
import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName;
import org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass;
import org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription;
import com.fasterxml.jackson.annotation.JsonIgnore;
import info.unterrainer.commons.opcuabrowser.OpcUaClient;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import lombok.extern.slf4j.Slf4j;
@Data
@NoArgsConstructor
@SuperBuilder(toBuilder = true)
@Slf4j
public class BrowseNode {
@JsonIgnore
private NodeId nodeId;
private String name;
private String id;
private String description;
private String displayName;
private String type;
public void log(final String indent) {
log.info("[{}] browse=[{}] id=[{}] desc=[{}] display=[{}] class=[{}]", indent, name, id, description,
displayName, type);
}
public static BrowseNode getFrom(final ReferenceDescription ref, final OpcUaClient client) throws Exception {
NodeId nodeId = ref.getNodeId().toNodeIdOrThrow(client.getNamespaceTable());
UaNode node = client.getAddressSpace().getNode(nodeId);
return getFrom(node);
}
public static BrowseNode getFrom(final Node node) throws InterruptedException, ExecutionException {
QualifiedName fBrowseName = node.getBrowseName();
NodeId fNodeId = node.getNodeId();
LocalizedText fDisplayName = node.getDisplayName();
LocalizedText fDescription = node.getDescription();
NodeClass fNodeClass = node.getNodeClass();
BrowseNode n = new BrowseNode();
n.setNodeId(fNodeId);
n.setDescription(fDescription.getText());
n.setDisplayName(fDisplayName.getText());
n.setName(fBrowseName.getName());
n.setId(fNodeId.toParseableString());
n.setType(fNodeClass.toString());
return n;
}
}