@Override public NotificationEntity getFreshNotification(String userId) { NotificationEntity notificationEntity = notificationRepository.getFreshNotificationForUser( userId, NotificationType.FRESH.toString()); return notificationEntity; }
@Override public void moveNotification(String userId) { NotificationEntity freshNotificationEntity = notificationRepository.getFreshNotificationForUser( userId, NotificationType.FRESH.toString()); NotificationEntity pastNotificationEntity = notificationRepository.getFreshNotificationForUser( userId, NotificationType.PAST.toString()); pastNotificationEntity.getNotifications().addAll(freshNotificationEntity.getNotifications()); savenotification(pastNotificationEntity); freshNotificationEntity.getNotifications().clear(); savenotification(freshNotificationEntity); }
@Override public List<Notification> getNotifications(String userId, String filter) { List<Notification> notifications = new ArrayList<Notification>(); Set<String> notificationsSet = new HashSet<String>(); if (filter.equalsIgnoreCase("all")) { List<NotificationEntity> notificationEntity = notificationRepository.getAllNotificationForUser(userId); for (NotificationEntity eachNotificationEntity : notificationEntity) { notificationsSet.addAll(eachNotificationEntity.getNotifications()); } for (String eachNotification : notificationsSet) { try { System.out.println("each notification" + eachNotification); Notification notificationDeserialised = objectMapper.readValue(eachNotification, Notification.class); notifications.add(notificationDeserialised); } catch (Exception e) { e.printStackTrace(); } } } else { NotificationEntity notificationEntity = notificationRepository.getFreshNotificationForUser( userId, NotificationType.FRESH.toString()); notificationsSet.addAll(notificationEntity.getNotifications()); for (String eachNotification : notificationsSet) { try { System.out.println("each notification" + eachNotification); Notification notificationDeserialised = objectMapper.readValue(eachNotification, Notification.class); notifications.add(notificationDeserialised); } catch (Exception e) { e.printStackTrace(); } } } return notifications; }