Refactor nbinotifications
[transportpce.git] / nbinotifications / src / main / java / org / opendaylight / transportpce / nbinotifications / impl / rpc / GetNotificationsProcessServiceImpl.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.NotificationServiceDeserializer;
14 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessService;
15 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceInput;
16 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceOutput;
17 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceOutputBuilder;
18 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
19 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.get.notifications.process.service.output.NotificationsProcessService;
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 GetNotificationsProcessServiceImpl implements GetNotificationsProcessService {
27     private static final Logger LOG = LoggerFactory.getLogger(GetNotificationsProcessServiceImpl.class);
28
29     private final JsonStringConverter<NotificationProcessService> converterService;
30     private final String server;
31
32     public GetNotificationsProcessServiceImpl(JsonStringConverter<NotificationProcessService> converterService,
33             String server) {
34         this.converterService = converterService;
35         this.server = server;
36     }
37
38     @Override
39     public ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> invoke(
40             GetNotificationsProcessServiceInput input) {
41         LOG.info("RPC getNotificationsService 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 GetNotificationsProcessServiceOutputBuilder().build()).buildFuture();
45         }
46         return RpcResultBuilder
47             .success(
48                 new GetNotificationsProcessServiceOutputBuilder()
49                     .setNotificationsProcessService(
50                         new Subscriber<NotificationProcessService, NotificationsProcessService>(
51                                 input.getIdConsumer(), input.getGroupId(), server, converterService,
52                                 NotificationServiceDeserializer.class)
53                             .subscribe(input.getConnectionType().getName(), NotificationsProcessService.QNAME))
54                     .build())
55             .buildFuture();
56     }
57 }