Coverage Report - org.kuali.rice.kcb.quartz.MessageDeletionListener
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageDeletionListener
0%
0/25
0%
0/8
2.5
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.kcb.quartz;
 17  
 
 18  
 import java.util.Collection;
 19  
 
 20  
 import org.apache.log4j.Logger;
 21  
 import org.kuali.rice.kcb.bo.Message;
 22  
 import org.kuali.rice.kcb.bo.MessageDelivery;
 23  
 import org.kuali.rice.kcb.quartz.MessageProcessingJob.Mode;
 24  
 import org.kuali.rice.kcb.service.GlobalKCBServiceLocator;
 25  
 import org.kuali.rice.kcb.service.MessageDeliveryService;
 26  
 import org.kuali.rice.kcb.service.MessageService;
 27  
 import org.quartz.JobExecutionContext;
 28  
 import org.quartz.JobExecutionException;
 29  
 import org.quartz.JobListener;
 30  
 
 31  
 /**
 32  
  * Listener that takes care of deleting removed messages 
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  *
 36  
  */
 37  0
 public class MessageDeletionListener implements JobListener {
 38  
     public static final String NAME = "MessageDeletionListener";
 39  
 
 40  0
     private static final Logger LOG = Logger.getLogger(MessageDeletionListener.class);
 41  
  
 42  
 
 43  
     /**
 44  
      * @see org.quartz.JobListener#getName()
 45  
      */
 46  
     public String getName() {
 47  0
         return NAME;
 48  
     }
 49  
 
 50  
     /**
 51  
      * @see org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext)
 52  
      */
 53  
     public void jobExecutionVetoed(JobExecutionContext arg0) {
 54  0
     }
 55  
 
 56  
     /**
 57  
      * @see org.quartz.JobListener#jobToBeExecuted(org.quartz.JobExecutionContext)
 58  
      */
 59  
     public void jobToBeExecuted(JobExecutionContext arg0) {
 60  0
     }
 61  
 
 62  
     /**
 63  
      * @see org.quartz.JobListener#jobWasExecuted(org.quartz.JobExecutionContext, org.quartz.JobExecutionException)
 64  
      */
 65  
     public void jobWasExecuted(JobExecutionContext context, JobExecutionException exception) {
 66  0
         if (exception != null) {
 67  0
             LOG.error("Exception occurred in DeliveryJob, not acting", exception);
 68  0
             return;
 69  
         }
 70  
         
 71  0
         long messageId = context.getMergedJobDataMap().getLong("messageId");
 72  0
         LOG.debug("Handling message " + messageId);
 73  0
         Mode mode = Mode.valueOf(context.getMergedJobDataMap().getString("mode"));
 74  
         //if (Mode.REMOVE == mode) {
 75  0
             MessageService ms = GlobalKCBServiceLocator.getInstance().getMessageService();
 76  0
             Message m = ms.getMessage(messageId);
 77  
             
 78  0
             if (m == null) {
 79  
                 // this can happen in unit tests, or if for some other reason the message goes away before this listener
 80  
                 // is called
 81  0
                 LOG.warn("Called for invalid message: " + messageId);
 82  0
                 return;
 83  
             }
 84  0
             MessageDeliveryService mds = GlobalKCBServiceLocator.getInstance().getMessageDeliveryService(); 
 85  0
             Collection<MessageDelivery> c = mds.getMessageDeliveries(m);
 86  0
             if (c.size() == 0) {
 87  0
                 LOG.debug("Deleting message " + m);
 88  0
                 ms.deleteMessage(m);
 89  
             } else {
 90  0
                 LOG.debug("Message " + m.getId() + " has " + c.size() + " deliveries");
 91  0
                 for (MessageDelivery md: c) {
 92  0
                     LOG.debug(md);
 93  
                 }
 94  
             }
 95  
         //}
 96  0
     }
 97  
 }