private Optional<MapNode> build(ListSchemaNode schema, Map<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> resultNodes) { if(resultNodes.isEmpty()) { return Optional.absent(); } CollectionNodeBuilder<MapEntryNode, MapNode> b = Builders.mapBuilder(schema); for (MapEntryNode child : resultNodes.values()) { b.withChild(child); } return Optional.of(b.build()); }
private Optional<UnkeyedListNode> build(ListSchemaNode schema, List<UnkeyedListEntryNode> resultNodes) { if (resultNodes.isEmpty()) { return Optional.absent(); } CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> b = Builders.unkeyedListBuilder(); b.withNodeIdentifier(new NodeIdentifier(schema.getQName())); for (UnkeyedListEntryNode child : resultNodes) { b.withChild(child); } return Optional.of(b.build()); }
private static MapNode initInnerListItems(final int count) { final CollectionNodeBuilder<MapEntryNode, MapNode> mapEntryBuilder = ImmutableNodes .mapNodeBuilder(BenchmarkModel.INNER_LIST); for (int i = 0; i < count; ++i) { mapEntryBuilder .withChild(ImmutableNodes.mapEntry(BenchmarkModel.INNER_LIST_QNAME, BenchmarkModel.NAME_QNAME, i)); } return mapEntryBuilder.build(); }
private MapNode makeModuleMapNode(final Set<Module> modules) { Preconditions.checkNotNull(modules); final Module restconfModule = getRestconfModule(); final DataSchemaNode moduleSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode( restconfModule, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE); Preconditions.checkState(moduleSchemaNode instanceof ListSchemaNode); final CollectionNodeBuilder<MapEntryNode, MapNode> listModuleBuilder = Builders .mapBuilder((ListSchemaNode) moduleSchemaNode); for (final Module module : modules) { listModuleBuilder.withChild(toModuleEntryNode(module, moduleSchemaNode)); } return listModuleBuilder.build(); }
listErorsBuilder.withChild(toErrorEntryNode(error, errListSchemaNode));
private NormalizedNode<?, ?> buildCollectionNode( final CollectionNodeBuilder builder, final NormalizedNodeMessages.Node node) { builder.withNodeIdentifier(toNodeIdentifier(node.getPathArgument())); for(NormalizedNodeMessages.Node child : node.getChildList()){ builder.withChild(deSerialize(child)); } return builder.build(); }
@VisibleForTesting static DataContainerChild<?, ?> wrapListIntoMixinNode( final Collection<NormalizedNode<?, ?>> normalizedRootElements, final ListSchemaNode listSchema) { if (listSchema.getKeyDefinition().isEmpty()) { final CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> listBuilder = Builders.unkeyedListBuilder(); listBuilder.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(listSchema.getQName())); for (NormalizedNode<?, ?> normalizedRootElement : normalizedRootElements) { listBuilder.withChild((UnkeyedListEntryNode) normalizedRootElement); } return listBuilder.build(); } else { final CollectionNodeBuilder<MapEntryNode, ? extends MapNode> listBuilder = listSchema.isUserOrdered() ? Builders.orderedMapBuilder() : Builders.mapBuilder(); listBuilder.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(listSchema.getQName())); for (NormalizedNode<?, ?> normalizedRootElement : normalizedRootElements) { listBuilder.withChild((MapEntryNode) normalizedRootElement); } return listBuilder.build(); } }
private void processMapEntries(final NormalizedNode<?, ?> node, final Integer depth, CollectionNodeBuilder<MapEntryNode, ? extends MapNode> newOrderedMapNodeBuilder) { if (depth > 1) { for (MapEntryNode oldMapEntryNode : ((MapNode) node).getValue()) { DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> newMapEntryNodeBuilder = Builders .mapEntryBuilder().withNodeIdentifier(oldMapEntryNode.getIdentifier()); for (DataContainerChild<? extends PathArgument, ?> mapEntryNodeValue : oldMapEntryNode.getValue()) { newMapEntryNodeBuilder.withChild(pruneDataAtDepth(mapEntryNodeValue, depth - 1)); } newOrderedMapNodeBuilder.withChild(newMapEntryNodeBuilder.build()); } } }
data = ImmutableNodes.mapNodeBuilder(data.getNodeType()).withChild(((MapEntryNode) data)).build();
@Override public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) { final SchemaContext schemaContext = controllerContext.getGlobalSchema(); final Set<String> availableStreams = Notificator.getStreamNames(); final Module restconfModule = getRestconfModule(); final DataSchemaNode streamSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule, Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE); Preconditions.checkState(streamSchemaNode instanceof ListSchemaNode); final CollectionNodeBuilder<MapEntryNode, MapNode> listStreamsBuilder = Builders .mapBuilder((ListSchemaNode) streamSchemaNode); for (final String streamName : availableStreams) { listStreamsBuilder.withChild(toStreamEntryNode(streamName, streamSchemaNode)); } final DataSchemaNode streamsContainerSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode( restconfModule, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); Preconditions.checkState(streamsContainerSchemaNode instanceof ContainerSchemaNode); final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> streamsContainerBuilder = Builders.containerBuilder((ContainerSchemaNode) streamsContainerSchemaNode); streamsContainerBuilder.withChild(listStreamsBuilder.build()); return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, streamsContainerSchemaNode, null, schemaContext), streamsContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo)); }
.withChild(Builders.leafBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier( format)).withValue(Yang.QNAME).build()) .withChild(Builders.leafBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier( namespace)).withValue(schema.getNamespace().getValue()).build()) .withChild((DataContainerChild<?, ?>) Builders.leafSetBuilder().withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifier(location)) .withChild(locationLeafSetEntryNode).build()) .build(); schemaMapEntryNodeMapNodeCollectionNodeBuilder.withChild(schemaMapEntryNode);
segmentsBuilder.withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(this.asPathSegments).withChild(asSequenceBuilder.build()).build()); segmentsBuilder.withChild(firstSegment); segmentsBuilder.withChild(oldAsSegments.next()); segmentsBuilder.withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(this.asPathSegments).withChild( Builders.orderedLeafSetBuilder().withNodeIdentifier(this.asPathSequence).addChild( Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue(this.asNumberQname, localAs)).withValue(localAs).build()).build()).build());
} else { if(data instanceof MapEntryNode) { data = ImmutableNodes.mapNodeBuilder(data.getNodeType()).withChild(((MapEntryNode) data)).build();
.withChild(ImmutableNodes.leafNode(CHILD_NAME_QNAME, FIRST_CHILD_NAME)) .withChild( mapNodeBuilder(GRAND_CHILDREN_QNAME).withChild( firstGrandChildBuilder.build()).build()); .withChild(ImmutableNodes.leafNode(CHILD_NAME_QNAME, SECOND_CHILD_NAME)) .withChild( mapNodeBuilder(GRAND_CHILDREN_QNAME).withChild( firstGrandChildBuilder.build()).build()); childrenBuilder.withChild(firstChildBuilder.build()); childrenBuilder.withChild(secondChildBuilder.build());
@Test public void testInnerContainerNodeWithParentPathPrunedWhenSchemaMissing() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode innerList = mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INVALID_QNAME)).build()).build(); NormalizedNode<?, ?> input = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .withChild(innerList).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> expected = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").build()).build()).build(); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", expected, actual); }
@Test public void testInnerListNodeWithFullPathNotPruned() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .node(TestModel.INNER_LIST_QNAME).build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode input = mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", input, actual); }
@Test public void testInnerListNodeWithFullPathPrunedWhenSchemaMissing() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .node(TestModel.INVALID_QNAME).build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode input = mapNodeBuilder(TestModel.INVALID_QNAME).withChild(mapEntryBuilder( TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertNull(actual); }
@Test public void testInnerListNodeWithParentPathPrunedWhenSchemaMissing() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode innerList = mapNodeBuilder(TestModel.INVALID_QNAME).withChild(mapEntryBuilder( TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); NormalizedNode<?, ?> input = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .withChild(innerList).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> expected = mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", expected, actual); }
private static NormalizedNode<?, ?> createTestContainer() { byte[] bytes1 = {1, 2, 3}; LeafSetEntryNode<Object> entry1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier( new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes1)).withValue(bytes1).build(); byte[] bytes2 = {}; LeafSetEntryNode<Object> entry2 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier( new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes2)).withValue(bytes2).build(); return TestModel.createBaseTestContainerBuilder() .withChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier( new NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME)) .withChild(entry1).withChild(entry2).build()) .withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, new byte[]{1, 2, 3, 4})) .withChild(ImmutableNodes.leafNode(TestModel.EMPTY_QNAME, Empty.getInstance())) .withChild(Builders.orderedMapBuilder() .withNodeIdentifier(new NodeIdentifier(TestModel.ORDERED_LIST_QNAME)) .withChild(ImmutableNodes.mapEntry(TestModel.ORDERED_LIST_ENTRY_QNAME, TestModel.ID_QNAME, 11)).build()).build(); }
builder.withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(STAT9_QNAME)) .withChild(ImmutableNodes.mapNodeBuilder(AF_QNAME) .withChild(Builders.mapEntryBuilder() .withChild(ImmutableNodes.leafNode(COUNT_QNAME, tlvs.getPerAfiSafiAdjRibInTlv().getCount().getValue())) .withNodeIdentifier(TablesUtil.toYangTablesKey(AF_QNAME, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)) builder.withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(STAT10_QNAME)) .withChild(ImmutableNodes.mapNodeBuilder(AF_QNAME) .withChild(Builders.mapEntryBuilder() .withChild(ImmutableNodes.leafNode(COUNT_QNAME, tlvs.getPerAfiSafiLocRibTlv().getCount().getValue())) .withNodeIdentifier(TablesUtil.toYangTablesKey(AF_QNAME, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class))