| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.ken.service.impl; |
| 17 | |
|
| 18 | |
import org.kuali.rice.core.api.util.RiceConstants; |
| 19 | |
import org.kuali.rice.core.framework.persistence.dao.GenericDao; |
| 20 | |
import org.kuali.rice.ken.bo.Notification; |
| 21 | |
import org.kuali.rice.ken.bo.NotificationMessageDelivery; |
| 22 | |
import org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao; |
| 23 | |
import org.kuali.rice.ken.service.NotificationMessageDeliveryService; |
| 24 | |
import org.kuali.rice.ken.util.NotificationConstants; |
| 25 | |
|
| 26 | |
import java.sql.Timestamp; |
| 27 | |
import java.util.Collection; |
| 28 | |
import java.util.HashMap; |
| 29 | |
import java.util.Map; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public class NotificationMessageDeliveryServiceImpl implements NotificationMessageDeliveryService { |
| 39 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger |
| 40 | |
.getLogger(NotificationMessageDeliveryServiceImpl.class); |
| 41 | |
|
| 42 | |
private GenericDao businessObjectDao; |
| 43 | |
private NotificationMessegeDeliveryDao ntdDao; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | 0 | public NotificationMessageDeliveryServiceImpl(GenericDao businessObjectDao, NotificationMessegeDeliveryDao ntdDao) { |
| 50 | 0 | this.businessObjectDao = businessObjectDao; |
| 51 | 0 | this.ntdDao = ntdDao; |
| 52 | 0 | } |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
public NotificationMessageDelivery getNotificationMessageDelivery(Long id) { |
| 60 | 0 | HashMap<String, Long> primaryKeys = new HashMap<String, Long>(); |
| 61 | 0 | primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, id); |
| 62 | |
|
| 63 | 0 | return (NotificationMessageDelivery) businessObjectDao.findByPrimaryKey(NotificationMessageDelivery.class, primaryKeys); |
| 64 | |
} |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
public NotificationMessageDelivery getNotificationMessageDeliveryByDelivererId(String id) { |
| 71 | 0 | Map<String, Object> c = new HashMap<String, Object>(); |
| 72 | 0 | c.put(NotificationConstants.BO_PROPERTY_NAMES.DELIVERY_SYSTEM_ID, id); |
| 73 | 0 | Collection<NotificationMessageDelivery> results = businessObjectDao.findMatching(NotificationMessageDelivery.class, c); |
| 74 | |
|
| 75 | 0 | if (results == null || results.size() == 0) return null; |
| 76 | 0 | if (results.size() > 1) { |
| 77 | 0 | throw new RuntimeException("More than one message delivery found with the following delivery system id: " + id); |
| 78 | |
} |
| 79 | 0 | return results.iterator().next(); |
| 80 | |
} |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
public Collection<NotificationMessageDelivery> getNotificationMessageDeliveries() { |
| 86 | 0 | return businessObjectDao.findAll(NotificationMessageDelivery.class); |
| 87 | |
} |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
public Collection<NotificationMessageDelivery> getNotificationMessageDeliveries(Notification notification, String userRecipientId) { |
| 94 | |
|
| 95 | 0 | Map<String, Object> c = new HashMap<String, Object>(); |
| 96 | 0 | c.put(NotificationConstants.BO_PROPERTY_NAMES.NOTIFICATION, notification.getId()); |
| 97 | 0 | c.put(NotificationConstants.BO_PROPERTY_NAMES.USER_RECIPIENT_ID, userRecipientId); |
| 98 | |
|
| 99 | 0 | return businessObjectDao.findMatching(NotificationMessageDelivery.class, c); |
| 100 | |
} |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
public Collection<NotificationMessageDelivery> takeMessageDeliveriesForDispatch() { |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | 0 | Collection<NotificationMessageDelivery> messageDeliveries = ntdDao.getUndeliveredMessageDelivers(businessObjectDao); |
| 118 | |
|
| 119 | |
|
| 120 | 0 | LOG.debug("Retrieved " + messageDeliveries.size() + " available message deliveries: " + System.currentTimeMillis()); |
| 121 | |
|
| 122 | |
|
| 123 | 0 | for (NotificationMessageDelivery delivery: messageDeliveries) { |
| 124 | 0 | delivery.setLockedDate(new Timestamp(System.currentTimeMillis())); |
| 125 | 0 | businessObjectDao.save(delivery); |
| 126 | |
} |
| 127 | 0 | return messageDeliveries; |
| 128 | |
} |
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
public Collection<NotificationMessageDelivery> takeMessageDeliveriesForAutoRemoval() { |
| 139 | |
|
| 140 | 0 | Collection<NotificationMessageDelivery> messageDeliveries = ntdDao.getMessageDeliveriesForAutoRemoval(new Timestamp(System.currentTimeMillis()), businessObjectDao); |
| 141 | |
|
| 142 | 0 | for (NotificationMessageDelivery d: messageDeliveries) { |
| 143 | 0 | d.setLockedDate(new Timestamp(System.currentTimeMillis())); |
| 144 | 0 | businessObjectDao.save(d); |
| 145 | |
} |
| 146 | |
|
| 147 | 0 | return messageDeliveries; |
| 148 | |
|
| 149 | |
} |
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
public void unlockMessageDelivery(NotificationMessageDelivery messageDelivery) { |
| 156 | 0 | Map<String, Long> c = new HashMap<String, Long>(); |
| 157 | 0 | c.put(NotificationConstants.BO_PROPERTY_NAMES.DELIVERY_SYSTEM_ID, messageDelivery.getId()); |
| 158 | |
|
| 159 | 0 | Collection<NotificationMessageDelivery> deliveries = businessObjectDao.findMatching(NotificationMessageDelivery.class, c, true, RiceConstants.NO_WAIT); |
| 160 | 0 | if (deliveries == null || deliveries.size() == 0) { |
| 161 | 0 | throw new RuntimeException("NotificationMessageDelivery #" + messageDelivery.getId() + " not found to unlock"); |
| 162 | |
} |
| 163 | |
|
| 164 | 0 | NotificationMessageDelivery d = deliveries.iterator().next(); |
| 165 | 0 | d.setLockedDate(null); |
| 166 | |
|
| 167 | 0 | businessObjectDao.save(d); |
| 168 | 0 | } |
| 169 | |
} |