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.NbiNotificationsImpl;
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.SubscriptionServiceKey;
20 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.context.NotifSubscription;
21 import org.opendaylight.yangtools.yang.common.ErrorType;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
23 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
26 public class GetNotificationSubscriptionServiceListImpl implements GetNotificationSubscriptionServiceList {
28 private NbiNotificationsImpl nbiNotifications;
30 public GetNotificationSubscriptionServiceListImpl(NbiNotificationsImpl nbiNotifications) {
31 this.nbiNotifications = nbiNotifications;
35 public ListenableFuture<RpcResult<GetNotificationSubscriptionServiceListOutput>> invoke(
36 GetNotificationSubscriptionServiceListInput input) {
37 NotificationContext notificationContext = nbiNotifications.getNotificationContext();
38 if (notificationContext == null) {
39 return RpcResultBuilder.<GetNotificationSubscriptionServiceListOutput>failed()
40 .withError(ErrorType.APPLICATION, "Notification context is empty")
43 if (notificationContext.getNotifSubscription() == null) {
44 return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder()
45 .setSubscriptionService(new HashMap<>()).build()).buildFuture();
47 Map<SubscriptionServiceKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang
48 .tapi.notification.rev221121.get.notification.subscription.service.list.output.SubscriptionService>
49 notifSubsMap = new HashMap<>();
50 for (NotifSubscription notifSubscription:notificationContext.getNotifSubscription().values()) {
51 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang
52 .tapi.notification.rev221121.get.notification.subscription.service.list.output.SubscriptionService
53 subscriptionService = new org.opendaylight.yang.gen.v1
54 .urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service
55 .list.output.SubscriptionServiceBuilder(notifSubscription).build();
56 notifSubsMap.put(subscriptionService.key(), subscriptionService);
58 return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder()
59 .setSubscriptionService(notifSubsMap).build()).buildFuture();