Ejemplo n.º 1
0
 @Override
 public NotificationEntity addNotification(String userId, Notification notification) {
   try {
     String notificationEventSerialized = objectMapper.writeValueAsString(notification);
     String notificationString = notificationEventSerialized;
     NotificationEntity notificationEntity = getFreshNotification(userId);
     Set<String> notifications = notificationEntity.getNotifications();
     notifications.add(notificationString);
     return savenotification(notificationEntity);
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
Ejemplo n.º 2
0
  @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);
  }
Ejemplo n.º 3
0
  @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;
  }