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