Search in sources :

Example 1 with BrowsePathTarget

use of org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathTarget 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)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)1 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)1 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)1 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)1 BrowsePathResult (org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult)1 BrowsePathTarget (org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathTarget)1 RelativePath (org.eclipse.milo.opcua.stack.core.types.structured.RelativePath)1 RelativePathElement (org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement)1