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