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