1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.postprocessor.kew;
17
18 import org.apache.log4j.Logger;
19 import org.kuali.rice.ken.bo.NotificationMessageDelivery;
20 import org.kuali.rice.ken.core.GlobalNotificationServiceLocator;
21 import org.kuali.rice.ken.deliverer.impl.KEWActionListMessageDeliverer;
22 import org.kuali.rice.ken.service.NotificationMessageDeliveryService;
23 import org.kuali.rice.ken.service.NotificationService;
24 import org.kuali.rice.ken.util.NotificationConstants;
25 import org.kuali.rice.ken.util.Util;
26 import org.kuali.rice.kew.api.KewApiConstants;
27 import org.kuali.rice.kew.api.WorkflowDocument;
28 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
29 import org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent;
30 import org.kuali.rice.kew.framework.postprocessor.AfterProcessEvent;
31 import org.kuali.rice.kew.framework.postprocessor.BeforeProcessEvent;
32 import org.kuali.rice.kew.framework.postprocessor.DeleteEvent;
33 import org.kuali.rice.kew.framework.postprocessor.DocumentLockingEvent;
34 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
35 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
36 import org.kuali.rice.kew.framework.postprocessor.PostProcessor;
37 import org.kuali.rice.kew.framework.postprocessor.ProcessDocReport;
38
39 import java.io.ByteArrayInputStream;
40 import java.io.IOException;
41 import java.util.List;
42 import java.util.Properties;
43
44
45
46
47
48
49
50
51
52 public class NotificationPostProcessor implements PostProcessor {
53 private static final Logger LOG = Logger.getLogger(NotificationPostProcessor.class);
54
55 NotificationService notificationService;
56 NotificationMessageDeliveryService msgDeliverySvc;
57
58
59
60
61 public NotificationPostProcessor() {
62 this.msgDeliverySvc = GlobalNotificationServiceLocator.getInstance().getNotificationMessageDeliveryService();
63 this.notificationService = GlobalNotificationServiceLocator.getInstance().getNotificationService();
64 }
65
66
67
68
69
70
71 public ProcessDocReport doActionTaken(ActionTakenEvent event) throws Exception {
72 LOG.debug("ENTERING NotificationPostProcessor.doActionTaken() for Notification action item with document ID: " + event.getDocumentId());
73
74
75
76
77
78
79 LOG.debug("ACTION TAKEN=" + event.getActionTaken().getActionTaken());
80
81 String actionTakenCode = event.getActionTaken().getActionTaken().getCode();
82
83 Properties p = new Properties();
84 WorkflowDocument doc = WorkflowDocumentFactory.loadDocument(event.getActionTaken().getPrincipalId(), event.getDocumentId());
85 try {
86 p.load(new ByteArrayInputStream(doc.getAttributeContent().getBytes()));
87 } catch (IOException ioe) {
88 throw new RuntimeException(ioe);
89 }
90 String internalCommand = p.getProperty(KEWActionListMessageDeliverer.INTERNAL_COMMAND_FLAG);
91
92 if (Boolean.valueOf(internalCommand).booleanValue()) {
93 LOG.info("Internal command detected by NotificationPostProcessor - will not invoke KEN");
94 return new ProcessDocReport(true, "");
95 }
96
97 LOG.info("NotificationPostProcessor detected end-user action " + event.getActionTaken().getActionTaken() + " on document " + event.getActionTaken().getDocumentId());
98
99 if(actionTakenCode.equals(KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD) || actionTakenCode.equals(KewApiConstants.ACTION_TAKEN_FYI_CD)) {
100 LOG.debug("User has taken either acknowledge or fy action (action code=" + actionTakenCode +
101 ") for Notification action item with document ID: " + event.getDocumentId() +
102 ". We are now changing the status of the associated NotificationMessageDelivery to REMOVED.");
103
104 try {
105 NotificationMessageDelivery nmd = msgDeliverySvc.getNotificationMessageDeliveryByDelivererId(event.getDocumentId());
106
107 if (nmd == null) {
108 throw new RuntimeException("Could not find message delivery from workflow document " + event.getDocumentId() + " to dismiss");
109 }
110
111
112 String cause;
113 if (KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD.equals(actionTakenCode)) {
114 cause = NotificationConstants.ACK_CAUSE;
115 } else if (KewApiConstants.ACTION_TAKEN_FYI_CD.equals(actionTakenCode)) {
116 cause = NotificationConstants.FYI_CAUSE;
117 } else {
118 cause = "unknown";
119 }
120
121 LOG.info("Dismissing message id " + nmd.getId() + " due to cause: " + cause);
122 notificationService.dismissNotificationMessageDelivery(nmd.getId(),
123 Util.getNotificationSystemUser(),
124 cause);
125 } catch(Exception e) {
126 throw new RuntimeException("Error dismissing message", e);
127 }
128 }
129
130 LOG.debug("LEAVING NotificationPostProcessor.doActionTaken() for Notification action item with document ID: " + event.getDocumentId());
131 return new ProcessDocReport(true);
132 }
133
134
135
136
137 public ProcessDocReport doDeleteRouteHeader(DeleteEvent arg0) throws Exception {
138 return new ProcessDocReport(true, "");
139 }
140
141
142
143
144 public ProcessDocReport doRouteLevelChange(DocumentRouteLevelChange arg0) throws Exception {
145 return new ProcessDocReport(true, "");
146 }
147
148
149
150
151 public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange arg0) throws Exception {
152 return new ProcessDocReport(true, "");
153 }
154
155
156
157
158 public ProcessDocReport beforeProcess(BeforeProcessEvent beforeProcessEvent) throws Exception {
159 return new ProcessDocReport(true, "");
160 }
161
162
163
164
165 public ProcessDocReport afterProcess(AfterProcessEvent afterProcessEvent) throws Exception {
166 return new ProcessDocReport(true, "");
167 }
168
169
170
171
172 public List<String> getDocumentIdsToLock(DocumentLockingEvent documentLockingEvent) throws Exception {
173 return null;
174 }
175
176
177
178
179 }