Search in sources :

Example 51 with NormalizedNodeContext

use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.

the class NnToXmlTest method prepareLeafrefData.

private static NormalizedNodeContext prepareLeafrefData() {
    final QName cont = QName.create("basic:module", "2013-12-02", "cont");
    final QName lfBoolean = QName.create("basic:module", "2013-12-02", "lfBoolean");
    final QName lfLfref = QName.create("basic:module", "2013-12-02", "lfLfref");
    final YangInstanceIdentifier yII = YangInstanceIdentifier.builder().node(cont).build();
    final DataSchemaNode contSchema = schemaContext.getDataChildByName(cont);
    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contData = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) contSchema);
    List<DataSchemaNode> instanceLf = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) contSchema, lfBoolean.getLocalName());
    DataSchemaNode schemaLf = Iterables.getFirst(instanceLf, null);
    contData.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) schemaLf).withValue(Boolean.TRUE).build());
    instanceLf = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) contSchema, lfLfref.getLocalName());
    schemaLf = Iterables.getFirst(instanceLf, null);
    contData.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) schemaLf).withValue("true").build());
    final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(new InstanceIdentifierContext<>(yII, contSchema, null, schemaContext), contData.build());
    return testNormalizedNodeContext;
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

Example 52 with NormalizedNodeContext

use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.

the class NnToXmlTest method prepareLeafrefNegativeData.

private static NormalizedNodeContext prepareLeafrefNegativeData() {
    final QName cont = QName.create("basic:module", "2013-12-02", "cont");
    final QName lfLfref = QName.create("basic:module", "2013-12-02", "lfLfrefNegative");
    final YangInstanceIdentifier yII = YangInstanceIdentifier.builder().node(cont).build();
    final DataSchemaNode contSchema = schemaContext.getDataChildByName(cont);
    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contData = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) contSchema);
    final List<DataSchemaNode> instanceLf = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) contSchema, lfLfref.getLocalName());
    final DataSchemaNode schemaLf = Iterables.getFirst(instanceLf, null);
    contData.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) schemaLf).withValue("value").build());
    return new NormalizedNodeContext(new InstanceIdentifierContext<>(yII, contSchema, null, schemaContext), contData.build());
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

Example 53 with NormalizedNodeContext

use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.

the class JsonIdentityrefToNnTest method jsonIdentityrefToNn.

@Test
public void jsonIdentityrefToNn() throws Exception {
    final String uri = "identityref-module:cont";
    mockBodyReader(uri, this.jsonBodyReader, false);
    final InputStream inputStream = this.getClass().getResourceAsStream("/json-to-nn/identityref/json/data.json");
    final NormalizedNodeContext normalizedNodeContext = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    assertEquals("cont", normalizedNodeContext.getData().getIdentifier().getNodeType().getLocalName());
    final String dataTree = NormalizedNodes.toStringTree(normalizedNodeContext.getData());
    assertTrue(dataTree.contains("cont1"));
    assertTrue(dataTree.contains("lf11 (identity:module?revision=2013-12-02)iden"));
    assertTrue(dataTree.contains("lf12 (identityref:module?revision=2013-12-02)iden_local"));
    assertTrue(dataTree.contains("lf13 (identityref:module?revision=2013-12-02)iden_local"));
    assertTrue(dataTree.contains("lf14 (identity:module?revision=2013-12-02)iden"));
}
Also used : InputStream(java.io.InputStream) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) AbstractBodyReaderTest(org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest) Test(org.junit.Test)

Example 54 with NormalizedNodeContext

use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.

the class RestconfImpl method readOperationalData.

@Override
public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo uriInfo) {
    final InstanceIdentifierContext<?> iiWithData = controllerContext.toInstanceIdentifier(identifier);
    final DOMMountPoint mountPoint = iiWithData.getMountPoint();
    NormalizedNode data = null;
    final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
    if (mountPoint != null) {
        data = broker.readOperationalData(mountPoint, normalizedII);
    } else {
        data = broker.readOperationalData(normalizedII);
    }
    if (data == null) {
        throw dataMissing(identifier);
    }
    return new NormalizedNodeContext(iiWithData, data, QueryParametersParser.parseWriterParameters(uriInfo));
}
Also used : DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

Example 55 with NormalizedNodeContext

use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.

the class RestconfImpl method readConfigurationData.

@Override
public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
    boolean withDefaUsed = false;
    String withDefa = null;
    for (final Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) {
        switch(entry.getKey()) {
            case "with-defaults":
                if (!withDefaUsed) {
                    withDefaUsed = true;
                    withDefa = entry.getValue().iterator().next();
                } else {
                    throw new RestconfDocumentedException("With-defaults parameter can be used only once.");
                }
                break;
            default:
                LOG.info("Unknown key : {}.", entry.getKey());
                break;
        }
    }
    // TODO: this flag is always ignored
    boolean tagged = false;
    if (withDefaUsed) {
        if ("report-all-tagged".equals(withDefa)) {
            tagged = true;
            withDefa = null;
        }
        if ("report-all".equals(withDefa)) {
            withDefa = null;
        }
    }
    final InstanceIdentifierContext<?> iiWithData = controllerContext.toInstanceIdentifier(identifier);
    final DOMMountPoint mountPoint = iiWithData.getMountPoint();
    NormalizedNode data = null;
    final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
    if (mountPoint != null) {
        data = broker.readConfigurationData(mountPoint, normalizedII, withDefa);
    } else {
        data = broker.readConfigurationData(normalizedII, withDefa);
    }
    if (data == null) {
        throw dataMissing(identifier);
    }
    return new NormalizedNodeContext(iiWithData, data, QueryParametersParser.parseWriterParameters(uriInfo));
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) ArrayList(java.util.ArrayList) List(java.util.List) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

Aggregations

NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)105 Test (org.junit.Test)70 InputStream (java.io.InputStream)36 AbstractBodyReaderTest (org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest)34 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)34 QName (org.opendaylight.yangtools.yang.common.QName)25 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)22 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)18 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)13 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)13 Module (org.opendaylight.yangtools.yang.model.api.Module)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 OutputStream (java.io.OutputStream)9 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)9 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)9 UriInfo (javax.ws.rs.core.UriInfo)8 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)8 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)8 IOException (java.io.IOException)7