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.core.framework.persistence.dao.GenericDao;
20 import org.kuali.rice.ken.bo.Notification;
21 import org.kuali.rice.ken.core.GlobalNotificationServiceLocator;
22 import org.kuali.rice.ken.document.kew.NotificationWorkflowDocument;
23 import org.kuali.rice.ken.service.NotificationMessageContentService;
24 import org.kuali.rice.ken.service.NotificationService;
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.framework.postprocessor.ActionTakenEvent;
29 import org.kuali.rice.kew.framework.postprocessor.AfterProcessEvent;
30 import org.kuali.rice.kew.framework.postprocessor.BeforeProcessEvent;
31 import org.kuali.rice.kew.framework.postprocessor.DeleteEvent;
32 import org.kuali.rice.kew.framework.postprocessor.DocumentLockingEvent;
33 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
34 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
35 import org.kuali.rice.kew.framework.postprocessor.PostProcessor;
36 import org.kuali.rice.kew.framework.postprocessor.ProcessDocReport;
37
38 import java.util.List;
39
40
41
42
43
44
45
46 public class NotificationSenderFormPostProcessor implements PostProcessor {
47 private static final Logger LOG = Logger.getLogger(NotificationSenderFormPostProcessor.class);
48
49 NotificationService notificationService;
50 GenericDao businessObjectDao;
51 NotificationMessageContentService messageContentService;
52
53
54
55
56 public NotificationSenderFormPostProcessor() {
57 this.notificationService = GlobalNotificationServiceLocator.getInstance().getNotificationService();
58 this.businessObjectDao = GlobalNotificationServiceLocator.getInstance().getGenericDao();
59 this.messageContentService = GlobalNotificationServiceLocator.getInstance().getNotificationMessageContentService();
60 }
61
62
63
64
65
66
67 public NotificationSenderFormPostProcessor(NotificationService notificationService, GenericDao businessObjectDao) {
68 this.notificationService = notificationService;
69 this.businessObjectDao = businessObjectDao;
70 }
71
72
73
74
75 @Override
76 public ProcessDocReport doActionTaken(ActionTakenEvent arg0) throws Exception {
77 return new ProcessDocReport(true, "");
78 }
79
80
81
82
83 @Override
84 public ProcessDocReport doDeleteRouteHeader(DeleteEvent arg0) throws Exception {
85 return new ProcessDocReport(true, "");
86 }
87
88
89
90
91 @Override
92 public ProcessDocReport doRouteLevelChange(DocumentRouteLevelChange arg0) throws Exception {
93 return new ProcessDocReport(true, "");
94 }
95
96
97
98
99
100
101 @Override
102 public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange arg0) throws Exception {
103 LOG.debug("ENTERING NotificationSenderFormPostProcessor.doRouteStatusChange() for Notification Sender Form with document ID: " + arg0.getDocumentId());
104
105 if(arg0.getNewRouteStatus().equals(KewApiConstants.ROUTE_HEADER_PROCESSED_CD)) {
106 LOG.debug("Workflow status has changed to RESOLVED for Notification Sender Form with document ID: " + arg0.getDocumentId() +
107 ". We are now calling the NotificationService.sendNotification() service.");
108
109
110
111 String proxyUserId = Util.getNotificationSystemUser();
112
113
114 WorkflowDocument document;
115 try {
116 document = NotificationWorkflowDocument.loadNotificationDocument(proxyUserId, arg0.getDocumentId());
117
118 LOG.debug("XML:" + document.getApplicationContent());
119
120
121 Notification notification = messageContentService.parseSerializedNotificationXml(document.getApplicationContent().getBytes());
122
123 LOG.debug("Notification Content: " + notification.getContent());
124
125
126 notificationService.sendNotification(notification);
127
128 LOG.debug("NotificationService.sendNotification() was successfully called for Notification Sender Form with document ID: " + arg0.getDocumentId());
129 } catch(Exception e) {
130 throw new RuntimeException(e);
131 }
132 }
133
134 LOG.debug("LEAVING NotificationSenderFormPostProcessor.doRouteStatusChange() for Notification Sender Form with document ID: " + arg0.getDocumentId());
135 return new ProcessDocReport(true, "");
136 }
137
138
139
140
141 @Override
142 public ProcessDocReport beforeProcess(BeforeProcessEvent beforeProcessEvent) throws Exception {
143 return new ProcessDocReport(true, "");
144 }
145
146
147
148
149 @Override
150 public ProcessDocReport afterProcess(AfterProcessEvent afterProcessEvent) throws Exception {
151 return new ProcessDocReport(true, "");
152 }
153
154
155
156
157 @Override
158 public List<String> getDocumentIdsToLock(DocumentLockingEvent documentLockingEvent) throws Exception {
159 return null;
160 }
161
162 }