src/core/net/sf/basedb/util/fileset/ResetMetadataRenderer.java

Code
Comments
Other
Rev Date Author Line
5623 06 May 11 nicklas 1 /**
5623 06 May 11 nicklas 2   $Id$
5623 06 May 11 nicklas 3
5623 06 May 11 nicklas 4   Copyright (C) 2011 Nicklas Nordborg
5623 06 May 11 nicklas 5
5623 06 May 11 nicklas 6   This file is part of BASE - BioArray Software Environment.
5623 06 May 11 nicklas 7   Available at http://base.thep.lu.se/
5623 06 May 11 nicklas 8
5623 06 May 11 nicklas 9   BASE is free software; you can redistribute it and/or
5623 06 May 11 nicklas 10   modify it under the terms of the GNU General Public License
5623 06 May 11 nicklas 11   as published by the Free Software Foundation; either version 3
5623 06 May 11 nicklas 12   of the License, or (at your option) any later version.
5623 06 May 11 nicklas 13
5623 06 May 11 nicklas 14   BASE is distributed in the hope that it will be useful,
5623 06 May 11 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
5623 06 May 11 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5623 06 May 11 nicklas 17   GNU General Public License for more details.
5623 06 May 11 nicklas 18
5623 06 May 11 nicklas 19   You should have received a copy of the GNU General Public License
5623 06 May 11 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
5623 06 May 11 nicklas 21 */
5623 06 May 11 nicklas 22 package net.sf.basedb.util.fileset;
5623 06 May 11 nicklas 23
5623 06 May 11 nicklas 24 import java.util.ArrayList;
5623 06 May 11 nicklas 25 import java.util.List;
5623 06 May 11 nicklas 26
5623 06 May 11 nicklas 27 import net.sf.basedb.core.signal.ThreadSignalHandler;
8144 21 Apr 23 nicklas 28 import net.sf.basedb.util.extensions.AbstractRenderer;
8144 21 Apr 23 nicklas 29 import net.sf.basedb.util.extensions.Extension;
5623 06 May 11 nicklas 30
5623 06 May 11 nicklas 31 /**
5623 06 May 11 nicklas 32   Renderer implementation for resetting metadata for the members of a file set.
5623 06 May 11 nicklas 33
5623 06 May 11 nicklas 34   @author Nicklas
5623 06 May 11 nicklas 35   @since 3.0
5623 06 May 11 nicklas 36   @base.modified $Date$
5623 06 May 11 nicklas 37 */
5623 06 May 11 nicklas 38 public class ResetMetadataRenderer
8144 21 Apr 23 nicklas 39   extends AbstractRenderer<ValidationAction>
5623 06 May 11 nicklas 40 {
5623 06 May 11 nicklas 41
5623 06 May 11 nicklas 42   private final List<ValidatingFileSetMember> members;
5623 06 May 11 nicklas 43
5623 06 May 11 nicklas 44   /**
5623 06 May 11 nicklas 45     Create a new renderer instance.
5623 06 May 11 nicklas 46   
5623 06 May 11 nicklas 47     @param members A list with the members of the file set that should have
5623 06 May 11 nicklas 48       their metadata reset
5623 06 May 11 nicklas 49    */
5623 06 May 11 nicklas 50   public ResetMetadataRenderer(List<ValidatingFileSetMember> members)
5623 06 May 11 nicklas 51   {
5623 06 May 11 nicklas 52     this.members = members;
5623 06 May 11 nicklas 53   }
5623 06 May 11 nicklas 54   
5623 06 May 11 nicklas 55   /*
5623 06 May 11 nicklas 56     From the Renderer interface
5623 06 May 11 nicklas 57     ---------------------------
5623 06 May 11 nicklas 58   */
5623 06 May 11 nicklas 59   @Override
8144 21 Apr 23 nicklas 60   public void render(ValidationAction action, Extension<? extends ValidationAction> ext)
5623 06 May 11 nicklas 61   {
5623 06 May 11 nicklas 62     ThreadSignalHandler.checkInterrupted();
5623 06 May 11 nicklas 63     
5623 06 May 11 nicklas 64     // Check if the action accepts any file(s)
5623 06 May 11 nicklas 65     List<ValidatingFileSetMember> accepted = new ArrayList<ValidatingFileSetMember>();
5623 06 May 11 nicklas 66     for (ValidatingFileSetMember member : members)
5623 06 May 11 nicklas 67     {
5623 06 May 11 nicklas 68       Accept accept = member.isAcceptedByValidator(action);
5623 06 May 11 nicklas 69       if (accept == Accept.VALIDATE_IMMEDIATELY)
5623 06 May 11 nicklas 70       {
5623 06 May 11 nicklas 71         // Reset metadata immediately
5623 06 May 11 nicklas 72         action.resetMetadata();
5623 06 May 11 nicklas 73       }
5623 06 May 11 nicklas 74       else if (accept == Accept.VALIDATE_LATER)
5623 06 May 11 nicklas 75       {
5623 06 May 11 nicklas 76         // File will be used in batch later
5623 06 May 11 nicklas 77         accepted.add(member);
5623 06 May 11 nicklas 78       }
5623 06 May 11 nicklas 79     }
5623 06 May 11 nicklas 80     
5623 06 May 11 nicklas 81     // Are there any files waiting for validation?
5623 06 May 11 nicklas 82     if (accepted.size() == 0) return;
5623 06 May 11 nicklas 83
5623 06 May 11 nicklas 84     // Reset metadata for the remaining files
5623 06 May 11 nicklas 85     action.resetMetadata();
5623 06 May 11 nicklas 86   }
5623 06 May 11 nicklas 87   // ---------------------------------
5623 06 May 11 nicklas 88 }