Fixed merge of entries in mock data store 09/2609/1
authorTony Tkacik <ttkacik@cisco.com>
Mon, 11 Nov 2013 13:27:23 +0000 (14:27 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Mon, 11 Nov 2013 13:27:23 +0000 (14:27 +0100)
Change-Id: Ifdaf681ecfc846e58afe0358568e86afe1822b4e
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/md-sal/sal-dom-broker/pom.xml
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataUtils.xtend [new file with mode: 0644]
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/HashMapDataStore.xtend

index f92d86a..62dbe16 100644 (file)
             <artifactId>sal-common-util</artifactId>
             <version>1.0-SNAPSHOT</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-data-impl</artifactId>
+            <version>0.5.9-SNAPSHOT</version>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>sal-common-impl</artifactId>
diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataUtils.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataUtils.xtend
new file mode 100644 (file)
index 0000000..1a2f947
--- /dev/null
@@ -0,0 +1,50 @@
+package org.opendaylight.controller.sal.dom.broker.impl
+
+import org.opendaylight.yangtools.yang.data.api.CompositeNode
+import java.util.Map
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
+import java.util.Map.Entry
+import java.util.HashSet
+import java.util.ArrayList
+import org.opendaylight.yangtools.yang.data.api.Node
+import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl
+
+class DataUtils {
+
+    static def CompositeNode read(Map<InstanceIdentifier, CompositeNode> map, InstanceIdentifier path) {
+        val root = map.get(path);
+        val childs = map.getChilds(path);
+        if(root === null && childs.empty) {
+            return null;
+        }
+        
+        return merge(path, root, childs);
+    }
+
+    static def CompositeNode merge(InstanceIdentifier path, CompositeNode node,
+        HashSet<Entry<InstanceIdentifier, CompositeNode>> entries) {
+        val it = new ArrayList<Node<?>>();
+        val qname = path.path.last.nodeType;
+        if (node != null) {
+            addAll(node.children);
+        }
+        for (entry : entries) {
+            val nesting = entry.key.path.size - path.path.size;
+            if (nesting === 1) {
+                add(entry.value);
+            }
+        }
+        return new CompositeNodeTOImpl(qname, null, it);
+    }
+
+    static def getChilds(Map<InstanceIdentifier, CompositeNode> map, InstanceIdentifier path) {
+        val it = new HashSet<Entry<InstanceIdentifier, CompositeNode>>();
+        for (entry : map.entrySet) {
+            if (path.contains(entry.key)) {
+                add(entry);
+            }
+        }
+        return it;
+    }
+
+}
index 404842c..7d57819 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.controller.sal.common.util.Rpcs
 import java.util.Collections
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
 import org.opendaylight.yangtools.yang.data.api.CompositeNode
+import static extension org.opendaylight.controller.sal.dom.broker.impl.DataUtils.*;
 
 class HashMapDataStore //
 implements //
@@ -20,12 +21,15 @@ DataReader<InstanceIdentifier, CompositeNode>, DataCommitHandler<InstanceIdentif
     val Map<InstanceIdentifier, CompositeNode> operational = new ConcurrentHashMap();
 
     override readConfigurationData(InstanceIdentifier path) {
-        configuration.get(path);
+        configuration.read(path);
     }
 
     override readOperationalData(InstanceIdentifier path) {
-        operational.get(path);
+        operational.read(path);
     }
+    
+
+
 
     override requestCommit(DataModification<InstanceIdentifier, CompositeNode> modification) {
         return new HashMapDataStoreTransaction(modification, this);