Coverage Report - org.mule.module.atom.routing.EntryLastUpdatedFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
EntryLastUpdatedFilter
0%
0/32
0%
0/18
2.571
 
 1  
 /*
 2  
  * $Id: EntryLastUpdatedFilter.java 19980 2010-10-21 11:27:14Z rossmason $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 package org.mule.module.atom.routing;
 11  
 
 12  
 import org.mule.api.MuleMessage;
 13  
 import org.mule.api.routing.filter.Filter;
 14  
 
 15  
 import java.util.Date;
 16  
 
 17  
 import org.apache.abdera.model.Entry;
 18  
 import org.apache.commons.logging.Log;
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 
 21  
 /**
 22  
  * Will filter entries in an atom feed based on the lasted Edited date, falling back to the
 23  
  * published date if the edit date was not set
 24  
  */
 25  
 public class EntryLastUpdatedFilter implements Filter
 26  
 {
 27  
     /**
 28  
      * logger used by this class
 29  
      */
 30  0
     private final transient Log logger = LogFactory.getLog(EntryLastUpdatedFilter.class);
 31  
     private Date lastUpdate;
 32  
 
 33  0
     private boolean acceptWithoutUpdateDate = true;
 34  
 
 35  
     public EntryLastUpdatedFilter()
 36  0
     {
 37  0
     }
 38  
 
 39  
     public EntryLastUpdatedFilter(Date lastUpdate)
 40  0
     {
 41  0
         this.lastUpdate = lastUpdate;
 42  0
     }
 43  
 
 44  
     public boolean accept(MuleMessage message)
 45  
     {
 46  0
         Entry entry = (Entry) message.getPayload();
 47  0
         Date updated = entry.getEdited();
 48  0
         if (updated == null)
 49  
         {
 50  0
             updated = entry.getPublished();
 51  0
             if (updated == null)
 52  
             {
 53  0
                 if (isAcceptWithoutUpdateDate())
 54  
                 {
 55  0
                     if (logger.isDebugEnabled())
 56  
                     {
 57  0
                         logger.debug("Entry does not have a last updated or published date set, assuming the feed should be processed");
 58  
                     }
 59  0
                     return true;
 60  
                 }
 61  
                 else
 62  
                 {
 63  0
                     if (logger.isWarnEnabled())
 64  
                     {
 65  0
                         logger.warn("Entry does not have a last updated or published date set, not consuming the feed because 'acceptWithoutUpdateDate' is false");
 66  
                     }
 67  0
                     return false;
 68  
                 }
 69  
             }
 70  
         }
 71  0
         if (lastUpdate != null)
 72  
         {
 73  0
             if (lastUpdate.after(updated) || lastUpdate.equals(updated))
 74  
             {
 75  0
                 if (logger.isDebugEnabled())
 76  
                 {
 77  0
                     logger.debug("Feed update is not newer than the last update, not processing");
 78  
                 }
 79  0
                 return false;
 80  
             }
 81  
         }
 82  0
         lastUpdate = updated;
 83  0
         return true;
 84  
     }
 85  
 
 86  
     public boolean isAcceptWithoutUpdateDate()
 87  
     {
 88  0
         return acceptWithoutUpdateDate;
 89  
     }
 90  
 
 91  
     public void setAcceptWithoutUpdateDate(boolean acceptWithoutUpdateDate)
 92  
     {
 93  0
         this.acceptWithoutUpdateDate = acceptWithoutUpdateDate;
 94  0
     }
 95  
 
 96  
     public Date getLastUpdate()
 97  
     {
 98  0
         return lastUpdate;
 99  
     }
 100  
 
 101  
     public void setLastUpdate(Date lastUpdate)
 102  
     {
 103  0
         this.lastUpdate = lastUpdate;
 104  0
     }
 105  
 }