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 org.opendaylight.transportpce.nbinotifications.impl.NbiNotificationsProvider;
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;
26 public class GetNotificationSubscriptionServiceDetailsImpl implements GetNotificationSubscriptionServiceDetails {
27 private static final Logger LOG = LoggerFactory.getLogger(GetNotificationSubscriptionServiceDetailsImpl.class);
29 private NbiNotificationsProvider nbiNotifications;
31 public GetNotificationSubscriptionServiceDetailsImpl(NbiNotificationsProvider nbiNotifications) {
32 this.nbiNotifications = nbiNotifications;
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();
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")
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();
56 if (!notificationContext.getNotifSubscription().containsKey(new NotifSubscriptionKey(notifSubsUuid))) {
57 return RpcResultBuilder.<GetNotificationSubscriptionServiceDetailsOutput>failed()
58 .withError(ErrorType.APPLICATION,
59 "Notification subscription service doesnt exist").buildFuture();
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();