View Javadoc

1   /*
2    * Copyright 2007 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 java.rmi.RemoteException;
19  
20  import org.apache.log4j.Logger;
21  import org.kuali.rice.core.dao.GenericDao;
22  import org.kuali.rice.ken.bo.Notification;
23  import org.kuali.rice.ken.core.GlobalNotificationServiceLocator;
24  import org.kuali.rice.ken.document.kew.NotificationWorkflowDocument;
25  import org.kuali.rice.ken.service.NotificationMessageContentService;
26  import org.kuali.rice.ken.service.NotificationService;
27  import org.kuali.rice.ken.util.Util;
28  import org.kuali.rice.kew.dto.ActionTakenEventDTO;
29  import org.kuali.rice.kew.dto.AfterProcessEventDTO;
30  import org.kuali.rice.kew.dto.BeforeProcessEventDTO;
31  import org.kuali.rice.kew.dto.DeleteEventDTO;
32  import org.kuali.rice.kew.dto.DocumentLockingEventDTO;
33  import org.kuali.rice.kew.dto.DocumentRouteLevelChangeDTO;
34  import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO;
35  import org.kuali.rice.kew.dto.NetworkIdDTO;
36  import org.kuali.rice.kew.postprocessor.PostProcessorRemote;
37  import org.kuali.rice.kew.util.KEWConstants;
38  
39  
40  /**
41   * This class is the post processor that gets run when the general notification 
42   * message sending form is approved by its reviewers.
43   * @author Kuali Rice Team (rice.collab@kuali.org)
44   */
45  public class NotificationSenderFormPostProcessor implements PostProcessorRemote {
46      private static final Logger LOG = Logger.getLogger(NotificationSenderFormPostProcessor.class);
47      
48      NotificationService notificationService;
49      GenericDao businessObjectDao;
50      NotificationMessageContentService messageContentService;
51      
52      /**
53       * Constructs a NotificationSenderFormPostProcessor instance.
54       */
55      public NotificationSenderFormPostProcessor() {
56  	this.notificationService = GlobalNotificationServiceLocator.getInstance().getNotificationService();
57  	this.businessObjectDao = GlobalNotificationServiceLocator.getInstance().getGenericDao();
58  	this.messageContentService = GlobalNotificationServiceLocator.getInstance().getNotificationMessageContentService();
59      }
60  
61      /**
62       * Constructs a NotificationSenderFormPostProcessor instance.
63       * @param notificationService
64       * @param businessObjectDao
65       */
66      public NotificationSenderFormPostProcessor(NotificationService notificationService, GenericDao businessObjectDao) {
67  	this.notificationService = notificationService;
68  	this.businessObjectDao = businessObjectDao;
69      }
70      
71      /**
72       * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#doActionTaken(org.kuali.rice.kew.dto.ActionTakenEventDTO)
73       */
74      public boolean doActionTaken(ActionTakenEventDTO arg0) throws RemoteException {
75  	return true;
76      }
77  
78      /**
79       * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#doDeleteRouteHeader(org.kuali.rice.kew.dto.DeleteEventDTO)
80       */
81      public boolean doDeleteRouteHeader(DeleteEventDTO arg0) throws RemoteException {
82  	return true;
83      }
84  
85      /**
86       * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#doRouteLevelChange(org.kuali.rice.kew.dto.DocumentRouteLevelChangeDTO)
87       */
88      public boolean doRouteLevelChange(DocumentRouteLevelChangeDTO arg0) throws RemoteException {
89  	return true;
90      }
91  
92      /**
93       * When the EDL simple message sending form is submitted, it is routed straight to FINAL and at that time (when RESOLVED), we 
94       * actually send the notification.
95       * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#doRouteStatusChange(org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO)
96       */
97      public boolean doRouteStatusChange(DocumentRouteStatusChangeDTO arg0) throws RemoteException {
98  	LOG.debug("ENTERING NotificationSenderFormPostProcessor.doRouteStatusChange() for Notification Sender Form with route header ID: " + arg0.getRouteHeaderId());
99  	
100 	if(arg0.getNewRouteStatus().equals(KEWConstants.ROUTE_HEADER_PROCESSED_CD)) {
101 	    LOG.debug("Workflow status has changed to RESOLVED for Notification Sender Form with route header ID: " + arg0.getRouteHeaderId() + 
102 		    ".  We are now calling the NotificationService.sendNotification() service.");
103 	    
104 	    // obtain a workflow user object first
105 	    NetworkIdDTO proxyUser = new NetworkIdDTO(Util.getNotificationSystemUser());
106 	        
107 	    // now construct the workflow document, which will interact with workflow
108 	    NotificationWorkflowDocument document;
109 	    try {	
110 		document = new NotificationWorkflowDocument(proxyUser, arg0.getRouteHeaderId());
111 		
112 		LOG.debug("XML:" + document.getApplicationContent());
113 		
114 		//parse out the application content into a Notification BO
115                 Notification notification = messageContentService.parseSerializedNotificationXml(document.getApplicationContent().getBytes());
116                 
117                 LOG.debug("Notification Content: " + notification.getContent());
118                 
119                 // send the notification
120                 notificationService.sendNotification(notification);
121                 
122                 LOG.debug("NotificationService.sendNotification() was successfully called for Notification Sender Form with route header ID: " + arg0.getRouteHeaderId());
123 	    } catch(Exception e) {
124 		throw new RuntimeException(e);
125 	    }
126 	}
127 	
128 	LOG.debug("LEAVING NotificationSenderFormPostProcessor.doRouteStatusChange() for Notification Sender Form with route header ID: " + arg0.getRouteHeaderId());
129 	return true;
130     }
131 
132     /**
133      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#beforeProcess(org.kuali.rice.kew.dto.BeforeProcessEventDTO)
134      */
135     public boolean beforeProcess(BeforeProcessEventDTO beforeProcessEvent) throws Exception {
136         return true;
137     }
138 
139     /**
140      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#afterProcess(org.kuali.rice.kew.dto.AfterProcessEventDTO)
141      */
142     public boolean afterProcess(AfterProcessEventDTO afterProcessEvent) throws Exception {
143         return true;
144     }
145     
146     /**
147      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#getDocumentIdsToLock(org.kuali.rice.kew.dto.DocumentLockingEventDTO)
148      */
149 	public Long[] getDocumentIdsToLock(DocumentLockingEventDTO documentLockingEvent) throws Exception {
150 		return null;
151 	}
152 	
153 }