1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.notification.service.impl; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import javax.xml.namespace.QName; |
21 | |
|
22 | |
import org.apache.commons.lang.StringUtils; |
23 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
24 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
25 | |
import org.kuali.rice.kcb.api.message.MessageDTO; |
26 | |
import org.kuali.rice.kcb.api.service.KCBServiceNames; |
27 | |
import org.kuali.rice.kcb.api.service.MessagingService; |
28 | |
import org.kuali.rice.kcb.util.KCBConstants; |
29 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
30 | |
import org.kuali.rice.kew.api.action.ActionItem; |
31 | |
import org.kuali.rice.kew.api.KewApiConstants; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class KCBNotificationService extends DefaultNotificationService { |
40 | |
@Override |
41 | |
protected void sendNotification(ActionItem actionItem) { |
42 | 0 | super.sendNotification(actionItem); |
43 | |
|
44 | 0 | String enableKENNotificationValue = ConfigContext.getCurrentContextConfig().getProperty(KewApiConstants.ENABLE_KEN_NOTIFICATION); |
45 | 0 | boolean enableKENNotification = Boolean.parseBoolean(enableKENNotificationValue); |
46 | |
|
47 | 0 | if (!enableKENNotification || actionItem.getPrincipalId() != null) |
48 | 0 | return; |
49 | |
|
50 | |
|
51 | |
|
52 | 0 | MessagingService ms = (MessagingService) GlobalResourceLoader.getService(new QName(KCBConstants.SERVICE_NAMESPACE, KCBServiceNames.KCB_MESSAGING)); |
53 | 0 | if (ms == null) { |
54 | 0 | LOG.info("Could not locate KCB MessagingService. Message will not be forwarded to the KCB."); |
55 | 0 | return; |
56 | |
} |
57 | 0 | MessageDTO mvo = new MessageDTO(); |
58 | 0 | mvo.setChannel("KEW"); |
59 | 0 | mvo.setContent("i'm a kew notification"); |
60 | 0 | mvo.setContentType("KEW notification"); |
61 | 0 | mvo.setDeliveryType(actionItem.getActionRequestCd()); |
62 | 0 | mvo.setProducer("kew@localhost"); |
63 | 0 | mvo.setTitle(actionItem.getDocLabel() + " - " + actionItem.getDocName() + " - " + actionItem.getDocTitle()); |
64 | 0 | if (StringUtils.isNotBlank(actionItem.getDocHandlerURL())) { |
65 | 0 | mvo.setUrl(actionItem.getDocHandlerURL() + "?docId=" + actionItem.getDocumentId()); |
66 | |
} |
67 | 0 | mvo.setOriginId(String.valueOf(actionItem.getId())); |
68 | |
try { |
69 | |
|
70 | 0 | mvo.setRecipient(actionItem.getPrincipalId()); |
71 | 0 | LOG.debug("Sending message to KCB: " + mvo); |
72 | 0 | ms.deliver(mvo); |
73 | 0 | } catch (Exception e) { |
74 | 0 | throw new WorkflowRuntimeException("could not deliver message to KCB", e); |
75 | 0 | } |
76 | 0 | } |
77 | |
|
78 | |
@Override |
79 | |
public void removeNotification(List<ActionItem> actionItems) { |
80 | 0 | String enableKENNotificationValue = ConfigContext.getCurrentContextConfig().getProperty(KewApiConstants.ENABLE_KEN_NOTIFICATION); |
81 | 0 | boolean enableKENNotification = Boolean.parseBoolean(enableKENNotificationValue); |
82 | 0 | if (!enableKENNotification) { |
83 | 0 | return; |
84 | |
} |
85 | 0 | MessagingService ms = (MessagingService) GlobalResourceLoader.getService(new QName(KCBConstants.SERVICE_NAMESPACE, KCBServiceNames.KCB_MESSAGING)); |
86 | |
|
87 | 0 | for (ActionItem actionItem: actionItems) { |
88 | 0 | LOG.debug("Removing KCB messages for action item: " + actionItem.getId() + " " + actionItem.getActionRequestCd() + " " + actionItem.getPrincipalId()); |
89 | |
try { |
90 | |
|
91 | 0 | ms.removeByOriginId(String.valueOf(actionItem.getId()), null, null); |
92 | 0 | } catch (Exception e) { |
93 | 0 | throw new RuntimeException("could not remove message from KCB", e); |
94 | 0 | } |
95 | |
} |
96 | 0 | } |
97 | |
} |