Search in sources :

Example 1 with NotificationState

use of com.pratilipi.common.type.NotificationState in project pratilipi by Pratilipi.

the class NotificationDataUtil method saveNotificationState.

public static void saveNotificationState(Map<Long, NotificationState> notificationStates) throws InsufficientAccessException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Map<Long, Notification> notifications = dataAccessor.getNotifications(notificationStates.keySet());
    for (Map.Entry<Long, NotificationState> entry : notificationStates.entrySet()) {
        Notification notification = notifications.get(entry.getKey());
        if (notification.getState() == entry.getValue())
            continue;
        if (!hasAccessToUpdateData(notification))
            throw new InsufficientAccessException();
        notification.setState(entry.getValue());
    }
    dataAccessor.createOrUpdateNotificationList(new ArrayList<Notification>(notifications.values()));
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) HashMap(java.util.HashMap) Map(java.util.Map) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException) Notification(com.pratilipi.data.type.Notification) NotificationState(com.pratilipi.common.type.NotificationState)

Aggregations

InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)1 NotificationState (com.pratilipi.common.type.NotificationState)1 DataAccessor (com.pratilipi.data.DataAccessor)1 Notification (com.pratilipi.data.type.Notification)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1