use of org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload in project netconf by opendaylight.
the class JsonNormalizedNodeBodyWriter method writeTo.
@Override
public void writeTo(final NormalizedNodePayload context, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException {
final NormalizedNode data = context.getData();
if (data == null) {
return;
}
@SuppressWarnings("unchecked") final InstanceIdentifierContext<SchemaNode> identifierCtx = (InstanceIdentifierContext<SchemaNode>) context.getInstanceIdentifierContext();
final SchemaInferenceStack stack = SchemaInferenceStack.of(identifierCtx.getSchemaContext());
identifierCtx.getInstanceIdentifier().getPathArguments().stream().filter(arg -> !(arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates)).filter(arg -> !(arg instanceof YangInstanceIdentifier.AugmentationIdentifier)).forEach(p -> stack.enterSchemaTree(p.getNodeType()));
final SchemaPath path = stack.toSchemaPath();
final var pretty = context.getWriterParameters().prettyPrint();
try (JsonWriter jsonWriter = createJsonWriter(entityStream, pretty == null ? false : pretty.value())) {
jsonWriter.beginObject();
writeNormalizedNode(jsonWriter, path, identifierCtx, data, context.getWriterParameters().depth(), context.getWriterParameters().fields());
jsonWriter.endObject();
jsonWriter.flush();
}
if (httpHeaders != null) {
for (final Map.Entry<String, Object> entry : context.getNewHeaders().entrySet()) {
httpHeaders.add(entry.getKey(), entry.getValue());
}
}
}
use of org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload in project netconf by opendaylight.
the class RestconfStreamsSubscriptionServiceImpl method subscribeToStream.
@Override
public NormalizedNodePayload subscribeToStream(final String identifier, final UriInfo uriInfo) {
final NotificationQueryParams params = QueryParams.newNotificationQueryParams(uriInfo);
final URI response;
if (identifier.contains(RestconfStreamsConstants.DATA_SUBSCRIPTION)) {
response = streamUtils.subscribeToDataStream(identifier, uriInfo, params, handlersHolder);
} else if (identifier.contains(RestconfStreamsConstants.NOTIFICATION_STREAM)) {
response = streamUtils.subscribeToYangStream(identifier, uriInfo, params, handlersHolder);
} else {
final String msg = "Bad type of notification of sal-remote";
LOG.warn(msg);
throw new RestconfDocumentedException(msg);
}
// prepare node with value of location
return NormalizedNodePayload.ofLocation(prepareIIDSubsStreamOutput(handlersHolder.getSchemaHandler()), LOCATION_NODEID, response);
}
Aggregations