BUG 392: Resolved translation to JSON behind mount point
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / rest / impl / JsonMapper.java
index 4c5fd9ff7ccb77fa17f781406db125ff26e2cc52..ca318e4f3692d28da298810d0b4ff7272bc4f615 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.sal.rest.impl;
 
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -127,7 +134,7 @@ class JsonMapper {
 
     private DataSchemaNode findFirstSchemaForNode(Node<?> node, Set<DataSchemaNode> dataSchemaNode) {
         for (DataSchemaNode dsn : dataSchemaNode) {
-            if (node.getNodeType().getLocalName().equals(dsn.getQName().getLocalName())) {
+            if (node.getNodeType().equals(dsn.getQName())) {
                 return dsn;
             } else if (dsn instanceof ChoiceNode) {
                 for (ChoiceCaseNode choiceCase : ((ChoiceNode) dsn).getCases()) {
@@ -293,10 +300,16 @@ class JsonMapper {
         String nameForOutput = node.getNodeType().getLocalName();
         if (schema.isAugmenting()) {
             ControllerContext contContext = ControllerContext.getInstance();
-            CharSequence moduleName;
-            moduleName = contContext.toRestconfIdentifier(schema.getQName());
+            CharSequence moduleName = null;
+            if (mountPoint == null) {
+                moduleName = contContext.toRestconfIdentifier(schema.getQName());
+            } else {
+                moduleName = contContext.toRestconfIdentifier(mountPoint, schema.getQName());
+            }
             if (moduleName != null) {
                 nameForOutput = moduleName.toString();
+            } else {
+                logger.info("Module '{}' was not found in schema from mount point", schema.getQName());
             }
         }
         writer.name(nameForOutput);