Search in sources :

Example 61 with NormalizedNodePayload

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());
        }
    }
}
Also used : SchemaInferenceStack(org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack) JSONNormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter) JSONCodecFactorySupplier(org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) Produces(javax.ws.rs.Produces) Provider(javax.ws.rs.ext.Provider) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) JsonWriterFactory(org.opendaylight.yangtools.yang.data.codec.gson.JsonWriterFactory) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) MediaType(javax.ws.rs.core.MediaType) Map(java.util.Map) OutputStreamWriter(java.io.OutputStreamWriter) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) JsonWriter(com.google.gson.stream.JsonWriter) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) OutputStream(java.io.OutputStream) DepthParam(org.opendaylight.restconf.nb.rfc8040.DepthParam) Module(org.opendaylight.yangtools.yang.model.api.Module) SchemaInferenceStack(org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack) Set(java.util.Set) IOException(java.io.IOException) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) QName(org.opendaylight.yangtools.yang.common.QName) MediaTypes(org.opendaylight.restconf.nb.rfc8040.MediaTypes) RestconfNormalizedNodeWriter(org.opendaylight.restconf.nb.rfc8040.jersey.providers.api.RestconfNormalizedNodeWriter) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) List(java.util.List) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) Type(java.lang.reflect.Type) NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) ImmutableNodes(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes) Annotation(java.lang.annotation.Annotation) JSONCodecFactory(org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactory) WebApplicationException(javax.ws.rs.WebApplicationException) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) JsonWriter(com.google.gson.stream.JsonWriter) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 62 with NormalizedNodePayload

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);
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) NotificationQueryParams(org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams) URI(java.net.URI)

Aggregations

NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)57 Test (org.junit.Test)53 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)33 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)24 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)21 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)13 QName (org.opendaylight.yangtools.yang.common.QName)13 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)12 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)12 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)12 Response (javax.ws.rs.core.Response)10 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)10 AbstractBodyReaderTest (org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest)7 XmlBodyReaderTest (org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest)7 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)6 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)5 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)5 ActionDefinition (org.opendaylight.yangtools.yang.model.api.ActionDefinition)5 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)5 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)5