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;
}
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());
}
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"));
}
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));
}
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));
}
Aggregations