View Javadoc

1   /**
2    * Copyright 2005-2012 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.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   * This class is the post processor that gets run when the general notification 
43   * message sending form is approved by its reviewers.
44   * @author Kuali Rice Team (rice.collab@kuali.org)
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       * Constructs a NotificationSenderFormPostProcessor instance.
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       * Constructs a NotificationSenderFormPostProcessor instance.
64       * @param notificationService
65       * @param businessObjectDao
66       */
67      public NotificationSenderFormPostProcessor(NotificationService notificationService, GenericDao businessObjectDao) {
68          this.notificationService = notificationService;
69          this.businessObjectDao = businessObjectDao;
70      }
71      
72      /**
73       * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#doActionTaken(org.kuali.rice.kew.framework.postprocessor.ActionTakenEvent)
74       */
75      @Override
76      public ProcessDocReport doActionTaken(ActionTakenEvent arg0) throws Exception {
77  	    return new ProcessDocReport(true, "");
78      }
79  
80      /**
81       * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#doDeleteRouteHeader(org.kuali.rice.kew.framework.postprocessor.DeleteEvent)
82       */
83      @Override
84      public ProcessDocReport doDeleteRouteHeader(DeleteEvent arg0) throws Exception {
85  	    return new ProcessDocReport(true, "");
86      }
87  
88      /**
89       * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#doRouteLevelChange(org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange)
90       */
91      @Override
92      public ProcessDocReport doRouteLevelChange(DocumentRouteLevelChange arg0) throws Exception {
93  	    return new ProcessDocReport(true, "");
94      }
95  
96      /**
97       * When the EDL simple message sending form is submitted, it is routed straight to FINAL and at that time (when RESOLVED), we 
98       * actually send the notification.
99       * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#doRouteStatusChange(org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange)
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             // obtain a workflow user object first
110             //NetworkIdDTO proxyUser = new NetworkIdDTO(Util.getNotificationSystemUser());
111             String proxyUserId = Util.getNotificationSystemUser();
112 
113             // now construct the workflow document, which will interact with workflow
114             WorkflowDocument document;
115             try {
116             document = NotificationWorkflowDocument.loadNotificationDocument(proxyUserId, arg0.getDocumentId());
117 
118             LOG.debug("XML:" + document.getApplicationContent());
119 
120             //parse out the application content into a Notification BO
121                     Notification notification = messageContentService.parseSerializedNotificationXml(document.getApplicationContent().getBytes());
122 
123                     LOG.debug("Notification Content: " + notification.getContent());
124 
125                     // send the notification
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      * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#beforeProcess(org.kuali.rice.kew.framework.postprocessor.BeforeProcessEvent)
140      */
141     @Override
142     public ProcessDocReport beforeProcess(BeforeProcessEvent beforeProcessEvent) throws Exception {
143         return new ProcessDocReport(true, "");
144     }
145 
146     /**
147      * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#afterProcess(org.kuali.rice.kew.framework.postprocessor.AfterProcessEvent)
148      */
149     @Override
150     public ProcessDocReport afterProcess(AfterProcessEvent afterProcessEvent) throws Exception {
151         return new ProcessDocReport(true, "");
152     }
153     
154     /**
155      * @see org.kuali.rice.kew.framework.postprocessor.PostProcessor#getDocumentIdsToLock(org.kuali.rice.kew.framework.postprocessor.DocumentLockingEvent)
156      */
157     @Override
158 	public List<String> getDocumentIdsToLock(DocumentLockingEvent documentLockingEvent) throws Exception {
159 		return null;
160 	}
161 	
162 }