1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kcb.quartz; |
17 | |
|
18 | |
import java.util.Collection; |
19 | |
|
20 | |
import org.apache.log4j.Logger; |
21 | |
import org.kuali.rice.kcb.bo.Message; |
22 | |
import org.kuali.rice.kcb.bo.MessageDelivery; |
23 | |
import org.kuali.rice.kcb.quartz.MessageProcessingJob.Mode; |
24 | |
import org.kuali.rice.kcb.service.GlobalKCBServiceLocator; |
25 | |
import org.kuali.rice.kcb.service.MessageDeliveryService; |
26 | |
import org.kuali.rice.kcb.service.MessageService; |
27 | |
import org.quartz.JobExecutionContext; |
28 | |
import org.quartz.JobExecutionException; |
29 | |
import org.quartz.JobListener; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class MessageDeletionListener implements JobListener { |
38 | |
public static final String NAME = "MessageDeletionListener"; |
39 | |
|
40 | 0 | private static final Logger LOG = Logger.getLogger(MessageDeletionListener.class); |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public String getName() { |
47 | 0 | return NAME; |
48 | |
} |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public void jobExecutionVetoed(JobExecutionContext arg0) { |
54 | 0 | } |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public void jobToBeExecuted(JobExecutionContext arg0) { |
60 | 0 | } |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public void jobWasExecuted(JobExecutionContext context, JobExecutionException exception) { |
66 | 0 | if (exception != null) { |
67 | 0 | LOG.error("Exception occurred in DeliveryJob, not acting", exception); |
68 | 0 | return; |
69 | |
} |
70 | |
|
71 | 0 | long messageId = context.getMergedJobDataMap().getLong("messageId"); |
72 | 0 | LOG.debug("Handling message " + messageId); |
73 | 0 | Mode mode = Mode.valueOf(context.getMergedJobDataMap().getString("mode")); |
74 | |
|
75 | 0 | MessageService ms = GlobalKCBServiceLocator.getInstance().getMessageService(); |
76 | 0 | Message m = ms.getMessage(messageId); |
77 | |
|
78 | 0 | if (m == null) { |
79 | |
|
80 | |
|
81 | 0 | LOG.warn("Called for invalid message: " + messageId); |
82 | 0 | return; |
83 | |
} |
84 | 0 | MessageDeliveryService mds = GlobalKCBServiceLocator.getInstance().getMessageDeliveryService(); |
85 | 0 | Collection<MessageDelivery> c = mds.getMessageDeliveries(m); |
86 | 0 | if (c.size() == 0) { |
87 | 0 | LOG.debug("Deleting message " + m); |
88 | 0 | ms.deleteMessage(m); |
89 | |
} else { |
90 | 0 | LOG.debug("Message " + m.getId() + " has " + c.size() + " deliveries"); |
91 | 0 | for (MessageDelivery md: c) { |
92 | 0 | LOG.debug(md); |
93 | |
} |
94 | |
} |
95 | |
|
96 | 0 | } |
97 | |
} |