Reenforce Lighty use in the gate
[transportpce.git] / nbinotifications / src / main / java / org / opendaylight / transportpce / nbinotifications / listener / NbiNotificationsListenerImpl.java
1 /*
2  * Copyright © 2020 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.nbinotifications.listener;
9
10 import java.util.Map;
11 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
12 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NbiNotificationsListener;
13 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationAlarmService;
14 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationAlarmServiceBuilder;
15 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationService;
16 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationServiceBuilder;
17 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationAlarmService;
18 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationService;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class NbiNotificationsListenerImpl implements NbiNotificationsListener {
23     private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
24     private final Map<String, Publisher<NotificationService>> publishersServiceMap;
25     private final Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap;
26
27     public NbiNotificationsListenerImpl(Map<String, Publisher<NotificationService>> publishersServiceMap,
28                                         Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap) {
29         this.publishersServiceMap = publishersServiceMap;
30         this.publishersAlarmMap = publishersAlarmMap;
31     }
32
33     @Override
34     public void onPublishNotificationService(PublishNotificationService notification) {
35         LOG.info("Receiving request for publishing notification service");
36         String topic = notification.getTopic();
37         if (!publishersServiceMap.containsKey(topic)) {
38             LOG.error("Unknown topic {}", topic);
39             return;
40         }
41         Publisher<NotificationService> publisher = publishersServiceMap.get(topic);
42         publisher.sendEvent(new NotificationServiceBuilder().setCommonId(notification.getCommonId())
43                 .setConnectionType(notification.getConnectionType()).setMessage(notification.getMessage())
44                 .setOperationalState(notification.getOperationalState())
45                 .setResponseFailed(notification.getResponseFailed())
46                 .setServiceAEnd(notification.getServiceAEnd())
47                 .setServiceName(notification.getServiceName())
48                 .setServiceZEnd(notification.getServiceZEnd()).build(), notification.getConnectionType().getName());
49     }
50
51     @Override
52     public void onPublishNotificationAlarmService(PublishNotificationAlarmService notification) {
53         LOG.info("Receiving request for publishing notification alarm service");
54         String topic = notification.getTopic();
55         if (!publishersAlarmMap.containsKey(topic)) {
56             LOG.error("Unknown topic {}", topic);
57             return;
58         }
59         Publisher<NotificationAlarmService> publisherAlarm = publishersAlarmMap.get(topic);
60         publisherAlarm.sendEvent(new NotificationAlarmServiceBuilder().setConnectionType(notification
61                 .getConnectionType())
62                 .setMessage(notification.getMessage())
63                 .setOperationalState(notification.getOperationalState())
64                 .setServiceName(notification.getServiceName())
65                 .build(), "alarm" + notification.getConnectionType().getName());
66     }
67 }