Coverage Report - org.kuali.rice.ken.postprocessor.kew.NotificationPostProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
NotificationPostProcessor
0%
0/45
0%
0/12
2.75
 
 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 org.apache.log4j.Logger;
 19  
 import org.kuali.rice.ken.bo.NotificationMessageDelivery;
 20  
 import org.kuali.rice.ken.core.GlobalNotificationServiceLocator;
 21  
 import org.kuali.rice.ken.deliverer.impl.KEWActionListMessageDeliverer;
 22  
 import org.kuali.rice.ken.service.NotificationMessageDeliveryService;
 23  
 import org.kuali.rice.ken.service.NotificationService;
 24  
 import org.kuali.rice.ken.util.NotificationConstants;
 25  
 import org.kuali.rice.ken.util.Util;
 26  
 import org.kuali.rice.kew.dto.ActionTakenEventDTO;
 27  
 import org.kuali.rice.kew.dto.AfterProcessEventDTO;
 28  
 import org.kuali.rice.kew.dto.BeforeProcessEventDTO;
 29  
 import org.kuali.rice.kew.dto.DeleteEventDTO;
 30  
 import org.kuali.rice.kew.dto.DocumentLockingEventDTO;
 31  
 import org.kuali.rice.kew.dto.DocumentRouteLevelChangeDTO;
 32  
 import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO;
 33  
 import org.kuali.rice.kew.exception.WorkflowException;
 34  
 import org.kuali.rice.kew.postprocessor.PostProcessorRemote;
 35  
 import org.kuali.rice.kew.service.WorkflowDocument;
 36  
 import org.kuali.rice.kew.util.KEWConstants;
 37  
 
 38  
 import java.io.ByteArrayInputStream;
 39  
 import java.io.IOException;
 40  
 import java.rmi.RemoteException;
 41  
 import java.util.Properties;
 42  
 
 43  
 
 44  
 /**
 45  
  * This class is the post processor that gets run when workflow state changes occur for the 
 46  
  * underlying core NotificationDocumentType that all notifications go into KEW as.  This class is responsible for changing 
 47  
  * the state of the associated notification message delivery record after someone FYIs or ACKs their notification 
 48  
  * in the KEW Action List.
 49  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 50  
  */
 51  
 public class NotificationPostProcessor implements PostProcessorRemote {
 52  0
     private static final Logger LOG = Logger.getLogger(NotificationPostProcessor.class);
 53  
 
 54  
     NotificationService notificationService;
 55  
     NotificationMessageDeliveryService msgDeliverySvc;
 56  
 
 57  
     /**
 58  
      * Constructs a NotificationPostProcessor instance.
 59  
      */
 60  0
     public NotificationPostProcessor() {
 61  0
         this.msgDeliverySvc = GlobalNotificationServiceLocator.getInstance().getNotificationMessageDeliveryService();
 62  0
         this.notificationService = GlobalNotificationServiceLocator.getInstance().getNotificationService();
 63  0
     }
 64  
 
 65  
     /**
 66  
      * Need to intercept ACKNOWLEDGE or FYI actions taken on notification workflow documents and set the local state of the 
 67  
      * Notification to REMOVED as well.
 68  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#doActionTaken(org.kuali.rice.kew.dto.ActionTakenEventDTO)
 69  
      */
 70  
     public boolean doActionTaken(ActionTakenEventDTO event) throws RemoteException {
 71  0
         LOG.debug("ENTERING NotificationPostProcessor.doActionTaken() for Notification action item with document ID: " + event.getDocumentId());
 72  
 
 73  
         // NOTE: this action could be happening because the user initiated it via KEW, OR because a dismiss or autoremove action
 74  
         // has been invoked programmatically and the KEWActionListMessageDeliverer is taking an action...so there is a risk of being
 75  
         // invoked recursively (which will lead to locking issues and other problems).  We therefore mark the document in the KEWActionList
 76  
         // MessageDeliverer before performing an action, so that we can detect this scenario here, and avoid invoking KEN again.
 77  
 
 78  0
         LOG.debug("ACTION TAKEN=" + event.getActionTaken().getActionTaken());
 79  
 
 80  0
         String actionTakenCode = event.getActionTaken().getActionTaken();
 81  
 
 82  0
         Properties p = new Properties();
 83  
         WorkflowDocument doc;
 84  
         try {
 85  0
                 doc = WorkflowDocument.loadDocument(event.getActionTaken().getPrincipalId(), event.getDocumentId());
 86  0
         } catch (WorkflowException we) {
 87  0
             throw new RuntimeException("Could not create document", we);
 88  0
         }
 89  
         try {
 90  0
             p.load(new ByteArrayInputStream(doc.getAttributeContent().getBytes()));
 91  0
         } catch (IOException ioe) {
 92  0
             throw new RuntimeException(ioe);
 93  0
         }
 94  0
         String internalCommand = p.getProperty(KEWActionListMessageDeliverer.INTERNAL_COMMAND_FLAG);
 95  
 
 96  0
         if (Boolean.valueOf(internalCommand)) {
 97  0
             LOG.info("Internal command detected by NotificationPostProcessor - will not invoke KEN");
 98  0
             return true;
 99  
         }
 100  
         
 101  0
         LOG.info("NotificationPostProcessor detected end-user action " + event.getActionTaken().getActionTaken() + " on document " + event.getActionTaken().getDocumentId());
 102  
 
 103  0
         if(actionTakenCode.equals(KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD) || actionTakenCode.equals(KEWConstants.ACTION_TAKEN_FYI_CD)) {
 104  0
             LOG.debug("User has taken either acknowledge or fy action (action code=" + actionTakenCode + 
 105  
                     ") for Notification action item with document ID: " + event.getDocumentId() + 
 106  
             ".  We are now changing the status of the associated NotificationMessageDelivery to REMOVED.");
 107  
 
 108  
             try {
 109  0
                 NotificationMessageDelivery nmd = msgDeliverySvc.getNotificationMessageDeliveryByDelivererId(event.getDocumentId());
 110  
 
 111  0
                 if (nmd == null) {
 112  0
                     throw new RuntimeException("Could not find message delivery from workflow document " + event.getDocumentId() + " to dismiss");
 113  
                 }
 114  
 
 115  
                 //get the id of the associated notification message delivery record
 116  
                 String cause;
 117  0
                 if (KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD.equals(actionTakenCode)) {
 118  0
                     cause = NotificationConstants.ACK_CAUSE;
 119  0
                 } else if (KEWConstants.ACTION_TAKEN_FYI_CD.equals(actionTakenCode)) {
 120  0
                     cause = NotificationConstants.FYI_CAUSE;
 121  
                 } else {
 122  0
                     cause = "unknown";
 123  
                 }
 124  
 
 125  0
                 LOG.info("Dismissing message id " + nmd.getId() + " due to cause: " + cause);
 126  0
                 notificationService.dismissNotificationMessageDelivery(nmd.getId(),
 127  
                         Util.getNotificationSystemUser(),
 128  
                         cause);
 129  0
             } catch(Exception e) {
 130  0
                 throw new RuntimeException("Error dismissing message", e);
 131  0
             }
 132  
         }
 133  
 
 134  0
         LOG.debug("LEAVING NotificationPostProcessor.doActionTaken() for Notification action item with document ID: " + event.getDocumentId());
 135  0
         return true;
 136  
     }
 137  
 
 138  
     /**
 139  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#doDeleteRouteHeader(org.kuali.rice.kew.dto.DeleteEventDTO)
 140  
      */
 141  
     public boolean doDeleteRouteHeader(DeleteEventDTO arg0) throws RemoteException {
 142  0
         return true;
 143  
     }
 144  
 
 145  
     /**
 146  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#doRouteLevelChange(org.kuali.rice.kew.dto.DocumentRouteLevelChangeDTO)
 147  
      */
 148  
     public boolean doRouteLevelChange(DocumentRouteLevelChangeDTO arg0) throws RemoteException {
 149  0
         return true;
 150  
     }
 151  
 
 152  
     /**
 153  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#doRouteStatusChange(org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO)
 154  
      */
 155  
     public boolean doRouteStatusChange(DocumentRouteStatusChangeDTO arg0) throws RemoteException {
 156  0
         return true;
 157  
     }
 158  
 
 159  
     /**
 160  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#beforeProcess(org.kuali.rice.kew.dto.BeforeProcessEventDTO)
 161  
      */
 162  
     public boolean beforeProcess(BeforeProcessEventDTO beforeProcessEvent) throws Exception {
 163  0
         return true;
 164  
     }
 165  
 
 166  
     /**
 167  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#afterProcess(org.kuali.rice.kew.dto.AfterProcessEventDTO)
 168  
      */
 169  
     public boolean afterProcess(AfterProcessEventDTO afterProcessEvent) throws Exception {
 170  0
         return true;
 171  
     }
 172  
 
 173  
     /**
 174  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#getDocumentIdsToLock(org.kuali.rice.kew.dto.DocumentLockingEventDTO)
 175  
      */
 176  
         public String[] getDocumentIdsToLock(DocumentLockingEventDTO documentLockingEvent) throws Exception {
 177  0
                 return null;
 178  
         }
 179  
     
 180  
     
 181  
     
 182  
     
 183  
 }