use of org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId in project milo by eclipse.
the class AddressSpace method browseNodesAsync.
/**
* Browse from {@code nodeId} using {@code browseOptions}.
* <p>
* This call completes asynchronously.
*
* @param nodeId the {@link NodeId} to start the browse from.
* @param browseOptions the {@link BrowseOptions} to use.
* @return a CompletableFuture that completes successfully with a List of {@link UaNode}s
* referenced by {@code node} given the currently configured {@link BrowseOptions} or completes
* exceptionally if a service-level error occurs.
*/
public CompletableFuture<List<? extends UaNode>> browseNodesAsync(NodeId nodeId, BrowseOptions browseOptions) {
BrowseDescription browseDescription = new BrowseDescription(nodeId, browseOptions.getBrowseDirection(), browseOptions.getReferenceTypeId(), browseOptions.isIncludeSubtypes(), browseOptions.getNodeClassMask(), uint(BrowseResultMask.All.getValue()));
CompletableFuture<List<ReferenceDescription>> browse = BrowseHelper.browse(client, browseDescription, browseOptions.getMaxReferencesPerNode());
return browse.thenCompose(references -> {
List<CompletableFuture<? extends UaNode>> cfs = references.stream().map(reference -> {
NodeClass nodeClass = reference.getNodeClass();
ExpandedNodeId xNodeId = reference.getNodeId();
ExpandedNodeId xTypeDefinitionId = reference.getTypeDefinition();
switch(nodeClass) {
case Object:
case Variable:
{
CompletableFuture<CompletableFuture<? extends UaNode>> ff = toNodeIdAsync(xNodeId).thenCombine(toNodeIdAsync(xTypeDefinitionId), (targetNodeId, typeDefinitionId) -> {
if (nodeClass == NodeClass.Object) {
return getObjectNodeAsync(targetNodeId, typeDefinitionId);
} else {
return getVariableNodeAsync(targetNodeId, typeDefinitionId);
}
});
return unwrap(ff).exceptionally(ex -> {
logger.warn("Failed to create Node from Reference to {}", reference.getNodeId(), ex);
return null;
});
}
default:
{
// TODO specialized getNode for other NodeClasses?
return toNodeIdAsync(xNodeId).thenCompose(this::getNodeAsync).exceptionally(ex -> {
logger.warn("Failed to create Node from Reference to {}", reference.getNodeId(), ex);
return null;
});
}
}
}).collect(Collectors.toList());
return sequence(cfs);
});
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId in project milo by eclipse.
the class ObjectTypeNodeLoader method loadNode16.
private void loadNode16() {
UaObjectTypeNode node = new UaObjectTypeNode(this.context, Identifiers.AuditConditionAcknowledgeEventType, new QualifiedName(0, "AuditConditionAcknowledgeEventType"), new LocalizedText("en", "AuditConditionAcknowledgeEventType"), LocalizedText.NULL_VALUE, UInteger.valueOf(0), UInteger.valueOf(0), false);
node.addReference(new Reference(Identifiers.AuditConditionAcknowledgeEventType, Identifiers.HasProperty, new ExpandedNodeId(UShort.valueOf(0), null, UInteger.valueOf(15002), UInteger.valueOf(0)), true));
node.addReference(new Reference(Identifiers.AuditConditionAcknowledgeEventType, Identifiers.HasProperty, Identifiers.AuditConditionAcknowledgeEventType_Comment.expanded(), true));
node.addReference(new Reference(Identifiers.AuditConditionAcknowledgeEventType, Identifiers.HasSubtype, Identifiers.AuditConditionEventType.expanded(), false));
this.nodeManager.addNode(node);
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId in project milo by eclipse.
the class JsonStructureCodec method opcUaToMemberTypeScalar.
@Override
protected JsonElement opcUaToMemberTypeScalar(String name, Object value, String typeName) {
if (value == null) {
return JsonNull.INSTANCE;
} else if (value instanceof Number) {
if (value instanceof UByte) {
return new JsonPrimitive(((UByte) value).shortValue());
} else if (value instanceof UShort) {
return new JsonPrimitive(((UShort) value).intValue());
} else if (value instanceof UInteger) {
return new JsonPrimitive(((UInteger) value).longValue());
} else if (value instanceof ULong) {
return new JsonPrimitive(((ULong) value).toBigInteger());
} else {
return new JsonPrimitive((Number) value);
}
} else if (value instanceof Boolean) {
return new JsonPrimitive((Boolean) value);
} else if (value instanceof String) {
return new JsonPrimitive((String) value);
} else if (value instanceof Character) {
return new JsonPrimitive((Character) value);
} else if (value instanceof JsonElement) {
return (JsonElement) value;
} else if (value instanceof DateTime) {
return new JsonPrimitive(((DateTime) value).getUtcTime());
} else if (value instanceof UUID) {
return new JsonPrimitive(value.toString());
} else if (value instanceof LocalizedText) {
return gson.toJsonTree(value);
} else if (value instanceof QualifiedName) {
return gson.toJsonTree(value);
} else if (value instanceof ByteString) {
ByteString byteString = (ByteString) value;
byte[] bs = byteString.bytesOrEmpty();
JsonArray array = new JsonArray();
for (Byte b : bs) {
array.add(new JsonPrimitive(b));
}
return array;
} else if (value instanceof XmlElement) {
String fragment = ((XmlElement) value).getFragment();
return fragment != null ? new JsonPrimitive(fragment) : JsonNull.INSTANCE;
} else if (value instanceof NodeId) {
String nodeId = ((NodeId) value).toParseableString();
return new JsonPrimitive(nodeId);
} else if (value instanceof ExpandedNodeId) {
String xNodeId = ((ExpandedNodeId) value).toParseableString();
return new JsonPrimitive(xNodeId);
} else if (value instanceof StatusCode) {
long code = ((StatusCode) value).getValue();
return new JsonPrimitive(code);
} else {
throw new RuntimeException("could not create JsonElement for value: " + value);
}
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId 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.builtin.ExpandedNodeId 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