5623 |
06 May 11 |
nicklas |
1 |
/** |
5623 |
06 May 11 |
nicklas |
$Id$ |
5623 |
06 May 11 |
nicklas |
3 |
|
5623 |
06 May 11 |
nicklas |
Copyright (C) 2011 Nicklas Nordborg |
5623 |
06 May 11 |
nicklas |
5 |
|
5623 |
06 May 11 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5623 |
06 May 11 |
nicklas |
Available at http://base.thep.lu.se/ |
5623 |
06 May 11 |
nicklas |
8 |
|
5623 |
06 May 11 |
nicklas |
BASE is free software; you can redistribute it and/or |
5623 |
06 May 11 |
nicklas |
modify it under the terms of the GNU General Public License |
5623 |
06 May 11 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5623 |
06 May 11 |
nicklas |
of the License, or (at your option) any later version. |
5623 |
06 May 11 |
nicklas |
13 |
|
5623 |
06 May 11 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5623 |
06 May 11 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5623 |
06 May 11 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5623 |
06 May 11 |
nicklas |
GNU General Public License for more details. |
5623 |
06 May 11 |
nicklas |
18 |
|
5623 |
06 May 11 |
nicklas |
You should have received a copy of the GNU General Public License |
5623 |
06 May 11 |
nicklas |
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 |
Action for validating and metadata extraction from files in a file set. |
5623 |
06 May 11 |
nicklas |
This action is used in two different contexts: |
5623 |
06 May 11 |
nicklas |
39 |
|
5623 |
06 May 11 |
nicklas |
<ul> |
5623 |
06 May 11 |
nicklas |
<li>For validating the files when {@link FileSet#validate(DbControl)}. |
5623 |
06 May 11 |
nicklas |
This action is supposed to validated the entire file set as a whole. The |
5623 |
06 May 11 |
nicklas |
{@link ClientContext} parameter passed to the factory has the owner |
5623 |
06 May 11 |
nicklas |
of the file set (eg. the {@link FileStoreEnabled}) item as the |
5623 |
06 May 11 |
nicklas |
current item. |
5623 |
06 May 11 |
nicklas |
46 |
|
5623 |
06 May 11 |
nicklas |
<li>For removing metadata when a file in a file set is removed or replaced |
5818 |
21 Oct 11 |
nicklas |
with another file. For example, when the {@link FileSet#removeMember(FileSetMember)}, |
5818 |
21 Oct 11 |
nicklas |
{@link FileSet#setMember(File, DataFileType)} or any other method that removs |
5818 |
21 Oct 11 |
nicklas |
a file from the fileset is called. The {@link ClientContext} in this case also |
5818 |
21 Oct 11 |
nicklas |
has the owner of the file set as the current item, but the action will only be |
5818 |
21 Oct 11 |
nicklas |
asked to accept the file(s) that are actually removed/modified. |
5623 |
06 May 11 |
nicklas |
</ul> |
5623 |
06 May 11 |
nicklas |
<p> |
5623 |
06 May 11 |
nicklas |
55 |
|
5623 |
06 May 11 |
nicklas |
Tip! For validators that works on a single file at a time the |
5623 |
06 May 11 |
nicklas |
{@link SingleFileValidationAction} can be used as a base class. |
5623 |
06 May 11 |
nicklas |
58 |
|
5623 |
06 May 11 |
nicklas |
@author Nicklas |
5623 |
06 May 11 |
nicklas |
@since 3.0 |
5623 |
06 May 11 |
nicklas |
@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 |
Check if the given file is handled by this validator implementation |
5623 |
06 May 11 |
nicklas |
or not? No validation of the actual file data should take place in this |
5623 |
06 May 11 |
nicklas |
method. This method is called by the core for all members of the |
5623 |
06 May 11 |
nicklas |
file set that are still considered as valid. If another validator |
5623 |
06 May 11 |
nicklas |
has marked a file as invalid it will not be offered to the remaining |
5623 |
06 May 11 |
nicklas |
validators. |
5623 |
06 May 11 |
nicklas |
<p> |
5623 |
06 May 11 |
nicklas |
The file can either be validated immediately or later when this method |
5623 |
06 May 11 |
nicklas |
has been called for all files in the file set. If the file |
5623 |
06 May 11 |
nicklas |
is accepted for immediate validation the {@link #validateAndExtractMetadata()} |
5623 |
06 May 11 |
nicklas |
is called before the next file is processed. When all files |
5623 |
06 May 11 |
nicklas |
have been processed the {@link #validateAndExtractMetadata()} method |
5623 |
06 May 11 |
nicklas |
is called again if at least one was accepted for later validation. |
5623 |
06 May 11 |
nicklas |
81 |
|
5623 |
06 May 11 |
nicklas |
@param member A member of the current file set |
5623 |
06 May 11 |
nicklas |
@return A value from the Accept enumeration to accept the file |
5623 |
06 May 11 |
nicklas |
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 |
Validate and extract metadata from the file(s) that has been added to |
5623 |
06 May 11 |
nicklas |
this validator. If the {@link #acceptFile(FileSetMember)} method |
5623 |
06 May 11 |
nicklas |
returns {@link Accept#VALIDATE_IMMEDIATELY} this method is called |
5623 |
06 May 11 |
nicklas |
and the validator should work on the last accepted file. |
5623 |
06 May 11 |
nicklas |
<p> |
5623 |
06 May 11 |
nicklas |
This method is also called after all files has been processed if at |
5623 |
06 May 11 |
nicklas |
least one file returned {@link Accept#VALIDATE_LATER}. |
5623 |
06 May 11 |
nicklas |
<p> |
5623 |
06 May 11 |
nicklas |
97 |
|
5623 |
06 May 11 |
nicklas |
This method is recommended to throw an {@link InvalidDataException} or a |
5623 |
06 May 11 |
nicklas |
subclass if the file is not a valid file. {@link PermissionDeniedException}:s |
5623 |
06 May 11 |
nicklas |
are ignored by the core and will not change the validation status. An |
5623 |
06 May 11 |
nicklas |
exception of type {@link InvalidRelationException} can be thrown if the |
5623 |
06 May 11 |
nicklas |
file itself is valid, but a related file that it depends on is not. The |
5623 |
06 May 11 |
nicklas |
core will still mark the file as invalid and store the error message, |
5623 |
06 May 11 |
nicklas |
but extracted metadata will not be reset. |
5623 |
06 May 11 |
nicklas |
105 |
|
5623 |
06 May 11 |
nicklas |
@throws InvalidDataException If the validator detects an invalid |
5623 |
06 May 11 |
nicklas |
file |
5623 |
06 May 11 |
nicklas |
@throws InvalidRelationException If the validator detects that the |
5623 |
06 May 11 |
nicklas |
file is valid but another file that it depends on is not, metadata |
5623 |
06 May 11 |
nicklas |
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 |
Reset all metadata that this class normally can set. This method is called |
5623 |
06 May 11 |
nicklas |
if the validation of a file failed or if a file is removed from the |
5623 |
06 May 11 |
nicklas |
file set. Any previous metadata that may signal that a valid file is |
5623 |
06 May 11 |
nicklas |
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 |
} |