2 * Copyright © 2020 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;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.List;
12 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
13 import org.opendaylight.transportpce.nbinotifications.consumer.Subscriber;
14 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.GetNotificationsServiceInput;
15 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.GetNotificationsServiceOutput;
16 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.GetNotificationsServiceOutputBuilder;
17 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.NbiNotificationsService;
18 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.get.notifications.service.output.NotificationService;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class NbiNotificationsImpl implements NbiNotificationsService {
25 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsImpl.class);
26 private final JsonStringConverter<org.opendaylight.yang.gen.v1
27 .nbi.notifications.rev201130.NotificationService> converter;
28 private final String server;
30 public NbiNotificationsImpl(JsonStringConverter<org.opendaylight.yang.gen.v1
31 .nbi.notifications.rev201130.NotificationService> converter, String server) {
32 this.converter = converter;
37 public ListenableFuture<RpcResult<GetNotificationsServiceOutput>> getNotificationsService(
38 GetNotificationsServiceInput input) {
39 LOG.info("RPC getNotificationsService received");
40 if (input == null || input.getIdConsumer() == null || input.getGroupId() == null) {
41 LOG.warn("Missing mandatory params for input {}", input);
42 return RpcResultBuilder.success(new GetNotificationsServiceOutputBuilder().build()).buildFuture();
44 Subscriber subscriber = new Subscriber(input.getIdConsumer(), input.getGroupId(), server, converter);
45 List<NotificationService> notificationServiceList = subscriber
46 .subscribeService(input.getConnectionType().getName());
47 GetNotificationsServiceOutputBuilder output = new GetNotificationsServiceOutputBuilder()
48 .setNotificationService(notificationServiceList);
49 return RpcResultBuilder.success(output.build()).buildFuture();