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