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