1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Wipro Limited.
6 * ==============================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 *******************************************************************************/
22 package org.onap.dcaegen2.services.sonhms;
24 import com.fasterxml.jackson.databind.ObjectMapper;
26 import fj.data.Either;
28 import java.io.IOException;
29 import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository;
30 import org.onap.dcaegen2.services.sonhms.dao.PerformanceNotificationsRepository;
31 import org.onap.dcaegen2.services.sonhms.model.Notification;
32 import org.onap.dcaegen2.services.sonhms.model.PmNotification;
33 import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class DmaapNotificationsComponent {
39 private static Logger log = LoggerFactory.getLogger(DmaapNotificationsComponent.class);
42 * Get sdnr notifications.
44 public Either<Notification, Integer> getSdnrNotifications() {
45 DmaapNotificationsRepository dmaapNotificationsRepository = BeanUtil
46 .getBean(DmaapNotificationsRepository.class);
47 String notificationString = dmaapNotificationsRepository.getNotificationFromQueue();
48 if (notificationString == null) {
49 return Either.right(404);
51 ObjectMapper mapper = new ObjectMapper();
53 Notification notification = new Notification();
55 notification = mapper.readValue(notificationString, Notification.class);
56 return Either.left(notification);
57 } catch (IOException e) {
58 log.error("Exception in parsing notification", notificationString, e);
59 return Either.right(400);
64 * Get pm notifications.
66 public Either<PmNotification,Integer> getPmNotifications() {
67 PerformanceNotificationsRepository pmNotificationRepository =
68 BeanUtil.getBean(PerformanceNotificationsRepository.class);
69 String pmNotificationString = pmNotificationRepository.getPerformanceNotificationFromQueue();
70 if (pmNotificationString == null) {
71 return Either.right(404);
73 ObjectMapper mapper = new ObjectMapper();
74 PmNotification pmNotification = new PmNotification();
77 pmNotification = mapper.readValue(pmNotificationString, PmNotification.class);
78 return Either.left(pmNotification);
79 } catch (IOException e) {
80 log.error("Exception in parsing pm notification ",pmNotificationString,e);
81 return Either.right(400);