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