0bcdf6bd27cad0e86f84c9e42a8449f82103730a
[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.HashMap;
11 import java.util.Map;
12 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
13 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.NbiNotificationsListener;
14 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.NotificationServiceBuilder;
15 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationService;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class NbiNotificationsListenerImpl implements NbiNotificationsListener {
20     private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
21     private Map<String, Publisher> publishersMap =  new HashMap<>();
22
23     public NbiNotificationsListenerImpl(Map<String, Publisher> publishersMap) {
24         this.publishersMap = publishersMap;
25     }
26
27     @Override
28     public void onPublishNotificationService(PublishNotificationService notification) {
29         LOG.info("Receiving request for publishing notification service");
30         String topic = notification.getTopic();
31         if (!publishersMap.containsKey(topic)) {
32             LOG.error("Unknown topic {}", topic);
33             return;
34         }
35         Publisher publisher = publishersMap.get(topic);
36         publisher.sendEvent(new NotificationServiceBuilder().setCommonId(notification.getCommonId())
37                 .setConnectionType(notification.getConnectionType()).setMessage(notification.getMessage())
38                 .setOperationalState(notification.getOperationalState())
39                 .setResponseFailed(notification.getResponseFailed())
40                 .setServiceAEnd(notification.getServiceAEnd()).setServiceName(notification.getServiceName())
41                 .setServiceZEnd(notification.getServiceZEnd()).build());
42
43     }
44
45 }