7e9c8ba02e3f8c115f4e1188750d4f40979854bb
[transportpce.git] / nbinotifications / src / main / java / org / opendaylight / transportpce / nbinotifications / impl / rpc / GetNotificationSubscriptionServiceListImpl.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 java.util.HashMap;
12 import java.util.Map;
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;
24
25
26 public class GetNotificationSubscriptionServiceListImpl implements GetNotificationSubscriptionServiceList {
27
28     private NbiNotificationsImpl nbiNotifications;
29
30     public GetNotificationSubscriptionServiceListImpl(NbiNotificationsImpl nbiNotifications) {
31         this.nbiNotifications = nbiNotifications;
32     }
33
34     @Override
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")
41                 .buildFuture();
42         }
43         if (notificationContext.getNotifSubscription() == null) {
44             return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder()
45                 .setSubscriptionService(new HashMap<>()).build()).buildFuture();
46         }
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);
57         }
58         return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder()
59             .setSubscriptionService(notifSubsMap).build()).buildFuture();
60     }
61
62 }