use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode 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.builtin.StatusCode in project milo by eclipse.
the class Subscription method returnKeepAlive.
private void returnKeepAlive(ServiceRequest service) {
ResponseHeader header = service.createResponseHeader();
UInteger sequenceNumber = uint(currentSequenceNumber());
NotificationMessage notificationMessage = new NotificationMessage(sequenceNumber, DateTime.now(), new ExtensionObject[0]);
UInteger[] available = getAvailableSequenceNumbers();
StatusCode[] acknowledgeResults = service.attr(KEY_ACK_RESULTS).get();
PublishResponse response = new PublishResponse(header, subscriptionId, available, moreNotifications, notificationMessage, acknowledgeResults, new DiagnosticInfo[0]);
service.setResponse(response);
logger.debug("[id={}] returned keep-alive NotificationMessage sequenceNumber={}.", subscriptionId, sequenceNumber);
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.
the class ManagedAddressSpace method write.
@Override
public void write(WriteContext context, List<WriteValue> writeValues) {
List<StatusCode> results = Lists.newArrayListWithCapacity(writeValues.size());
for (WriteValue writeValue : writeValues) {
UaServerNode node = nodeManager.get(writeValue.getNodeId());
if (node != null) {
try {
node.writeAttribute(new AttributeContext(context), writeValue.getAttributeId(), writeValue.getValue(), writeValue.getIndexRange());
results.add(StatusCode.GOOD);
logger.debug("Wrote value {} to {} attribute of {}", writeValue.getValue().getValue(), AttributeId.from(writeValue.getAttributeId()).map(Object::toString).orElse("unknown"), node.getNodeId());
} catch (UaException e) {
logger.error("Unable to write value={}", writeValue.getValue(), e);
results.add(e.getStatusCode());
}
} else {
results.add(new StatusCode(StatusCodes.Bad_NodeIdUnknown));
}
}
context.success(results);
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.
the class EventContentFilter method validateFilterElement.
private static ContentFilterElementResult validateFilterElement(@NotNull FilterContext context, @NotNull ContentFilterElement filterElement) {
FilterOperator filterOperator = filterElement.getFilterOperator();
if (!Operators.SUPPORTED_OPERATORS.contains(filterOperator)) {
return new ContentFilterElementResult(new StatusCode(StatusCodes.Bad_FilterOperatorUnsupported), new StatusCode[0], new DiagnosticInfo[0]);
}
ExtensionObject[] xos = filterElement.getFilterOperands();
if (xos == null || xos.length == 0) {
return new ContentFilterElementResult(new StatusCode(StatusCodes.Bad_FilterOperandCountMismatch), new StatusCode[0], new DiagnosticInfo[0]);
}
FilterOperand[] operands = new FilterOperand[xos.length];
StatusCode[] operandStatusCodes = new StatusCode[xos.length];
for (int i = 0; i < xos.length; i++) {
Object operand = xos[i].decodeOrNull(context.getServer().getSerializationContext());
if (operand instanceof FilterOperand) {
operands[i] = (FilterOperand) operand;
if (operand instanceof SimpleAttributeOperand) {
try {
validateSimpleOperand(context, (SimpleAttributeOperand) operand);
operandStatusCodes[i] = StatusCode.GOOD;
} catch (ValidationException e) {
operandStatusCodes[i] = e.getStatusCode();
}
} else if (operand instanceof ElementOperand) {
operandStatusCodes[i] = StatusCode.GOOD;
} else if (operand instanceof LiteralOperand) {
operandStatusCodes[i] = StatusCode.GOOD;
} else {
// includes AttributeOperand and any unknown/unhandle subclasses
operandStatusCodes[i] = new StatusCode(StatusCodes.Bad_FilterOperandInvalid);
}
} else {
operandStatusCodes[i] = new StatusCode(StatusCodes.Bad_FilterOperandInvalid);
}
}
StatusCode operatorStatus = StatusCode.GOOD;
try {
Operator<?> operator = getOperator(filterOperator);
operator.validate(context, operands);
} catch (ValidationException e) {
operatorStatus = e.getStatusCode();
}
return new ContentFilterElementResult(operatorStatus, operandStatusCodes, new DiagnosticInfo[0]);
}
use of org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode in project milo by eclipse.
the class NodeManagementServices method addNodes.
default void addNodes(AddNodesContext context, List<AddNodesItem> nodesToAdd) {
AddNodesResult result = new AddNodesResult(new StatusCode(StatusCodes.Bad_NotSupported), NodeId.NULL_VALUE);
context.success(Collections.nCopies(nodesToAdd.size(), result));
}
Aggregations