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 public class KCBNotificationService extends DefaultNotificationService {
40 @Override
41 protected void sendNotification(ActionItem actionItem) {
42 super.sendNotification(actionItem);
43
44 String enableKENNotificationValue = ConfigContext.getCurrentContextConfig().getProperty(KewApiConstants.ENABLE_KEN_NOTIFICATION);
45 boolean enableKENNotification = Boolean.parseBoolean(enableKENNotificationValue);
46
47 if (!enableKENNotification || actionItem.getPrincipalId() != null)
48 return;
49
50
51
52 MessagingService ms = (MessagingService) GlobalResourceLoader.getService(new QName(KCBConstants.SERVICE_NAMESPACE, KCBServiceNames.KCB_MESSAGING));
53 if (ms == null) {
54 LOG.info("Could not locate KCB MessagingService. Message will not be forwarded to the KCB.");
55 return;
56 }
57 MessageDTO mvo = new MessageDTO();
58 mvo.setChannel("KEW");
59 mvo.setContent("i'm a kew notification");
60 mvo.setContentType("KEW notification");
61 mvo.setDeliveryType(actionItem.getActionRequestCd());
62 mvo.setProducer("kew@localhost");
63 mvo.setTitle(actionItem.getDocLabel() + " - " + actionItem.getDocName() + " - " + actionItem.getDocTitle());
64 if (StringUtils.isNotBlank(actionItem.getDocHandlerURL())) {
65 mvo.setUrl(actionItem.getDocHandlerURL() + "?docId=" + actionItem.getDocumentId());
66 }
67 mvo.setOriginId(String.valueOf(actionItem.getId()));
68 try {
69
70 mvo.setRecipient(actionItem.getPrincipalId());
71 LOG.debug("Sending message to KCB: " + mvo);
72 ms.deliver(mvo);
73 } catch (Exception e) {
74 throw new WorkflowRuntimeException("could not deliver message to KCB", e);
75 }
76 }
77
78 @Override
79 public void removeNotification(List<ActionItem> actionItems) {
80 String enableKENNotificationValue = ConfigContext.getCurrentContextConfig().getProperty(KewApiConstants.ENABLE_KEN_NOTIFICATION);
81 boolean enableKENNotification = Boolean.parseBoolean(enableKENNotificationValue);
82 if (!enableKENNotification) {
83 return;
84 }
85 MessagingService ms = (MessagingService) GlobalResourceLoader.getService(new QName(KCBConstants.SERVICE_NAMESPACE, KCBServiceNames.KCB_MESSAGING));
86
87 for (ActionItem actionItem: actionItems) {
88 LOG.debug("Removing KCB messages for action item: " + actionItem.getId() + " " + actionItem.getActionRequestCd() + " " + actionItem.getPrincipalId());
89 try {
90
91 ms.removeByOriginId(String.valueOf(actionItem.getId()), null, null);
92 } catch (Exception e) {
93 throw new RuntimeException("could not remove message from KCB", e);
94 }
95 }
96 }
97 }