T-API notification JUnit test
[transportpce.git] / nbinotifications / src / main / java / org / opendaylight / transportpce / nbinotifications / listener / NbiNotificationsListenerImpl.java
index 37b4c0181618044108e0d79435ca70ad5a7fa102..7450fa6711503272d3be8ca59efadbdea5f848d7 100644 (file)
@@ -9,25 +9,32 @@ package org.opendaylight.transportpce.nbinotifications.listener;
 
 import java.util.Map;
 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NbiNotificationsListener;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmService;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmServiceBuilder;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationProcessService;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationProcessServiceBuilder;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationAlarmService;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationProcessService;
+import org.opendaylight.transportpce.nbinotifications.utils.NbiNotificationsUtils;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmServiceBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessServiceBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiServiceBuilder;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationAlarmService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishTapiNotificationService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class NbiNotificationsListenerImpl implements NbiNotificationsListener {
     private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
-    private final Map<String, Publisher<NotificationProcessService>> publishersServiceMap;
-    private final Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap;
+    private Map<String, Publisher<NotificationProcessService>> publishersServiceMap;
+    private Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap;
+    private Map<String, Publisher<NotificationTapiService>> tapiPublisherMap;
 
     public NbiNotificationsListenerImpl(Map<String, Publisher<NotificationProcessService>> publishersServiceMap,
-                                        Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap) {
+                                        Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap,
+                                        Map<String, Publisher<NotificationTapiService>> tapiPublisherMap) {
         this.publishersServiceMap = publishersServiceMap;
         this.publishersAlarmMap = publishersAlarmMap;
+        this.tapiPublisherMap = tapiPublisherMap;
     }
 
     @Override
@@ -67,4 +74,33 @@ public class NbiNotificationsListenerImpl implements NbiNotificationsListener {
                 .setServiceName(notification.getServiceName())
                         .build(), "alarm" + notification.getConnectionType().getName());
     }
+
+    @Override
+    public void onPublishTapiNotificationService(PublishTapiNotificationService notification) {
+        LOG.info("Receiving request for publishing TAPI notification");
+        String topic = notification.getTopic();
+        if (!tapiPublisherMap.containsKey(topic)) {
+            LOG.error("Unknown topic {}", topic);
+            return;
+        }
+        Publisher<NotificationTapiService> publisher = tapiPublisherMap.get(topic);
+        publisher.sendEvent(new NotificationTapiServiceBuilder(
+                NbiNotificationsUtils.transformTapiNotification(notification)).build(), topic);
+    }
+
+    public void setPublishersServiceMap(Map<String, Publisher<NotificationProcessService>> publishersServiceMap) {
+        this.publishersServiceMap = publishersServiceMap;
+    }
+
+    public void setPublishersAlarmMap(Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap) {
+        this.publishersAlarmMap = publishersAlarmMap;
+    }
+
+    public void setTapiPublishersMap(Map<String, Publisher<NotificationTapiService>> tapiPublishersMap) {
+        this.tapiPublisherMap = tapiPublishersMap;
+    }
+
+    public Publisher<NotificationTapiService> getTapiPublisherFromTopic(String topic) {
+        return this.tapiPublisherMap.get(topic);
+    }
 }