Search in sources :

Example 1 with RelativePathElement

use of org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement in project milo by eclipse.

the class BrowsePathsHelper method target.

private CompletableFuture<List<ExpandedNodeId>> target(NodeId nodeId, RelativePathElement element) {
    NodeId referenceTypeId = element.getReferenceTypeId();
    boolean includeSubtypes = element.getIncludeSubtypes();
    QualifiedName targetName = element.getTargetName();
    if (targetName.isNull()) {
        return failedUaFuture(StatusCodes.Bad_BrowseNameInvalid);
    }
    BrowseContext browseContext = new BrowseContext(server, context.getSession().orElse(null));
    server.getAddressSpaceManager().browse(browseContext, nodeId);
    CompletableFuture<List<Reference>> future = browseContext.getFuture();
    return future.thenCompose(references -> {
        List<ExpandedNodeId> targetNodeIds = references.stream().filter(r -> referenceTypeId.isNull() || r.getReferenceTypeId().equals(referenceTypeId) || (includeSubtypes && r.subtypeOf(referenceTypeId, server.getReferenceTypes()))).filter(r -> r.isInverse() == element.getIsInverse()).map(Reference::getTargetNodeId).collect(toList());
        if (targetNodeIds.isEmpty()) {
            return failedUaFuture(StatusCodes.Bad_NoMatch);
        } else {
            return readTargetBrowseNames(targetNodeIds).thenApply(browseNames -> {
                List<ExpandedNodeId> targets = newArrayList();
                for (int i = 0; i < targetNodeIds.size(); i++) {
                    ExpandedNodeId targetNodeId = targetNodeIds.get(i);
                    QualifiedName browseName = browseNames.get(i);
                    if (matchesTarget(browseName, targetName)) {
                        targets.add(targetNodeId);
                    }
                }
                return targets;
            });
        }
    });
}
Also used : ReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) FutureUtils.sequence(org.eclipse.milo.opcua.stack.core.util.FutureUtils.sequence) CompletableFuture(java.util.concurrent.CompletableFuture) ConversionUtil.a(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.a) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) ServiceRequest(org.eclipse.milo.opcua.stack.server.services.ServiceRequest) BrowsePathTarget(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathTarget) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) TranslateBrowsePathsToNodeIdsRequest(org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsRequest) ServiceAttributes(org.eclipse.milo.opcua.sdk.server.services.ServiceAttributes) Reference(org.eclipse.milo.opcua.sdk.core.Reference) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) Lists.newArrayListWithCapacity(com.google.common.collect.Lists.newArrayListWithCapacity) BrowsePath(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePath) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) RelativePathElement(org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) BrowsePathResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) RelativePath(org.eclipse.milo.opcua.stack.core.types.structured.RelativePath) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) AccessContext(org.eclipse.milo.opcua.sdk.server.api.AccessContext) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) UaException(org.eclipse.milo.opcua.stack.core.UaException) TranslateBrowsePathsToNodeIdsResponse(org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsResponse) Optional(java.util.Optional) BrowseContext(org.eclipse.milo.opcua.sdk.server.api.services.ViewServices.BrowseContext) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) Collections(java.util.Collections) BrowseContext(org.eclipse.milo.opcua.sdk.server.api.services.ViewServices.BrowseContext) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)

Example 2 with RelativePathElement

use of org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement in project milo by eclipse.

the class BrowsePathsHelper method translate.

