1 24 package org.riotfamily.riot.workflow.notification.support; 25 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.HashSet ; 29 import java.util.List ; 30 import java.util.Map ; 31 import java.util.Set ; 32 33 import org.riotfamily.riot.workflow.notification.Notification; 34 import org.riotfamily.riot.workflow.notification.NotificationDao; 35 36 public class DefaultNotificationDao implements NotificationDao { 37 38 private List notifications = new ArrayList (); 39 40 private Map notificationsReadByUser = new HashMap (); 41 42 43 public DefaultNotificationDao() { 44 } 45 46 public List getNotifications(String userId) { 47 Set readNotificationIds = (Set ) notificationsReadByUser.get(userId); 48 if (readNotificationIds == null) { 49 return notifications; 50 } 51 else { 52 return getUnreadNotifications(readNotificationIds); 53 } 54 } 55 56 private List getUnreadNotifications(Set readNotificationIds) { 57 List unreadNotifications = new ArrayList (); 58 for (int i = 0; i < notifications.size(); i++) { 59 Notification notification = (Notification) notifications.get(i); 60 if (!readNotificationIds.contains(notification.getId())) { 61 unreadNotifications.add(notification); 62 } 63 } 64 return unreadNotifications; 65 } 66 67 public void markAsRead(String userId, Long notificationId) { 68 Set readNotifications = (Set ) notificationsReadByUser.get(userId); 69 if (readNotifications == null) { 70 readNotifications = new HashSet (); 71 notificationsReadByUser.put(userId, readNotifications); 72 } 73 readNotifications.add(notificationId); 74 } 75 76 public void saveNotification(Notification notification) { 77 notifications.add(notification); 78 } 79 80 } 81 | Popular Tags |