2 * Copyright © 2024 Orange, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.nbinotifications.impl.rpc;
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.NotificationServiceDeserializer;
15 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessService;
16 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceInput;
17 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceOutput;
18 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceOutputBuilder;
19 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
20 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.get.notifications.process.service.output.NotificationsProcessService;
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;
27 public class GetNotificationsProcessServiceImpl implements GetNotificationsProcessService {
28 private static final Logger LOG = LoggerFactory.getLogger(GetNotificationsProcessServiceImpl.class);
30 private final JsonStringConverter<NotificationProcessService> converterService;
31 private final String server;
33 public GetNotificationsProcessServiceImpl(JsonStringConverter<NotificationProcessService> converterService,
35 this.converterService = converterService;
40 public ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> invoke(
41 GetNotificationsProcessServiceInput input) {
42 LOG.info("RPC getNotificationsService 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 GetNotificationsProcessServiceOutputBuilder().build()).buildFuture();
47 Subscriber<NotificationProcessService, NotificationsProcessService> subscriber = new Subscriber<>(
48 input.getIdConsumer(), input.getGroupId(), server, converterService,
49 NotificationServiceDeserializer.class);
50 List<NotificationsProcessService> notificationServiceList = subscriber
51 .subscribe(input.getConnectionType().getName(), NotificationsProcessService.QNAME);
52 return RpcResultBuilder.success(new GetNotificationsProcessServiceOutputBuilder()
53 .setNotificationsProcessService(notificationServiceList).build()).buildFuture();