Bump upstream dependencies to Ca
[transportpce.git] / nbinotifications / src / main / java / org / opendaylight / transportpce / nbinotifications / impl / rpc / GetNotificationsAlarmServiceImpl.java
1 /*
2  * Copyright © 2024 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.impl.rpc;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.List;
12 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
13 import org.opendaylight.transportpce.nbinotifications.consumer.Subscriber;
14 import org.opendaylight.transportpce.nbinotifications.serialization.NotificationAlarmServiceDeserializer;
15 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmService;
16 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmServiceInput;
17 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmServiceOutput;
18 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmServiceOutputBuilder;
19 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationAlarmService;
20 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.get.notifications.alarm.service.output.NotificationsAlarmService;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26
27 public class GetNotificationsAlarmServiceImpl implements GetNotificationsAlarmService {
28     private static final Logger LOG = LoggerFactory.getLogger(GetNotificationsAlarmServiceImpl.class);
29
30     private final JsonStringConverter<NotificationAlarmService> converterAlarmService;
31     private final String server;
32
33     public GetNotificationsAlarmServiceImpl(JsonStringConverter<NotificationAlarmService> converterAlarmService,
34             String server) {
35         this.converterAlarmService = converterAlarmService;
36         this.server = server;
37     }
38
39     @Override
40     public ListenableFuture<RpcResult<GetNotificationsAlarmServiceOutput>> invoke(
41             GetNotificationsAlarmServiceInput input) {
42         LOG.info("RPC getNotificationsAlarmService received");
43         if (input == null || input.getIdConsumer() == null || input.getGroupId() == null) {
44             LOG.warn("Missing mandatory params for input {}", input);
45             return RpcResultBuilder.success(new GetNotificationsAlarmServiceOutputBuilder().build()).buildFuture();
46         }
47         Subscriber<NotificationAlarmService, NotificationsAlarmService> subscriber = new Subscriber<>(
48                 input.getIdConsumer(), input.getGroupId(), server, converterAlarmService,
49                 NotificationAlarmServiceDeserializer.class);
50         List<NotificationsAlarmService> notificationAlarmServiceList = subscriber
51                 .subscribe("alarm" + input.getConnectionType().getName(), NotificationsAlarmService.QNAME);
52         return RpcResultBuilder.success(new GetNotificationsAlarmServiceOutputBuilder()
53                 .setNotificationsAlarmService(notificationAlarmServiceList).build()).buildFuture();
54     }
55
56 }