View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  
39  import java.util.List;
40  
41  
42  /**
43   * This class is the post processor that gets run when the general notification 
44   * message sending form is approved by its reviewers.
45   * @author Kuali Rice Team (rice.collab@kuali.org)
46   */
47  public class NotificationSenderFormPostProcessor implements PostProcessor {
48      private static final Logger LOG = Logger.getLogger(NotificationSenderFormPostProcessor.class);
49      
50      NotificationService notificationService;
51      GenericDao businessObjectDao;
52      NotificationMessageContentService messageContentService;
53      
54      /**
55       * Constructs a NotificationSenderFormPostProcessor instance.
56       */
57      public NotificationSenderFormPostProcessor() {
58          this.notificationService = GlobalNotificationServiceLocator.getInstance().getNotificationService();
59          this.businessObjectDao = GlobalNotificationServiceLocator.getInstance().getGenericDao();
60          this.messageContentService = GlobalNotificationServiceLocator.getInstance().getNotificationMessageContentService();
61      }
62  
63      /**
64       * Constructs a NotificationSenderFormPostProcessor instance.
65       * @param notificationService
66       * @param businessObjectDao
67       */
68      public NotificationSenderFormPostProcessor(NotificationService notificationService, GenericDao businessObjectDao) {
69          this.notificationService = notificationService;
70          this.businessObjectDao = businessObjectDao;
71      }
72      
73      /**
74       * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#doActionTaken(org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent)
75       */
76      @Override
77      public ProcessDocReport doActionTaken(ActionTakenEvent arg0) throws Exception {
78  	    return new ProcessDocReport(true, "");
79      }
80  
81      /**
82       * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#afterActionTaken(org.kuali.rice.kew.api.action.ActionType, org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent)
83       */
84      @Override
85      public ProcessDocReport afterActionTaken(ActionType performed, ActionTakenEvent event) throws Exception {
86          return new ProcessDocReport(true, "");
87      }
88  
89      /**
90       * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#doDeleteRouteHeader(org.kuali.rice.kew.framework.postprocessor.DeleteEvent)
91       */
92      @Override
93      public ProcessDocReport doDeleteRouteHeader(DeleteEvent arg0) throws Exception {
94  	    return new ProcessDocReport(true, "");
95      }
96  
97      /**
98       * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#doRouteLevelChange(org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange)
99       */
100     @Override
101     public ProcessDocReport doRouteLevelChange(DocumentRouteLevelChange arg0) throws Exception {
102 	    return new ProcessDocReport(true, "");
103     }
104 
105     /**
106      * When the EDL simple message sending form is submitted, it is routed straight to FINAL and at that time (when RESOLVED), we 
107      * actually send the notification.
108      * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#doRouteStatusChange(org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange)
109      */
110     @Override
111     public ProcessDocReport doRouteStatusChange(DocumentRouteStatusChange arg0) throws Exception {
112         LOG.debug("ENTERING NotificationSenderFormPostProcessor.doRouteStatusChange() for Notification Sender Form with document ID: " + arg0.getDocumentId());
113 
114         if(arg0.getNewRouteStatus().equals(KewApiConstants.ROUTE_HEADER_PROCESSED_CD)) {
115             LOG.debug("Workflow status has changed to RESOLVED for Notification Sender Form with document ID: " + arg0.getDocumentId() +
116                 ".  We are now calling the NotificationService.sendNotification() service.");
117 
118             // obtain a workflow user object first
119             //NetworkIdDTO proxyUser = new NetworkIdDTO(Util.getNotificationSystemUser());
120             String proxyUserId = Util.getNotificationSystemUser();
121 
122             // now construct the workflow document, which will interact with workflow
123             WorkflowDocument document;
124             try {
125             document = NotificationWorkflowDocument.loadNotificationDocument(proxyUserId, arg0.getDocumentId());
126 
127             LOG.debug("XML:" + document.getApplicationContent());
128 
129             //parse out the application content into a Notification BO
130                     NotificationBo notification = messageContentService.parseSerializedNotificationXml(document.getApplicationContent().getBytes());
131 
132                     LOG.debug("Notification Content: " + notification.getContent());
133 
134                     // send the notification
135                     notificationService.sendNotification(notification);
136 
137                     LOG.debug("NotificationService.sendNotification() was successfully called for Notification Sender Form with document ID: " + arg0.getDocumentId());
138             } catch(Exception e) {
139             throw new RuntimeException(e);
140             }
141         }
142 
143         LOG.debug("LEAVING NotificationSenderFormPostProcessor.doRouteStatusChange() for Notification Sender Form with document ID: " + arg0.getDocumentId());
144         return new ProcessDocReport(true, "");
145     }
146 
147     /**
148      * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#beforeProcess(org.kuali.rice.kew.framework.postprocessor.BeforeProcessEvent)
149      */
150     @Override
151     public ProcessDocReport beforeProcess(BeforeProcessEvent beforeProcessEvent) throws Exception {
152         return new ProcessDocReport(true, "");
153     }
154 
155     /**
156      * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#afterProcess(org.kuali.rice.kew.framework.postprocessor.AfterProcessEvent)
157      */
158     @Override
159     public ProcessDocReport afterProcess(AfterProcessEvent afterProcessEvent) throws Exception {
160         return new ProcessDocReport(true, "");
161     }
162     
163     /**
164      * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#getDocumentIdsToLock(org.kuali.rice.kew.framework.postprocessor.DocumentLockingEvent)
165      */
166     @Override
167 	public List<String> getDocumentIdsToLock(DocumentLockingEvent documentLockingEvent) throws Exception {
168 		return null;
169 	}
170 	
171 }