Merge "Fix modules Restconf call for mounted devices"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / restconf / impl / ControllerContext.java
index 7df760115c168abd00806a50de61426ea471e81c..e3beaa2287d01f5734b50a467b4e5cdd47cfcf6f 100644 (file)
@@ -27,7 +27,6 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicReference;
 import javax.ws.rs.core.Response.Status;
@@ -42,17 +41,15 @@ import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
 import org.opendaylight.yangtools.concepts.Codec;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
 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.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -445,7 +442,7 @@ public class ControllerContext implements SchemaContextListener {
         return null;
     }
 
-    private static DataSchemaNode childByQName(final ChoiceNode container, final QName name) {
+    private static DataSchemaNode childByQName(final ChoiceSchemaNode container, final QName name) {
         for (final ChoiceCaseNode caze : container.getCases()) {
             final DataSchemaNode ret = ControllerContext.childByQName(caze, name);
             if (ret != null) {
@@ -480,8 +477,8 @@ public class ControllerContext implements SchemaContextListener {
         final DataSchemaNode ret = container.getDataChildByName(name);
         if (ret == null) {
             for (final DataSchemaNode node : container.getChildNodes()) {
-                if ((node instanceof ChoiceNode)) {
-                    final ChoiceNode choiceNode = ((ChoiceNode) node);
+                if ((node instanceof ChoiceSchemaNode)) {
+                    final ChoiceSchemaNode choiceNode = ((ChoiceSchemaNode) node);
                     final DataSchemaNode childByQName = ControllerContext.childByQName(choiceNode, name);
                     if (childByQName != null) {
                         return childByQName;
@@ -529,7 +526,7 @@ public class ControllerContext implements SchemaContextListener {
                             ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED);
                 }
 
-                final YangInstanceIdentifier partialPath = builder.toInstance();
+                final YangInstanceIdentifier partialPath = dataNormalizer.toNormalized(builder.build());
                 final Optional<DOMMountPoint> mountOpt = mountService.getMountPoint(partialPath);
                 if (!mountOpt.isPresent()) {
                     LOG.debug("Instance identifier to missing mount point: {}", partialPath);
@@ -544,12 +541,7 @@ public class ControllerContext implements SchemaContextListener {
                             ErrorType.APPLICATION, ErrorTag.UNKNOWN_ELEMENT);
                 }
 
-                if (returnJustMountPoint) {
-                    final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance();
-                    return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema);
-                }
-
-                if (strings.size() == 1) {
+                if (returnJustMountPoint || strings.size() == 1) {
                     final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance();
                     return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema);
                 }
@@ -713,9 +705,9 @@ public class ControllerContext implements SchemaContextListener {
         return instantiatedDataNodeContainers;
     }
 
-    private static final Function<ChoiceNode, Set<ChoiceCaseNode>> CHOICE_FUNCTION = new Function<ChoiceNode, Set<ChoiceCaseNode>>() {
+    private static final Function<ChoiceSchemaNode, Set<ChoiceCaseNode>> CHOICE_FUNCTION = new Function<ChoiceSchemaNode, Set<ChoiceCaseNode>>() {
         @Override
-        public Set<ChoiceCaseNode> apply(final ChoiceNode node) {
+        public Set<ChoiceCaseNode> apply(final ChoiceSchemaNode node) {
             return node.getCases();
         }
     };
@@ -740,7 +732,7 @@ public class ControllerContext implements SchemaContextListener {
             }
         }
 
-        final Iterable<ChoiceNode> choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceNode.class);
+        final Iterable<ChoiceSchemaNode> choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceSchemaNode.class);
         final Iterable<Set<ChoiceCaseNode>> map = Iterables.transform(choiceNodes, CHOICE_FUNCTION);
 
         final Iterable<ChoiceCaseNode> allCases = Iterables.<ChoiceCaseNode> concat(map);
@@ -927,8 +919,8 @@ public class ControllerContext implements SchemaContextListener {
     private static DataSchemaNode childByQName(final Object container, final QName name) {
         if (container instanceof ChoiceCaseNode) {
             return childByQName((ChoiceCaseNode) container, name);
-        } else if (container instanceof ChoiceNode) {
-            return childByQName((ChoiceNode) container, name);
+        } else if (container instanceof ChoiceSchemaNode) {
+            return childByQName((ChoiceSchemaNode) container, name);
         } else if (container instanceof ContainerSchemaNode) {
             return childByQName((ContainerSchemaNode) container, name);
         } else if (container instanceof ListSchemaNode) {
@@ -943,15 +935,6 @@ public class ControllerContext implements SchemaContextListener {
         }
     }
 
-    public Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> toNormalized(final YangInstanceIdentifier legacy,
-            final CompositeNode compositeNode) {
-        try {
-            return dataNormalizer.toNormalized(legacy, compositeNode);
-        } catch (final NullPointerException e) {
-            throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e);
-        }
-    }
-
     public YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) {
         try {
             return dataNormalizer.toNormalized(legacy);
@@ -960,15 +943,6 @@ public class ControllerContext implements SchemaContextListener {
         }
     }
 
-    public CompositeNode toLegacy(final YangInstanceIdentifier instanceIdentifier,
-            final NormalizedNode<?,?> normalizedNode) {
-        try {
-            return dataNormalizer.toLegacy(instanceIdentifier, normalizedNode);
-        } catch (final NullPointerException e) {
-            throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e);
-        }
-    }
-
     public YangInstanceIdentifier toXpathRepresentation(final YangInstanceIdentifier instanceIdentifier) {
         try {
             return dataNormalizer.toLegacy(instanceIdentifier);