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