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