src/core/net/sf/basedb/util/extensions/manager/filter/ValidAndNewOrModifiedFilter.java

Code
Comments
Other
Rev Date Author Line
5603 08 Apr 11 nicklas 1 /**
5603 08 Apr 11 nicklas 2   $Id$
5603 08 Apr 11 nicklas 3
5603 08 Apr 11 nicklas 4   Copyright (C) 2011 Nicklas Nordborg
5603 08 Apr 11 nicklas 5
5603 08 Apr 11 nicklas 6   This file is part of BASE - BioArray Software Environment.
5603 08 Apr 11 nicklas 7   Available at http://base.thep.lu.se/
5603 08 Apr 11 nicklas 8
5603 08 Apr 11 nicklas 9   BASE is free software; you can redistribute it and/or
5603 08 Apr 11 nicklas 10   modify it under the terms of the GNU General Public License
5603 08 Apr 11 nicklas 11   as published by the Free Software Foundation; either version 3
5603 08 Apr 11 nicklas 12   of the License, or (at your option) any later version.
5603 08 Apr 11 nicklas 13
5603 08 Apr 11 nicklas 14   BASE is distributed in the hope that it will be useful,
5603 08 Apr 11 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
5603 08 Apr 11 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5603 08 Apr 11 nicklas 17   GNU General Public License for more details.
5603 08 Apr 11 nicklas 18
5603 08 Apr 11 nicklas 19   You should have received a copy of the GNU General Public License
5603 08 Apr 11 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
5603 08 Apr 11 nicklas 21 */
5603 08 Apr 11 nicklas 22 package net.sf.basedb.util.extensions.manager.filter;
5603 08 Apr 11 nicklas 23
5603 08 Apr 11 nicklas 24 import net.sf.basedb.util.extensions.manager.ExtensionsFile;
5603 08 Apr 11 nicklas 25 import net.sf.basedb.util.filter.Filter;
5603 08 Apr 11 nicklas 26
5603 08 Apr 11 nicklas 27 /**
5603 08 Apr 11 nicklas 28   Filter implementation for extension files that 
5603 08 Apr 11 nicklas 29   allow valid and new or modified files to pass.
5605 12 Apr 11 nicklas 30   The allowUnmodified parameter can be set to also 
5603 08 Apr 11 nicklas 31   allow unmodified files to pass.
5603 08 Apr 11 nicklas 32   
5603 08 Apr 11 nicklas 33   @author Nicklas
5603 08 Apr 11 nicklas 34   @since 3.0
5603 08 Apr 11 nicklas 35   @base.modified $Date$
5603 08 Apr 11 nicklas 36 */
5603 08 Apr 11 nicklas 37 public class ValidAndNewOrModifiedFilter
5603 08 Apr 11 nicklas 38   implements Filter<ExtensionsFile>
5603 08 Apr 11 nicklas 39 {
5603 08 Apr 11 nicklas 40   
6444 09 Apr 14 nicklas 41   private static final org.slf4j.Logger log = 
6444 09 Apr 14 nicklas 42     org.slf4j.LoggerFactory.getLogger(ValidAndNewOrModifiedFilter.class);
5603 08 Apr 11 nicklas 43
5603 08 Apr 11 nicklas 44   private final boolean allowUnmodified;
5616 27 Apr 11 nicklas 45   private final Filter<ExtensionsFile> parent;
5603 08 Apr 11 nicklas 46   
5603 08 Apr 11 nicklas 47   /**
5603 08 Apr 11 nicklas 48     Create a new filter.
5603 08 Apr 11 nicklas 49     
5603 08 Apr 11 nicklas 50     @param allowUnmodified TRUE to allow unmodified files to 
5603 08 Apr 11 nicklas 51       pass the filter, FALSE to block them
5603 08 Apr 11 nicklas 52   */
5603 08 Apr 11 nicklas 53   public ValidAndNewOrModifiedFilter(boolean allowUnmodified)
5603 08 Apr 11 nicklas 54   {
5616 27 Apr 11 nicklas 55     this(allowUnmodified, null);
5616 27 Apr 11 nicklas 56   }
5616 27 Apr 11 nicklas 57   
5616 27 Apr 11 nicklas 58   /**
5616 27 Apr 11 nicklas 59     Create a new filter.
5616 27 Apr 11 nicklas 60     
5616 27 Apr 11 nicklas 61     @param allowUnmodified TRUE to allow unmodified files to 
5616 27 Apr 11 nicklas 62       pass the filter, FALSE to block them
5616 27 Apr 11 nicklas 63     @param parent An optional parent filter that will also be checked
5616 27 Apr 11 nicklas 64   */
5616 27 Apr 11 nicklas 65   public ValidAndNewOrModifiedFilter(boolean allowUnmodified, Filter<ExtensionsFile> parent)
5616 27 Apr 11 nicklas 66   {
5603 08 Apr 11 nicklas 67     this.allowUnmodified = allowUnmodified;
5616 27 Apr 11 nicklas 68     this.parent = parent;
5603 08 Apr 11 nicklas 69   }
5603 08 Apr 11 nicklas 70   
5603 08 Apr 11 nicklas 71   /*
5603 08 Apr 11 nicklas 72     From the Filter interface
5603 08 Apr 11 nicklas 73     -------------------------
5603 08 Apr 11 nicklas 74   */
5603 08 Apr 11 nicklas 75   @Override
5603 08 Apr 11 nicklas 76   public boolean evaluate(ExtensionsFile xtFile)
5603 08 Apr 11 nicklas 77   {
5616 27 Apr 11 nicklas 78     if (parent != null && !parent.evaluate(xtFile)) 
5616 27 Apr 11 nicklas 79     {
5616 27 Apr 11 nicklas 80       return false;
5616 27 Apr 11 nicklas 81     }
5616 27 Apr 11 nicklas 82     
5607 15 Apr 11 nicklas 83     if (!xtFile.isValid() || (xtFile.hasError() && !allowUnmodified)) 
5603 08 Apr 11 nicklas 84     {
5603 08 Apr 11 nicklas 85       log.info("File has errors (skipping): " + xtFile);
5603 08 Apr 11 nicklas 86       return false;
5603 08 Apr 11 nicklas 87     }
5603 08 Apr 11 nicklas 88     
5603 08 Apr 11 nicklas 89     if (!xtFile.wasModified() && !allowUnmodified)
5603 08 Apr 11 nicklas 90     {
5603 08 Apr 11 nicklas 91       log.info("File is not modified (skipping): " + xtFile);
5603 08 Apr 11 nicklas 92       return false;
5603 08 Apr 11 nicklas 93     }
5603 08 Apr 11 nicklas 94     
5603 08 Apr 11 nicklas 95     return true;
5603 08 Apr 11 nicklas 96   }
5603 08 Apr 11 nicklas 97   // -------------------------
5603 08 Apr 11 nicklas 98   
5603 08 Apr 11 nicklas 99   
5603 08 Apr 11 nicklas 100 }