Bug 3104 - fixed XmlNormalizedNodeBodyReader 78/22078/2
authorVaclav Demcak <vdemcak@cisco.com>
Fri, 29 May 2015 09:53:14 +0000 (11:53 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 8 Jun 2015 11:33:28 +0000 (11:33 +0000)
Note: add missing key is relevant only for a POST scenario.

Change-Id: Ibe97f83de4411c0fa5e28ced192f69aa65454027
Signed-off-by: Vaclav Demcak <vdemcak@cisco.com>
(cherry picked from commit 37aa81d301af72a6ea4ddf5e51c3f26f53c66a3d)

opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlNormalizedNodeBodyReader.java

index 50186b8dc76ecece25002c1f6f288f6922d0044d..817d25847a479ba9df38d905d4df1d05fc548911 100644 (file)
@@ -132,7 +132,7 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
         }
 
         final String docRootElm = doc.getDocumentElement().getLocalName();
-        List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
+        final List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
         InstanceIdentifierContext<SchemaNode> outIIContext;
 
 
@@ -143,7 +143,7 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
         if (isPost()) {
             final Deque<Object> foundSchemaNodes = findPathToSchemaNodeByName(schemaNode, docRootElm);
             while (!foundSchemaNodes.isEmpty()) {
-                Object child  = foundSchemaNodes.pop();
+                final Object child  = foundSchemaNodes.pop();
                 if (child instanceof AugmentationSchema) {
                     final AugmentationSchema augmentSchemaNode = (AugmentationSchema) child;
                     iiToDataList.add(SchemaUtils.getNodeIdentifierForAugmentation(augmentSchemaNode));
@@ -161,11 +161,13 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
         } else if(schemaNode instanceof ListSchemaNode) {
             final ListSchemaNode casted = (ListSchemaNode) schemaNode;
             parsed = parserFactory.getMapEntryNodeParser().parse(elements, casted);
-            iiToDataList.add(parsed.getIdentifier());
+            if (isPost()) {
+                iiToDataList.add(parsed.getIdentifier());
+            }
         }
         // FIXME : add another DataSchemaNode extensions e.g. LeafSchemaNode
 
-        YangInstanceIdentifier fullIIToData = YangInstanceIdentifier.create(Iterables.concat(
+        final YangInstanceIdentifier fullIIToData = YangInstanceIdentifier.create(Iterables.concat(
                 pathContext.getInstanceIdentifier().getPathArguments(), iiToDataList));
 
         outIIContext = new InstanceIdentifierContext<>(fullIIToData, pathContext.getSchemaNode(), pathContext.getMountPoint(),
@@ -174,7 +176,7 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
         return new NormalizedNodeContext(outIIContext, parsed);
     }
 
-    private static Deque<Object> findPathToSchemaNodeByName(DataSchemaNode schemaNode, String elementName) {
+    private static Deque<Object> findPathToSchemaNodeByName(final DataSchemaNode schemaNode, final String elementName) {
         final Deque<Object> result = new ArrayDeque<>();
         final ArrayList<ChoiceSchemaNode> choiceSchemaNodes = new ArrayList<>();
         final Collection<DataSchemaNode> children = ((DataNodeContainer) schemaNode).getChildNodes();
@@ -213,8 +215,8 @@ public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsPro
 
     private static AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) {
         if (parent instanceof AugmentationTarget && !(parent instanceof ChoiceSchemaNode)) {
-            for (AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
-                DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
+            for (final AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
+                final DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
                 if (childInAugmentation != null) {
                     return augmentation;
                 }