use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.
the class NormalizedNodeXmlTranslationTest method withAttributes.
private static ContainerNode withAttributes() {
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> b = containerBuilder();
b.withNodeIdentifier(getNodeIdentifier("container"));
final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listBuilder = Builders.mapBuilder().withNodeIdentifier(getNodeIdentifier("list"));
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> list1Builder = Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(getNodeIdentifier("list").getNodeType(), getNodeIdentifier("uint32InList").getNodeType(), Uint32.valueOf(3)));
final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> uint32InListBuilder = Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList"));
list1Builder.withChild(uint32InListBuilder.withValue(Uint32.valueOf(3)).build());
listBuilder.withChild(list1Builder.build());
b.withChild(listBuilder.build());
final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> booleanBuilder = Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("boolean"));
booleanBuilder.withValue(Boolean.FALSE);
b.withChild(booleanBuilder.build());
final ListNodeBuilder<Object, SystemLeafSetNode<Object>> leafListBuilder = Builders.leafSetBuilder().withNodeIdentifier(getNodeIdentifier("leafList"));
final NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafList1Builder = Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue(getNodeIdentifier("leafList").getNodeType(), "a"));
leafList1Builder.withValue("a");
leafListBuilder.withChild(leafList1Builder.build());
b.withChild(leafListBuilder.build());
return b.build();
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.
the class NormalizedNodeWriter method wasProcessedAsCompositeNode.
protected boolean wasProcessedAsCompositeNode(final NormalizedNode node) throws IOException {
if (node instanceof ContainerNode) {
final ContainerNode n = (ContainerNode) node;
writer.startContainerNode(n.getIdentifier(), childSizeHint(n.body()));
return writeChildren(n.body());
}
if (node instanceof MapEntryNode) {
return writeMapEntryNode((MapEntryNode) node);
}
if (node instanceof UnkeyedListEntryNode) {
final UnkeyedListEntryNode n = (UnkeyedListEntryNode) node;
writer.startUnkeyedListItem(n.getIdentifier(), childSizeHint(n.body()));
return writeChildren(n.body());
}
if (node instanceof ChoiceNode) {
final ChoiceNode n = (ChoiceNode) node;
writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.body()));
return writeChildren(n.body());
}
if (node instanceof AugmentationNode) {
final AugmentationNode n = (AugmentationNode) node;
writer.startAugmentationNode(n.getIdentifier());
return writeChildren(n.body());
}
if (node instanceof UnkeyedListNode) {
final UnkeyedListNode n = (UnkeyedListNode) node;
writer.startUnkeyedList(n.getIdentifier(), childSizeHint(n.body()));
return writeChildren(n.body());
}
if (node instanceof UserMapNode) {
final UserMapNode n = (UserMapNode) node;
writer.startOrderedMapNode(n.getIdentifier(), childSizeHint(n.body()));
return writeChildren(n.body());
}
if (node instanceof SystemMapNode) {
final SystemMapNode n = (SystemMapNode) node;
writer.startMapNode(n.getIdentifier(), childSizeHint(n.body()));
return writeChildren(n.body());
}
if (node instanceof UserLeafSetNode) {
final UserLeafSetNode<?> n = (UserLeafSetNode<?>) node;
writer.startOrderedLeafSet(n.getIdentifier(), childSizeHint(n.body()));
return writeChildren(n.body());
}
if (node instanceof SystemLeafSetNode) {
final SystemLeafSetNode<?> n = (SystemLeafSetNode<?>) node;
writer.startLeafSet(n.getIdentifier(), childSizeHint(n.body()));
return writeChildren(n.body());
}
return false;
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.
the class Bug4454Test method minMaxListNoMinMaxDeleteTest.
@Test
public void minMaxListNoMinMaxDeleteTest() throws DataValidationFailedException {
final MapEntryNode fooEntryNoMinMaxNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME_NO_MINMAX, MIN_MAX_KEY_LEAF_QNAME, "foo");
final SystemMapNode mapNode1 = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME_NO_MINMAX)).withChild(fooEntryNoMinMaxNode).build();
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
Map<QName, Object> key = new HashMap<>();
key.put(MIN_MAX_KEY_LEAF_QNAME, "foo");
NodeIdentifierWithPredicates mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
final YangInstanceIdentifier minMaxLeafFoo = MASTER_CONTAINER_PATH.node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2);
key.clear();
key.put(MIN_MAX_KEY_LEAF_QNAME, "non-existing-leaf");
mapEntryPath2 = NodeIdentifierWithPredicates.of(MIN_MAX_LIST_QNAME_NO_MINMAX, key);
YangInstanceIdentifier minMaxLeafNel = YangInstanceIdentifier.builder(MASTER_CONTAINER_PATH).node(MIN_MAX_LIST_QNAME_NO_MINMAX).node(mapEntryPath2).build();
modificationTree.write(MIN_MAX_LIST_NO_MINMAX_PATH, mapNode1);
modificationTree.delete(minMaxLeafFoo);
modificationTree.delete(minMaxLeafNel);
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
inMemoryDataTree.commit(prepare);
final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
final Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_NO_MINMAX_PATH);
// Empty list should have disappeared
assertFalse(minMaxListRead.isPresent());
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.
the class Bug4295Test method secondModification.
private void secondModification(final int testScenarioNumber) throws DataValidationFailedException {
/* MERGE */
SystemMapNode outerListNode = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(outerList)).withChild(createOuterListEntry("3", "o-3")).withChild(createOuterListEntry("4", "o-4")).withChild(createOuterListEntry("5", "o-5")).build();
ContainerNode rootContainerNode = createRootContainerBuilder().withChild(createSubRootContainerBuilder().withChild(outerListNode).build()).build();
YangInstanceIdentifier path = YangInstanceIdentifier.of(root);
DataTreeModification modification = inMemoryDataTree.takeSnapshot().newModification();
modification.merge(path, rootContainerNode);
if (testScenarioNumber == 1) {
/* WRITE EMPTY INNER LIST */
writeEmptyInnerList(modification, "2");
} else if (testScenarioNumber == 2) {
/* WRITE INNER LIST ENTRY */
MapEntryNode innerListEntryA = createInnerListEntry("a", "i-a-2");
path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2")).node(innerList).node(createInnerListEntryPath("a"));
modification.write(path, innerListEntryA);
} else if (testScenarioNumber == 3) {
/* WRITE INNER LIST WITH ENTRIES */
SystemMapNode innerListNode = createInnerListBuilder().withChild(createInnerListEntry("a", "i-a-3")).withChild(createInnerListEntry("c", "i-c")).build();
path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2")).node(innerList);
modification.write(path, innerListNode);
}
/* COMMIT */
modification.ready();
inMemoryDataTree.validate(modification);
inMemoryDataTree.commit(inMemoryDataTree.prepare(modification));
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project netconf by opendaylight.
the class RestconfImpl method getAvailableStreams.
@Override
@Deprecated
public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
final EffectiveModelContext schemaContext = controllerContext.getGlobalSchema();
final Set<String> availableStreams = Notificator.getStreamNames();
final Module restconfModule = getRestconfModule();
final DataSchemaNode streamSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule, RestConfModule.STREAM_LIST_SCHEMA_NODE);
checkState(streamSchemaNode instanceof ListSchemaNode);
final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listStreamsBuilder = SchemaAwareBuilders.mapBuilder((ListSchemaNode) streamSchemaNode);
for (final String streamName : availableStreams) {
listStreamsBuilder.withChild(toStreamEntryNode(streamName, streamSchemaNode));
}
final DataSchemaNode streamsContainerSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule, RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
checkState(streamsContainerSchemaNode instanceof ContainerSchemaNode);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> streamsContainerBuilder = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) streamsContainerSchemaNode);
streamsContainerBuilder.withChild(listStreamsBuilder.build());
return new NormalizedNodeContext(new InstanceIdentifierContext<>(STREAMS, streamsContainerSchemaNode, null, schemaContext), streamsContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo));
}
Aggregations