private CompletableFuture<BrowsePathResult> translate(BrowsePath browsePath) {
    CompletableFuture<BrowsePathResult> future = new CompletableFuture<>();
    NodeId startingNode = browsePath.getStartingNode();
    RelativePath relativePath = browsePath.getRelativePath();
    if (startingNode.isNull()) {
        future.complete(new BrowsePathResult(new StatusCode(StatusCodes.Bad_NodeIdInvalid), new BrowsePathTarget[0]));
        return future;
    }
    List<RelativePathElement> relativePathElements = l(relativePath.getElements());
    if (relativePathElements.isEmpty()) {
        future.complete(new BrowsePathResult(new StatusCode(StatusCodes.Bad_NothingToDo), new BrowsePathTarget[0]));
        return future;
    }
    follow(startingNode, relativePathElements).whenComplete((targets, ex) -> {
        if (targets != null) {
            BrowsePathResult result;
            if (!targets.isEmpty()) {
                result = new BrowsePathResult(StatusCode.GOOD, a(targets, BrowsePathTarget.class));
            } else {
                result = new BrowsePathResult(new StatusCode(StatusCodes.Bad_NoMatch), new BrowsePathTarget[0]);
            }
            future.complete(result);
        } else {
            StatusCode statusCode = UaException.extractStatusCode(ex).orElse(new StatusCode(StatusCodes.Bad_NoMatch));
            BrowsePathResult result = new BrowsePathResult(statusCode, new BrowsePathTarget[0]);
            future.complete(result);
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) BrowsePathResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult) RelativePath(org.eclipse.milo.opcua.stack.core.types.structured.RelativePath) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) RelativePathElement(org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) BrowsePathTarget(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathTarget)

Example 3 with RelativePathElement

use of org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement in project milo by eclipse.

the class BrowsePathsHelper method next.

private CompletableFuture<ExpandedNodeId> next(NodeId nodeId, RelativePathElement element) {
    NodeId referenceTypeId = element.getReferenceTypeId();
    boolean includeSubtypes = element.getIncludeSubtypes();
    QualifiedName targetName = element.getTargetName();
    if (targetName.isNull()) {
        return failedUaFuture(StatusCodes.Bad_BrowseNameInvalid);
    }
    BrowseContext browseContext = new BrowseContext(server, context.getSession().orElse(null));
    server.getAddressSpaceManager().browse(browseContext, nodeId);
    CompletableFuture<List<Reference>> future = browseContext.getFuture();
    return future.thenCompose(references -> {
        List<ExpandedNodeId> targetNodeIds = references.stream().filter(r -> referenceTypeId.isNull() || r.getReferenceTypeId().equals(referenceTypeId) || (includeSubtypes && r.subtypeOf(referenceTypeId, server.getReferenceTypes()))).filter(r -> r.isInverse() == element.getIsInverse()).map(Reference::getTargetNodeId).collect(toList());
        if (targetNodeIds.isEmpty()) {
            return failedUaFuture(StatusCodes.Bad_NoMatch);
        } else {
            return readTargetBrowseNames(targetNodeIds).thenApply(browseNames -> {
                for (int i = 0; i < targetNodeIds.size(); i++) {
                    ExpandedNodeId targetNodeId = targetNodeIds.get(i);
                    QualifiedName browseName = browseNames.get(i);
                    if (browseName.equals(targetName)) {
                        return targetNodeId;
                    }
                }
                return ExpandedNodeId.NULL_VALUE;
            });
        }
    });
}
Also used : ReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) FutureUtils.sequence(org.eclipse.milo.opcua.stack.core.util.FutureUtils.sequence) CompletableFuture(java.util.concurrent.CompletableFuture) ConversionUtil.a(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.a) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) ServiceRequest(org.eclipse.milo.opcua.stack.server.services.ServiceRequest) BrowsePathTarget(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathTarget) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) TranslateBrowsePathsToNodeIdsRequest(org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsRequest) ServiceAttributes(org.eclipse.milo.opcua.sdk.server.services.ServiceAttributes) Reference(org.eclipse.milo.opcua.sdk.core.Reference) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) Lists.newArrayListWithCapacity(com.google.common.collect.Lists.newArrayListWithCapacity) BrowsePath(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePath) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) RelativePathElement(org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) BrowsePathResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) RelativePath(org.eclipse.milo.opcua.stack.core.types.structured.RelativePath) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) AccessContext(org.eclipse.milo.opcua.sdk.server.api.AccessContext) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) UaException(org.eclipse.milo.opcua.stack.core.UaException) TranslateBrowsePathsToNodeIdsResponse(org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsResponse) Optional(java.util.Optional) BrowseContext(org.eclipse.milo.opcua.sdk.server.api.services.ViewServices.BrowseContext) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) Collections(java.util.Collections) BrowseContext(org.eclipse.milo.opcua.sdk.server.api.services.ViewServices.BrowseContext) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)

Example 4 with RelativePathElement

use of org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement in project milo by eclipse.

the class TranslateBrowsePathExample method run.

@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
    // synchronous connect
    client.connect().get();
    TranslateBrowsePathsToNodeIdsResponse response = client.translateBrowsePaths(newArrayList(new BrowsePath(Identifiers.ObjectsFolder, new RelativePath(new RelativePathElement[] { new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(2, "HelloWorld")), new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(2, "ScalarTypes")), new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(2, "UInt64")) })))).get();
    BrowsePathResult result = l(response.getResults()).get(0);
    StatusCode statusCode = result.getStatusCode();
    logger.info("Status={}", statusCode);
    l(result.getTargets()).forEach(target -> logger.info("TargetId={}", target.getTargetId()));
    future.complete(client);
}
Also used : RelativePath(org.eclipse.milo.opcua.stack.core.types.structured.RelativePath) BrowsePathResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) RelativePathElement(org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement) TranslateBrowsePathsToNodeIdsResponse(org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsResponse) BrowsePath(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePath) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

Aggregations

StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)4 BrowsePathResult (org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult)4 RelativePath (org.eclipse.milo.opcua.stack.core.types.structured.RelativePath)4 RelativePathElement (org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)3 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)3 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)3 BrowsePath (org.eclipse.milo.opcua.stack.core.types.structured.BrowsePath)3 BrowsePathTarget (org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathTarget)3 TranslateBrowsePathsToNodeIdsResponse (org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsResponse)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Lists.newArrayListWithCapacity (com.google.common.collect.Lists.newArrayListWithCapacity)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)2 Collectors.toList (java.util.stream.Collectors.toList)2 Reference (org.eclipse.milo.opcua.sdk.core.Reference)2 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)2