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.HashMap;
13 import org.opendaylight.transportpce.nbinotifications.impl.NbiNotificationsProvider;
14 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceList;
15 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceListInput;
16 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceListOutput;
17 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceListOutputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.context.NotificationContext;
19 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service.list.output.SubscriptionService;
20 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service.list.output.SubscriptionServiceBuilder;
21 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service.list.output.SubscriptionServiceKey;
22 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.context.NotifSubscription;
23 import org.opendaylight.yangtools.yang.common.ErrorType;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
28 public class GetNotificationSubscriptionServiceListImpl implements GetNotificationSubscriptionServiceList {
30 private NbiNotificationsProvider nbiNotifications;
32 public GetNotificationSubscriptionServiceListImpl(NbiNotificationsProvider nbiNotifications) {
33 this.nbiNotifications = nbiNotifications;
37 public ListenableFuture<RpcResult<GetNotificationSubscriptionServiceListOutput>> invoke(
38 GetNotificationSubscriptionServiceListInput input) {
39 NotificationContext notificationContext = nbiNotifications.getNotificationContext();
40 if (notificationContext == null) {
41 return RpcResultBuilder.<GetNotificationSubscriptionServiceListOutput>failed()
42 .withError(ErrorType.APPLICATION, "Notification context is empty")
45 if (notificationContext.getNotifSubscription() == null) {
46 return RpcResultBuilder
47 .success(new GetNotificationSubscriptionServiceListOutputBuilder()
48 .setSubscriptionService(new HashMap<>())
52 Map<SubscriptionServiceKey, SubscriptionService> notifSubsMap = new HashMap<>();
53 for (NotifSubscription notifSubscription:notificationContext.getNotifSubscription().values()) {
54 SubscriptionService subscriptionService = new SubscriptionServiceBuilder(notifSubscription).build();
55 notifSubsMap.put(subscriptionService.key(), subscriptionService);
57 return RpcResultBuilder
59 new GetNotificationSubscriptionServiceListOutputBuilder().setSubscriptionService(notifSubsMap).build())