Verification of keys in list 05/3605/3
authorTony Tkacik <ttkacik@cisco.com>
Tue, 17 Dec 2013 16:26:00 +0000 (17:26 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 17 Dec 2013 16:26:00 +0000 (17:26 +0100)
- verification of keys in list against list yang structure

Change-Id: Ieb46eea67a7d3173958184ced10cec1b853bb7fe
Signed-off-by: Martin Sunal <msunal@cisco.com>
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend

index 94a7756..02a4b18 100644 (file)
@@ -6,18 +6,20 @@ import java.util.Set
 import javax.ws.rs.core.Response
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus
 import org.opendaylight.controller.sal.rest.api.RestconfService
+import org.opendaylight.yangtools.yang.common.QName
 import org.opendaylight.yangtools.yang.data.api.CompositeNode
 import org.opendaylight.yangtools.yang.data.api.Node
 import org.opendaylight.yangtools.yang.data.impl.NodeFactory
+import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec
 import org.opendaylight.yangtools.yang.model.api.ChoiceNode
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
-import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode
-import org.opendaylight.yangtools.yang.common.QName
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition
+
 import static javax.ws.rs.core.Response.Status.*
 
 class RestconfImpl implements RestconfService {
@@ -164,6 +166,21 @@ class RestconfImpl implements RestconfService {
                     findFirstSchemaByLocalName(child.localName, (schema as DataNodeContainer).childNodes),
                     currentAugment)
             }
+            if(schema instanceof ListSchemaNode) {
+                val listKeys = (schema as ListSchemaNode).keyDefinition
+                for (listKey : listKeys) {
+                    var foundKey = false
+                    for (child : children) {
+                        if (child.unwrap.nodeType.localName == listKey.localName) {
+                            foundKey = true;
+                        }
+                    }
+                    if (!foundKey) {
+                        throw new ResponseException(BAD_REQUEST,
+                            "Missing key \"" + listKey.localName + "\" of list \"" + schema.QName.localName + "\"")
+                    }
+                }
+            }
         } else if (nodeBuilder instanceof SimpleNodeWrapper) {
             val simpleNode = (nodeBuilder as SimpleNodeWrapper)
             val stringValue = simpleNode.value as String;