X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-cli%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fcli%2Freader%2Fimpl%2FListEntryReader.java;h=9d1f56b0dfcb2e8bb41c01eebd95c838f1fdb789;hp=97f76944d9116aceeacdedba0aaa2d8f2f2f91cf;hb=78527e81f8cc82140af5cb2649863a597f380291;hpb=c222e37f2a0f0f3f6266242fbea2d3b018f4e6e3 diff --git a/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/reader/impl/ListEntryReader.java b/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/reader/impl/ListEntryReader.java index 97f76944d9..9d1f56b0df 100644 --- a/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/reader/impl/ListEntryReader.java +++ b/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/reader/impl/ListEntryReader.java @@ -13,7 +13,9 @@ import com.google.common.collect.Collections2; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import org.opendaylight.controller.netconf.cli.CommandArgHandlerRegistry; import org.opendaylight.controller.netconf.cli.io.BaseConsoleContext; @@ -22,9 +24,14 @@ import org.opendaylight.controller.netconf.cli.io.ConsoleIO; import org.opendaylight.controller.netconf.cli.reader.AbstractReader; import org.opendaylight.controller.netconf.cli.reader.GenericListEntryReader; import org.opendaylight.controller.netconf.cli.reader.ReadingException; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode; -import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; @@ -50,7 +57,7 @@ class ListEntryReader extends AbstractReader implements GenericL } @Override - public List> readWithContext(final ListSchemaNode listNode) throws IOException, ReadingException { + public List> readWithContext(final ListSchemaNode listNode) throws IOException, ReadingException { console.formatLn("Submit child nodes for list entry: %s, %s", listNode.getQName().getLocalName(), Collections2.transform(listNode.getChildNodes(), new Function() { @Override @@ -60,12 +67,21 @@ class ListEntryReader extends AbstractReader implements GenericL })); final String listName = listNode.getQName().getLocalName(); - final CompositeNodeBuilder compositeNodeBuilder = ImmutableCompositeNode.builder(); - compositeNodeBuilder.setQName(listNode.getQName()); + + final DataContainerNodeAttrBuilder builder = + ImmutableMapEntryNodeBuilder.create(); +// final CompositeNodeBuilder compositeNodeBuilder = ImmutableCompositeNode.builder(); +// compositeNodeBuilder.setQName(listNode.getQName()); final SeparatedNodes separatedChildNodes = SeparatedNodes.separateNodes(listNode, getReadConfigNode()); - final List> nodes = readKeys(separatedChildNodes.getKeyNodes()); + final List> nodes = readKeys(separatedChildNodes.getKeyNodes()); + final Map qnameToValues = new HashMap<>(); + for (NormalizedNode node : nodes) { + qnameToValues.put(node.getNodeType(), node.getValue()); + } + builder.withNodeIdentifier(new NodeIdentifierWithPredicates(listNode.getQName(), qnameToValues)); + nodes.addAll(readMandatoryNotKeys(separatedChildNodes.getMandatoryNotKey())); if (!separatedChildNodes.getOthers().isEmpty()) { final Optional readNodesWhichAreNotKey = new DecisionReader().read(console, @@ -76,18 +92,23 @@ class ListEntryReader extends AbstractReader implements GenericL } if (!nodes.isEmpty()) { - compositeNodeBuilder.addAll(nodes); - return Collections.> singletonList(compositeNodeBuilder.toInstance()); +// compositeNodeBuilder.addAll(nodes); + builder.withValue((List) nodes); + return Collections.>singletonList( + ImmutableMapNodeBuilder.create() + .withNodeIdentifier(new NodeIdentifier(listNode.getQName())) + .withChild(builder.build()).build()); +// return Collections.> singletonList(compositeNodeBuilder.toInstance()); } else { return Collections.emptyList(); } } - private List> readKeys(final Set keys) throws ReadingException, IOException { - final List> newNodes = new ArrayList<>(); + private List> readKeys(final Set keys) throws ReadingException, IOException { + final List> newNodes = new ArrayList<>(); console.writeLn("Reading keys:"); for (final DataSchemaNode key : keys) { - final List> readKey = new LeafReader(console, getSchemaContext(), getReadConfigNode()) + final List> readKey = new LeafReader(console, getSchemaContext(), getReadConfigNode()) .read((LeafSchemaNode) key); if (readKey.size() != 1) { final String message = String.format( @@ -98,16 +119,17 @@ class ListEntryReader extends AbstractReader implements GenericL } newNodes.addAll(readKey); } + return newNodes; } - private List> readMandatoryNotKeys(final Set mandatoryNotKeys) throws ReadingException, + private List> readMandatoryNotKeys(final Set mandatoryNotKeys) throws ReadingException, IOException { - final List> newNodes = new ArrayList<>(); + final List> newNodes = new ArrayList<>(); console.writeLn("Reading mandatory not keys nodes:"); for (final DataSchemaNode mandatoryNode : mandatoryNotKeys) { - final List> redValue = argumentHandlerRegistry.getGenericReader(getSchemaContext(), + final List> redValue = argumentHandlerRegistry.getGenericReader(getSchemaContext(), getReadConfigNode()).read(mandatoryNode); if (redValue.isEmpty()) { final String message = String.format( @@ -121,8 +143,8 @@ class ListEntryReader extends AbstractReader implements GenericL return newNodes; } - private List> readNotKeys(final Set notKeys) throws ReadingException { - final List> newNodes = new ArrayList<>(); + private List> readNotKeys(final Set notKeys) throws ReadingException { + final List> newNodes = new ArrayList<>(); for (final DataSchemaNode notKey : notKeys) { newNodes.addAll(argumentHandlerRegistry.getGenericReader(getSchemaContext(), getReadConfigNode()).read( notKey));