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