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;
});
}
});
}
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;
});
}
});
}
Aggregations