Coverage Report - org.kuali.rice.ken.postprocessor.kew.NotificationPostProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
NotificationPostProcessor
0%
0/42
0%
0/12
2.5
 
 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.io.ByteArrayInputStream;
 19  
 import java.io.IOException;
 20  
 import java.rmi.RemoteException;
 21  
 import java.util.Properties;
 22  
 
 23  
 import org.apache.log4j.Logger;
 24  
 import org.kuali.rice.ken.bo.NotificationMessageDelivery;
 25  
 import org.kuali.rice.ken.core.GlobalNotificationServiceLocator;
 26  
 import org.kuali.rice.ken.deliverer.impl.KEWActionListMessageDeliverer;
 27  
 import org.kuali.rice.ken.service.NotificationMessageDeliveryService;
 28  
 import org.kuali.rice.ken.service.NotificationService;
 29  
 import org.kuali.rice.ken.util.NotificationConstants;
 30  
 import org.kuali.rice.ken.util.Util;
 31  
 import org.kuali.rice.kew.api.WorkflowDocument;
 32  
 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
 33  
 import org.kuali.rice.kew.dto.ActionTakenEventDTO;
 34  
 import org.kuali.rice.kew.dto.AfterProcessEventDTO;
 35  
 import org.kuali.rice.kew.dto.BeforeProcessEventDTO;
 36  
 import org.kuali.rice.kew.dto.DeleteEventDTO;
 37  
 import org.kuali.rice.kew.dto.DocumentLockingEventDTO;
 38  
 import org.kuali.rice.kew.dto.DocumentRouteLevelChangeDTO;
 39  
 import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO;
 40  
 import org.kuali.rice.kew.postprocessor.PostProcessorRemote;
 41  
 import org.kuali.rice.kew.util.KEWConstants;
 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  0
         WorkflowDocument doc = WorkflowDocumentFactory.loadDocument(event.getActionTaken().getPrincipalId(), event.getDocumentId());
 84  
         try {
 85  0
             p.load(new ByteArrayInputStream(doc.getAttributeContent().getBytes()));
 86  0
         } catch (IOException ioe) {
 87  0
             throw new RuntimeException(ioe);
 88  0
         }
 89  0
         String internalCommand = p.getProperty(KEWActionListMessageDeliverer.INTERNAL_COMMAND_FLAG);
 90  
 
 91  0
         if (Boolean.valueOf(internalCommand)) {
 92  0
             LOG.info("Internal command detected by NotificationPostProcessor - will not invoke KEN");
 93  0
             return true;
 94  
         }
 95  
         
 96  0
         LOG.info("NotificationPostProcessor detected end-user action " + event.getActionTaken().getActionTaken() + " on document " + event.getActionTaken().getDocumentId());
 97  
 
 98  0
         if(actionTakenCode.equals(KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD) || actionTakenCode.equals(KEWConstants.ACTION_TAKEN_FYI_CD)) {
 99  0
             LOG.debug("User has taken either acknowledge or fy action (action code=" + actionTakenCode + 
 100  
                     ") for Notification action item with document ID: " + event.getDocumentId() + 
 101  
             ".  We are now changing the status of the associated NotificationMessageDelivery to REMOVED.");
 102  
 
 103  
             try {
 104  0
                 NotificationMessageDelivery nmd = msgDeliverySvc.getNotificationMessageDeliveryByDelivererId(event.getDocumentId());
 105  
 
 106  0
                 if (nmd == null) {
 107  0
                     throw new RuntimeException("Could not find message delivery from workflow document " + event.getDocumentId() + " to dismiss");
 108  
                 }
 109  
 
 110  
                 //get the id of the associated notification message delivery record
 111  
                 String cause;
 112  0
                 if (KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD.equals(actionTakenCode)) {
 113  0
                     cause = NotificationConstants.ACK_CAUSE;
 114  0
                 } else if (KEWConstants.ACTION_TAKEN_FYI_CD.equals(actionTakenCode)) {
 115  0
                     cause = NotificationConstants.FYI_CAUSE;
 116  
                 } else {
 117  0
                     cause = "unknown";
 118  
                 }
 119  
 
 120  0
                 LOG.info("Dismissing message id " + nmd.getId() + " due to cause: " + cause);
 121  0
                 notificationService.dismissNotificationMessageDelivery(nmd.getId(),
 122  
                         Util.getNotificationSystemUser(),
 123  
                         cause);
 124  0
             } catch(Exception e) {
 125  0
                 throw new RuntimeException("Error dismissing message", e);
 126  0
             }
 127  
         }
 128  
 
 129  0
         LOG.debug("LEAVING NotificationPostProcessor.doActionTaken() for Notification action item with document ID: " + event.getDocumentId());
 130  0
         return true;
 131  
     }
 132  
 
 133  
     /**
 134  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#doDeleteRouteHeader(org.kuali.rice.kew.dto.DeleteEventDTO)
 135  
      */
 136  
     public boolean doDeleteRouteHeader(DeleteEventDTO arg0) throws RemoteException {
 137  0
         return true;
 138  
     }
 139  
 
 140  
     /**
 141  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#doRouteLevelChange(org.kuali.rice.kew.dto.DocumentRouteLevelChangeDTO)
 142  
      */
 143  
     public boolean doRouteLevelChange(DocumentRouteLevelChangeDTO arg0) throws RemoteException {
 144  0
         return true;
 145  
     }
 146  
 
 147  
     /**
 148  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#doRouteStatusChange(org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO)
 149  
      */
 150  
     public boolean doRouteStatusChange(DocumentRouteStatusChangeDTO arg0) throws RemoteException {
 151  0
         return true;
 152  
     }
 153  
 
 154  
     /**
 155  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#beforeProcess(org.kuali.rice.kew.dto.BeforeProcessEventDTO)
 156  
      */
 157  
     public boolean beforeProcess(BeforeProcessEventDTO beforeProcessEvent) throws Exception {
 158  0
         return true;
 159  
     }
 160  
 
 161  
     /**
 162  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#afterProcess(org.kuali.rice.kew.dto.AfterProcessEventDTO)
 163  
      */
 164  
     public boolean afterProcess(AfterProcessEventDTO afterProcessEvent) throws Exception {
 165  0
         return true;
 166  
     }
 167  
 
 168  
     /**
 169  
      * @see org.kuali.rice.kew.postprocessor.PostProcessorRemote#getDocumentIdsToLock(org.kuali.rice.kew.dto.DocumentLockingEventDTO)
 170  
      */
 171  
         public String[] getDocumentIdsToLock(DocumentLockingEventDTO documentLockingEvent) throws Exception {
 172  0
                 return null;
 173  
         }
 174  
     
 175  
     
 176  
     
 177  
     
 178  
 }