src/core/net/sf/basedb/util/fileset/ValidationAction.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 net.sf.basedb.core.DataFileType;
5623 06 May 11 nicklas 25 import net.sf.basedb.core.DbControl;
5623 06 May 11 nicklas 26 import net.sf.basedb.core.File;
5623 06 May 11 nicklas 27 import net.sf.basedb.core.FileSet;
5623 06 May 11 nicklas 28 import net.sf.basedb.core.FileSetMember;
5623 06 May 11 nicklas 29 import net.sf.basedb.core.FileStoreEnabled;
5623 06 May 11 nicklas 30 import net.sf.basedb.core.InvalidDataException;
5623 06 May 11 nicklas 31 import net.sf.basedb.core.InvalidRelationException;
5623 06 May 11 nicklas 32 import net.sf.basedb.core.PermissionDeniedException;
5623 06 May 11 nicklas 33 import net.sf.basedb.util.extensions.Action;
5623 06 May 11 nicklas 34 import net.sf.basedb.util.extensions.ClientContext;
5623 06 May 11 nicklas 35
5623 06 May 11 nicklas 36 /**
5623 06 May 11 nicklas 37   Action for validating and metadata extraction from files in a file set. 
5623 06 May 11 nicklas 38   This action is used in two different contexts:
5623 06 May 11 nicklas 39   
5623 06 May 11 nicklas 40   <ul>
5623 06 May 11 nicklas 41   <li>For validating the files when {@link FileSet#validate(DbControl)}.
5623 06 May 11 nicklas 42     This action is supposed to validated the entire file set as a whole. The
5623 06 May 11 nicklas 43     {@link ClientContext} parameter passed to the factory has the owner
5623 06 May 11 nicklas 44     of the file set (eg. the {@link FileStoreEnabled}) item as the
5623 06 May 11 nicklas 45     current item.
5623 06 May 11 nicklas 46     
5623 06 May 11 nicklas 47   <li>For removing metadata when a file in a file set is removed or replaced
5818 21 Oct 11 nicklas 48     with another file. For example, when the {@link FileSet#removeMember(FileSetMember)},
5818 21 Oct 11 nicklas 49     {@link FileSet#setMember(File, DataFileType)} or any other method that removs
5818 21 Oct 11 nicklas 50     a file from the fileset is called. The {@link ClientContext} in this case also
5818 21 Oct 11 nicklas 51     has the owner of the file set as the current item, but the action will only be 
5818 21 Oct 11 nicklas 52     asked to accept the file(s) that are actually removed/modified.
5623 06 May 11 nicklas 53   </ul>
5623 06 May 11 nicklas 54   <p>
5623 06 May 11 nicklas 55   
5623 06 May 11 nicklas 56   Tip! For validators that works on a single file at a time the 
5623 06 May 11 nicklas 57   {@link SingleFileValidationAction} can be used as a base class.
5623 06 May 11 nicklas 58
5623 06 May 11 nicklas 59   @author Nicklas
5623 06 May 11 nicklas 60   @since 3.0
5623 06 May 11 nicklas 61   @base.modified $Date$
5623 06 May 11 nicklas 62 */
5623 06 May 11 nicklas 63 public interface ValidationAction
5623 06 May 11 nicklas 64   extends Action
5623 06 May 11 nicklas 65 {
5623 06 May 11 nicklas 66
5623 06 May 11 nicklas 67   /**
5623 06 May 11 nicklas 68     Check if the given file is handled by this validator implementation 
5623 06 May 11 nicklas 69     or not? No validation of the actual file data should take place in this
5623 06 May 11 nicklas 70     method. This method is called by the core for all members of the
5623 06 May 11 nicklas 71     file set that are still considered as valid. If another validator
5623 06 May 11 nicklas 72     has marked a file as invalid it will not be offered to the remaining
5623 06 May 11 nicklas 73     validators.
5623 06 May 11 nicklas 74     <p>
5623 06 May 11 nicklas 75     The file can either be validated immediately or later when this method
5623 06 May 11 nicklas 76     has been called for all files in the file set. If the file
5623 06 May 11 nicklas 77     is accepted for immediate validation the {@link #validateAndExtractMetadata()}
5623 06 May 11 nicklas 78     is called before the next file is processed. When all files
5623 06 May 11 nicklas 79     have been processed the {@link #validateAndExtractMetadata()} method
5623 06 May 11 nicklas 80     is called again if at least one was accepted for later validation.
5623 06 May 11 nicklas 81     
5623 06 May 11 nicklas 82     @param member A member of the current file set
5623 06 May 11 nicklas 83     @return A value from the Accept enumeration to accept the file
5623 06 May 11 nicklas 84       for validation or null to not accept the file for validatio
5623 06 May 11 nicklas 85   */
5623 06 May 11 nicklas 86   public Accept acceptFile(FileSetMember member);
5623 06 May 11 nicklas 87   
5623 06 May 11 nicklas 88   /**
5623 06 May 11 nicklas 89     Validate and extract metadata from the file(s) that has been added to 
5623 06 May 11 nicklas 90     this validator. If the {@link #acceptFile(FileSetMember)} method
5623 06 May 11 nicklas 91     returns {@link Accept#VALIDATE_IMMEDIATELY} this method is called
5623 06 May 11 nicklas 92     and the validator should work on the last accepted file. 
5623 06 May 11 nicklas 93     <p>
5623 06 May 11 nicklas 94     This method is also called after all files has been processed if at
5623 06 May 11 nicklas 95     least one file returned {@link Accept#VALIDATE_LATER}.
5623 06 May 11 nicklas 96     <p>
5623 06 May 11 nicklas 97     
5623 06 May 11 nicklas 98     This method is recommended to throw an {@link InvalidDataException} or a 
5623 06 May 11 nicklas 99     subclass if the file is not a valid file. {@link PermissionDeniedException}:s 
5623 06 May 11 nicklas 100     are ignored by the core and will not change the validation status. An 
5623 06 May 11 nicklas 101     exception of type {@link InvalidRelationException} can be thrown if the 
5623 06 May 11 nicklas 102     file itself is valid, but a related file that it depends on is not. The
5623 06 May 11 nicklas 103     core will still mark the file as invalid and store the error message,
5623 06 May 11 nicklas 104     but extracted metadata will not be reset.
5623 06 May 11 nicklas 105     
5623 06 May 11 nicklas 106     @throws InvalidDataException If the validator detects an invalid
5623 06 May 11 nicklas 107       file
5623 06 May 11 nicklas 108     @throws InvalidRelationException If the validator detects that the
5623 06 May 11 nicklas 109       file is valid but another file that it depends on is not, metadata
5623 06 May 11 nicklas 110       extract will still happen
5623 06 May 11 nicklas 111   */
5623 06 May 11 nicklas 112   public void validateAndExtractMetadata()
5623 06 May 11 nicklas 113     throws InvalidDataException, InvalidRelationException;
5623 06 May 11 nicklas 114
5623 06 May 11 nicklas 115   /**
5623 06 May 11 nicklas 116     Reset all metadata that this class normally can set. This method is called
5623 06 May 11 nicklas 117     if the validation of a file failed or if a file is removed from the 
5623 06 May 11 nicklas 118     file set. Any previous metadata that may signal that a valid file is
5623 06 May 11 nicklas 119     present should be reset.
5623 06 May 11 nicklas 120   */
5623 06 May 11 nicklas 121   public void resetMetadata();
5623 06 May 11 nicklas 122
5623 06 May 11 nicklas 123   
5623 06 May 11 nicklas 124 }