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