Search in sources :

Example 1 with BrowseContext

use of org.eclipse.milo.opcua.sdk.server.api.services.ViewServices.BrowseContext 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 BrowseContext

use of org.eclipse.milo.opcua.sdk.server.api.services.ViewServices.BrowseContext 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)

Aggregations

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 (java.util.concurrent.CompletableFuture)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 AccessContext (org.eclipse.milo.opcua.sdk.server.api.AccessContext)2 ReadContext (org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext)2 BrowseContext (org.eclipse.milo.opcua.sdk.server.api.services.ViewServices.BrowseContext)2 ServiceAttributes (org.eclipse.milo.opcua.sdk.server.services.ServiceAttributes)2 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)2 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)2 UaException (org.eclipse.milo.opcua.stack.core.UaException)2 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)2 DiagnosticInfo (org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo)2 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)2