1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.ken.service.impl; |
18 | |
|
19 | |
import org.kuali.rice.core.framework.persistence.dao.GenericDao; |
20 | |
import org.kuali.rice.ken.bo.NotificationMessageDelivery; |
21 | |
import org.kuali.rice.ken.deliverer.NotificationMessageDeliverer; |
22 | |
import org.kuali.rice.ken.deliverer.impl.KEWActionListMessageDeliverer; |
23 | |
import org.kuali.rice.ken.exception.NotificationAutoRemoveException; |
24 | |
import org.kuali.rice.ken.service.NotificationMessageDeliveryAutoRemovalService; |
25 | |
import org.kuali.rice.ken.service.NotificationMessageDeliveryService; |
26 | |
import org.kuali.rice.ken.service.ProcessingResult; |
27 | |
import org.kuali.rice.ken.util.NotificationConstants; |
28 | |
import org.springframework.transaction.PlatformTransactionManager; |
29 | |
|
30 | |
import java.sql.Timestamp; |
31 | |
import java.util.ArrayList; |
32 | |
import java.util.Collection; |
33 | |
import java.util.List; |
34 | |
import java.util.concurrent.ExecutorService; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public class NotificationMessageDeliveryAutoRemovalServiceImpl extends ConcurrentJob<NotificationMessageDelivery> implements NotificationMessageDeliveryAutoRemovalService { |
41 | |
private GenericDao businessObjectDao; |
42 | |
private NotificationMessageDeliveryService messageDeliveryService; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public NotificationMessageDeliveryAutoRemovalServiceImpl(GenericDao businessObjectDao, PlatformTransactionManager txManager, |
52 | |
ExecutorService executor, NotificationMessageDeliveryService messageDeliveryService) { |
53 | 0 | super(txManager, executor); |
54 | 0 | this.messageDeliveryService = messageDeliveryService; |
55 | 0 | this.businessObjectDao = businessObjectDao; |
56 | 0 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
@Override |
62 | |
protected Collection<NotificationMessageDelivery> takeAvailableWorkItems() { |
63 | 0 | return messageDeliveryService.takeMessageDeliveriesForAutoRemoval(); |
64 | |
} |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
@Override |
70 | |
protected Collection<String> processWorkItems(Collection<NotificationMessageDelivery> messageDeliveries) { |
71 | 0 | NotificationMessageDelivery firstMessageDelivery = messageDeliveries.iterator().next(); |
72 | |
|
73 | 0 | KEWActionListMessageDeliverer deliverer = new KEWActionListMessageDeliverer(); |
74 | 0 | Collection<String> successes = new ArrayList<String>(); |
75 | 0 | for (NotificationMessageDelivery delivery: messageDeliveries) { |
76 | 0 | successes.addAll(autoRemove(deliverer, delivery)); |
77 | |
} |
78 | 0 | return successes; |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
protected Collection<String> autoRemove(NotificationMessageDeliverer messageDeliverer, NotificationMessageDelivery messageDelivery) { |
88 | 0 | List<String> successes = new ArrayList<String>(1); |
89 | |
|
90 | |
|
91 | |
try { |
92 | 0 | messageDeliverer.autoRemoveMessageDelivery(messageDelivery); |
93 | 0 | LOG.debug("Auto-removal of message delivery '" + messageDelivery.getId() + "' for notification '" + messageDelivery.getNotification().getId() + "' was successful."); |
94 | 0 | successes.add("Auto-removal of message delivery '" + messageDelivery.getId() + "' for notification '" + messageDelivery.getNotification().getId() + "' was successful."); |
95 | 0 | } catch (NotificationAutoRemoveException nmde) { |
96 | 0 | LOG.error("Error auto-removing message " + messageDelivery); |
97 | 0 | throw new RuntimeException(nmde); |
98 | 0 | } |
99 | |
|
100 | |
|
101 | |
|
102 | 0 | markAutoRemoved(messageDelivery); |
103 | |
|
104 | 0 | return successes; |
105 | |
} |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
protected void markAutoRemoved(NotificationMessageDelivery messageDelivery) { |
112 | 0 | messageDelivery.setMessageDeliveryStatus(NotificationConstants.MESSAGE_DELIVERY_STATUS.AUTO_REMOVED); |
113 | |
|
114 | 0 | messageDelivery.setLockedDate(null); |
115 | 0 | businessObjectDao.save(messageDelivery); |
116 | 0 | } |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
@Override |
122 | |
protected void unlockWorkItem(NotificationMessageDelivery delivery) { |
123 | 0 | messageDeliveryService.unlockMessageDelivery(delivery); |
124 | 0 | } |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
public ProcessingResult processAutoRemovalOfDeliveredNotificationMessageDeliveries() { |
133 | 0 | LOG.debug("[" + new Timestamp(System.currentTimeMillis()).toString() + "] STARTING NOTIFICATION AUTO-REMOVAL PROCESSING"); |
134 | |
|
135 | 0 | ProcessingResult result = run(); |
136 | |
|
137 | 0 | LOG.debug("[" + new Timestamp(System.currentTimeMillis()).toString() + "] FINISHED NOTIFICATION AUTO-REMOVAL PROCESSING - Successes = " + result.getSuccesses().size() + ", Failures = " + result.getFailures().size()); |
138 | |
|
139 | 0 | return result; |
140 | |
} |
141 | |
} |