Fix of issue 377 for Notifications resolving.
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / NetconfMapping.xtend
index c151e42fbb803e26565e53eb965a6903ebfa98da..76a5506df3f163a2c0ccab2f1515102c6a9b58bb 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.connect.netconf
 
 import org.opendaylight.controller.netconf.api.NetconfMessage
@@ -26,6 +33,8 @@ import com.google.common.base.Preconditions
 import com.google.common.base.Optional
 import org.opendaylight.yangtools.yang.model.api.SchemaContext
 import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
+import java.util.Set
 
 class NetconfMapping {
 
@@ -96,7 +105,19 @@ class NetconfMapping {
     }
 
     static def CompositeNode toCompositeNode(NetconfMessage message,Optional<SchemaContext> ctx) {
-        return null//message.toRpcResult().result;
+        //TODO: implement general normalization to normalize incoming Netconf Message 
+        // for Schema Context counterpart
+        return null
+    }
+    
+    static def CompositeNode toNotificationNode(NetconfMessage message,Optional<SchemaContext> ctx) {
+        if (ctx.present) {
+            val schemaContext = ctx.get
+            val notifications = schemaContext.notifications
+            val document = message.document
+            return XmlDocumentUtils.notificationToDomNodes(document, Optional.<Set<NotificationDefinition>>fromNullable(notifications))
+        }
+        return null
     }
 
     static def NetconfMessage toRpcMessage(QName rpc, CompositeNode node,Optional<SchemaContext> ctx) {
@@ -127,11 +148,11 @@ class NetconfMapping {
             if(isDataRetrievalReply(rpc)) {
                 
                 val xmlData = message.document.dataSubtree
-                val dataNodes = XmlDocumentUtils.toDomNodes(xmlData,Optional.of(context.get.dataDefinitions))
+                val dataNodes = XmlDocumentUtils.toDomNodes(xmlData, Optional.of(context.get.dataDefinitions))
                 
                 val it = ImmutableCompositeNode.builder()
                 setQName(NETCONF_RPC_REPLY_QNAME)
-                add(ImmutableCompositeNode.create(NETCONF_DATA_QNAME,dataNodes));
+                add(ImmutableCompositeNode.create(NETCONF_DATA_QNAME, dataNodes));
                 
                 rawRpc = it.toInstance;
                 //sys(xmlData)