2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
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=========================================================
21 package org.openecomp.sdc.notification.services.impl;
23 import org.openecomp.sdc.notification.dao.LastNotificationDao;
24 import org.openecomp.sdc.notification.dao.NotificationsDao;
25 import org.openecomp.sdc.notification.dao.types.LastSeenNotificationEntity;
26 import org.openecomp.sdc.notification.dao.types.NotificationEntity;
27 import org.openecomp.sdc.notification.dtos.NotificationsStatus;
28 import org.openecomp.sdc.notification.exceptons.NotificationNotExistException;
29 import org.openecomp.sdc.notification.services.NotificationsService;
31 import java.util.List;
32 import java.util.Objects;
33 import java.util.UUID;
37 * @since June 26, 2017
39 public class NotificationsServiceImpl implements NotificationsService {
41 private LastNotificationDao lastNotificationDao;
42 private NotificationsDao notificationsDao;
44 public NotificationsServiceImpl(LastNotificationDao lastNotificationDao,
45 NotificationsDao notificationsDao) {
46 this.lastNotificationDao = lastNotificationDao;
47 this.notificationsDao = notificationsDao;
51 public LastSeenNotificationEntity getLastNotification(String ownerId) {
52 return new LastSeenNotificationEntity(ownerId,
53 lastNotificationDao.getOwnerLastEventId(ownerId));
57 public void updateLastSeenNotification(String ownerId, UUID eventId)
59 lastNotificationDao.persistOwnerLastEventId(ownerId, eventId);
63 public NotificationsStatus getNotificationsStatus(String ownerId, UUID lastDelivered, int numOfRecordsToReturn, UUID endOfPage) {
64 if (Objects.isNull(lastDelivered)) {
65 LastSeenNotificationEntity entity = getLastNotification(ownerId);
66 if (Objects.nonNull(entity)) {
67 lastDelivered = entity.getLastEventId();
69 if (Objects.isNull(lastDelivered)) {
70 lastDelivered = UUID.fromString("00000000-0000-1000-8080-808080808080"); // Lowest time UUID value
73 if (Objects.isNull(endOfPage)) {
75 return notificationsDao.getNotificationsStatus(ownerId, lastDelivered, numOfRecordsToReturn);
79 return notificationsDao.getNotificationsStatus(ownerId, lastDelivered, numOfRecordsToReturn, endOfPage);
84 public void markAsRead(String ownerId, String notificationId) throws
85 NotificationNotExistException {
86 NotificationEntity notificationEntity =
87 notificationsDao.get(new NotificationEntity(ownerId, UUID.fromString(notificationId)));
88 if (Objects.isNull(notificationEntity)) {
89 throw new NotificationNotExistException(
90 "Notification '" + notificationId + "' is not related to ownerId" +
91 " '" + ownerId + "'");
93 notificationEntity.setRead(true);
94 notificationsDao.update(notificationEntity);
98 public List<NotificationEntity> getNotificationsByOwnerId(String ownerId, int limit) {
99 return notificationsDao.getNotificationsByOwnerId(ownerId, limit);
103 public List<NotificationEntity> getNewNotificationsByOwnerId(String ownerId, UUID eventId) {
104 return notificationsDao.getNewNotificationsByOwnerId(ownerId, eventId);
108 public List<NotificationEntity> getNewNotificationsByOwnerId(String ownerId, UUID eventId, int limit) {
109 return notificationsDao.getNewNotificationsByOwnerId(ownerId, eventId, limit);