Search in sources :

Example 1 with BrowsePathResult

use of org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult 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 2 with BrowsePathResult

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

the class BrowsePathsHelper method onTranslateBrowsePaths.

public void onTranslateBrowsePaths(ServiceRequest service) {
    TranslateBrowsePathsToNodeIdsRequest request = (TranslateBrowsePathsToNodeIdsRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    List<BrowsePath> browsePaths = l(request.getBrowsePaths());
    if (browsePaths.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (browsePaths.size() > server.getConfig().getLimits().getMaxNodesPerTranslateBrowsePathsToNodeIds().intValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    List<CompletableFuture<BrowsePathResult>> futures = newArrayListWithCapacity(browsePaths.size());
    for (BrowsePath browsePath : browsePaths) {
        futures.add(translate(browsePath));
    }
    sequence(futures).thenAcceptAsync(results -> {
        ResponseHeader header = service.createResponseHeader();
        TranslateBrowsePathsToNodeIdsResponse response = new TranslateBrowsePathsToNodeIdsResponse(header, a(results, BrowsePathResult.class), new DiagnosticInfo[0]);
        service.setResponse(response);
    }, server.getExecutorService());
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) CompletableFuture(java.util.concurrent.CompletableFuture) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) BrowsePathResult(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult) TranslateBrowsePathsToNodeIdsRequest(org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsRequest) TranslateBrowsePathsToNodeIdsResponse(org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsResponse) BrowsePath(org.eclipse.milo.opcua.stack.core.types.structured.BrowsePath)

Example 3 with BrowsePathResult

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

BrowsePathResult (org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathResult)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)2 BrowsePath (org.eclipse.milo.opcua.stack.core.types.structured.BrowsePath)2 RelativePath (org.eclipse.milo.opcua.stack.core.types.structured.RelativePath)2 RelativePathElement (org.eclipse.milo.opcua.stack.core.types.structured.RelativePathElement)2 TranslateBrowsePathsToNodeIdsResponse (org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsResponse)2 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)1 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)1 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)1 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)1 BrowsePathTarget (org.eclipse.milo.opcua.stack.core.types.structured.BrowsePathTarget)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1 TranslateBrowsePathsToNodeIdsRequest (org.eclipse.milo.opcua.stack.core.types.structured.TranslateBrowsePathsToNodeIdsRequest)1