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.api.WorkflowDocument; |
32 | |
import org.kuali.rice.kew.api.WorkflowDocumentFactory; |
33 | |
import org.kuali.rice.kew.dto.ActionTakenEventDTO; |
34 | |
import org.kuali.rice.kew.dto.AfterProcessEventDTO; |
35 | |
import org.kuali.rice.kew.dto.BeforeProcessEventDTO; |
36 | |
import org.kuali.rice.kew.dto.DeleteEventDTO; |
37 | |
import org.kuali.rice.kew.dto.DocumentLockingEventDTO; |
38 | |
import org.kuali.rice.kew.dto.DocumentRouteLevelChangeDTO; |
39 | |
import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO; |
40 | |
import org.kuali.rice.kew.postprocessor.PostProcessorRemote; |
41 | |
import org.kuali.rice.kew.util.KEWConstants; |
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 | 0 | WorkflowDocument doc = WorkflowDocumentFactory.loadDocument(event.getActionTaken().getPrincipalId(), event.getDocumentId()); |
84 | |
try { |
85 | 0 | p.load(new ByteArrayInputStream(doc.getAttributeContent().getBytes())); |
86 | 0 | } catch (IOException ioe) { |
87 | 0 | throw new RuntimeException(ioe); |
88 | 0 | } |
89 | 0 | String internalCommand = p.getProperty(KEWActionListMessageDeliverer.INTERNAL_COMMAND_FLAG); |
90 | |
|
91 | 0 | if (Boolean.valueOf(internalCommand)) { |
92 | 0 | LOG.info("Internal command detected by NotificationPostProcessor - will not invoke KEN"); |
93 | 0 | return true; |
94 | |
} |
95 | |
|
96 | 0 | LOG.info("NotificationPostProcessor detected end-user action " + event.getActionTaken().getActionTaken() + " on document " + event.getActionTaken().getDocumentId()); |
97 | |
|
98 | 0 | if(actionTakenCode.equals(KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD) || actionTakenCode.equals(KEWConstants.ACTION_TAKEN_FYI_CD)) { |
99 | 0 | LOG.debug("User has taken either acknowledge or fy action (action code=" + actionTakenCode + |
100 | |
") for Notification action item with document ID: " + event.getDocumentId() + |
101 | |
". We are now changing the status of the associated NotificationMessageDelivery to REMOVED."); |
102 | |
|
103 | |
try { |
104 | 0 | NotificationMessageDelivery nmd = msgDeliverySvc.getNotificationMessageDeliveryByDelivererId(event.getDocumentId()); |
105 | |
|
106 | 0 | if (nmd == null) { |
107 | 0 | throw new RuntimeException("Could not find message delivery from workflow document " + event.getDocumentId() + " to dismiss"); |
108 | |
} |
109 | |
|
110 | |
|
111 | |
String cause; |
112 | 0 | if (KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD.equals(actionTakenCode)) { |
113 | 0 | cause = NotificationConstants.ACK_CAUSE; |
114 | 0 | } else if (KEWConstants.ACTION_TAKEN_FYI_CD.equals(actionTakenCode)) { |
115 | 0 | cause = NotificationConstants.FYI_CAUSE; |
116 | |
} else { |
117 | 0 | cause = "unknown"; |
118 | |
} |
119 | |
|
120 | 0 | LOG.info("Dismissing message id " + nmd.getId() + " due to cause: " + cause); |
121 | 0 | notificationService.dismissNotificationMessageDelivery(nmd.getId(), |
122 | |
Util.getNotificationSystemUser(), |
123 | |
cause); |
124 | 0 | } catch(Exception e) { |
125 | 0 | throw new RuntimeException("Error dismissing message", e); |
126 | 0 | } |
127 | |
} |
128 | |
|
129 | 0 | LOG.debug("LEAVING NotificationPostProcessor.doActionTaken() for Notification action item with document ID: " + event.getDocumentId()); |
130 | 0 | return true; |
131 | |
} |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
public boolean doDeleteRouteHeader(DeleteEventDTO arg0) throws RemoteException { |
137 | 0 | return true; |
138 | |
} |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
public boolean doRouteLevelChange(DocumentRouteLevelChangeDTO arg0) throws RemoteException { |
144 | 0 | return true; |
145 | |
} |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public boolean doRouteStatusChange(DocumentRouteStatusChangeDTO arg0) throws RemoteException { |
151 | 0 | return true; |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
public boolean beforeProcess(BeforeProcessEventDTO beforeProcessEvent) throws Exception { |
158 | 0 | return true; |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
public boolean afterProcess(AfterProcessEventDTO afterProcessEvent) throws Exception { |
165 | 0 | return true; |
166 | |
} |
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
public String[] getDocumentIdsToLock(DocumentLockingEventDTO documentLockingEvent) throws Exception { |
172 | 0 | return null; |
173 | |
} |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
} |