1 package org.openecomp.sdc.notification.services.impl;
3 import org.openecomp.sdc.notification.dao.LastNotificationDao;
4 import org.openecomp.sdc.notification.dao.NotificationsDao;
5 import org.openecomp.sdc.notification.dao.types.LastSeenNotificationEntity;
6 import org.openecomp.sdc.notification.dao.types.NotificationEntity;
7 import org.openecomp.sdc.notification.dtos.NotificationsStatus;
8 import org.openecomp.sdc.notification.exceptons.NotificationNotExistException;
9 import org.openecomp.sdc.notification.services.NotificationsService;
11 import java.util.List;
12 import java.util.Objects;
13 import java.util.UUID;
17 * @since June 26, 2017
19 public class NotificationsServiceImpl implements NotificationsService {
21 private LastNotificationDao lastNotificationDao;
22 private NotificationsDao notificationsDao;
24 public NotificationsServiceImpl(LastNotificationDao lastNotificationDao,
25 NotificationsDao notificationsDao) {
26 this.lastNotificationDao = lastNotificationDao;
27 this.notificationsDao = notificationsDao;
31 public LastSeenNotificationEntity getLastNotification(String ownerId) {
32 return new LastSeenNotificationEntity(ownerId,
33 lastNotificationDao.getOwnerLastEventId(ownerId));
37 public void updateLastSeenNotification(String ownerId, UUID eventId)
39 lastNotificationDao.persistOwnerLastEventId(ownerId, eventId);
43 public NotificationsStatus getNotificationsStatus(String ownerId, UUID lastDelivered, int numOfRecordsToReturn, UUID endOfPage) {
44 if (Objects.isNull(lastDelivered)) {
45 LastSeenNotificationEntity entity = getLastNotification(ownerId);
46 if (Objects.nonNull(entity)) {
47 lastDelivered = entity.getLastEventId();
49 if (Objects.isNull(lastDelivered)) {
50 lastDelivered = UUID.fromString("00000000-0000-1000-8080-808080808080"); // Lowest time UUID value
53 if (Objects.isNull(endOfPage)) {
55 return notificationsDao.getNotificationsStatus(ownerId, lastDelivered, numOfRecordsToReturn);
59 return notificationsDao.getNotificationsStatus(ownerId, lastDelivered, numOfRecordsToReturn, endOfPage);
64 public void markAsRead(String ownerId, String notificationId) throws
65 NotificationNotExistException {
66 NotificationEntity notificationEntity =
67 notificationsDao.get(new NotificationEntity(ownerId, UUID.fromString(notificationId)));
68 if (Objects.isNull(notificationEntity)) {
69 throw new NotificationNotExistException(
70 "Notification '" + notificationId + "' is not related to ownerId" +
71 " '" + ownerId + "'");
73 notificationEntity.setRead(true);
74 notificationsDao.update(notificationEntity);
78 public List<NotificationEntity> getNotificationsByOwnerId(String ownerId, int limit) {
79 return notificationsDao.getNotificationsByOwnerId(ownerId, limit);
83 public List<NotificationEntity> getNewNotificationsByOwnerId(String ownerId, UUID eventId) {
84 return notificationsDao.getNewNotificationsByOwnerId(ownerId, eventId);
88 public List<NotificationEntity> getNewNotificationsByOwnerId(String ownerId, UUID eventId, int limit) {
89 return notificationsDao.getNewNotificationsByOwnerId(ownerId, eventId, limit);