f75efe2291ef9d64a685099b67ea3b8e789ac937
[transportpce.git] / nbinotifications / src / main / java / org / opendaylight / transportpce / nbinotifications / impl / rpc / GetNotificationSubscriptionServiceDetailsImpl.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.nbinotifications.impl.NbiNotificationsImpl;
12 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
13 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceDetails;
14 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceDetailsInput;
15 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceDetailsOutput;
16 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceDetailsOutputBuilder;
17 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.context.NotificationContext;
18 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.context.NotifSubscriptionKey;
19 import org.opendaylight.yangtools.yang.common.ErrorType;
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 GetNotificationSubscriptionServiceDetailsImpl implements GetNotificationSubscriptionServiceDetails {
27     private static final Logger LOG = LoggerFactory.getLogger(GetNotificationSubscriptionServiceDetailsImpl.class);
28
29     private NbiNotificationsImpl nbiNotifications;
30
31     public GetNotificationSubscriptionServiceDetailsImpl(NbiNotificationsImpl nbiNotifications) {
32         this.nbiNotifications = nbiNotifications;
33     }
34
35     @Override
36     public ListenableFuture<RpcResult<GetNotificationSubscriptionServiceDetailsOutput>> invoke(
37             GetNotificationSubscriptionServiceDetailsInput input) {
38         if (input == null || input.getUuid() == null) {
39             LOG.warn("Missing mandatory params for input {}", input);
40             return RpcResultBuilder.<GetNotificationSubscriptionServiceDetailsOutput>failed()
41                 .withError(ErrorType.RPC, "Missing input parameters").buildFuture();
42         }
43         Uuid notifSubsUuid = input.getUuid();
44         NotificationContext notificationContext = nbiNotifications.getNotificationContext();
45         if (notificationContext == null) {
46             return RpcResultBuilder.<GetNotificationSubscriptionServiceDetailsOutput>failed()
47                 .withError(ErrorType.APPLICATION, "Notification context is empty")
48                 .buildFuture();
49         }
50         if (notificationContext.getNotifSubscription() == null) {
51             return RpcResultBuilder.success(new GetNotificationSubscriptionServiceDetailsOutputBuilder()
52                 .setSubscriptionService(new org.opendaylight.yang.gen.v1
53                     .urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service
54                         .details.output.SubscriptionServiceBuilder().build()).build()).buildFuture();
55         }
56         if (!notificationContext.getNotifSubscription().containsKey(new NotifSubscriptionKey(notifSubsUuid))) {
57             return RpcResultBuilder.<GetNotificationSubscriptionServiceDetailsOutput>failed()
58                 .withError(ErrorType.APPLICATION,
59                     "Notification subscription service doesnt exist").buildFuture();
60         }
61         return RpcResultBuilder.success(new GetNotificationSubscriptionServiceDetailsOutputBuilder()
62             .setSubscriptionService(new org.opendaylight.yang.gen.v1.urn
63                 .onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service.details.output
64                 .SubscriptionServiceBuilder(notificationContext.getNotifSubscription().get(
65                     new NotifSubscriptionKey(notifSubsUuid))).build()).build()).buildFuture();
66     }
67
68 }