src/core/net/sf/basedb/util/overview/validator/NodeValidator.java

Code
Comments
Other
Rev Date Author Line
4740 05 Feb 09 nicklas 1 /**
4740 05 Feb 09 nicklas 2   $Id$
4740 05 Feb 09 nicklas 3
4740 05 Feb 09 nicklas 4   Copyright (C) 2008 Nicklas Nordborg
4740 05 Feb 09 nicklas 5
4740 05 Feb 09 nicklas 6   This file is part of BASE - BioArray Software Environment.
4740 05 Feb 09 nicklas 7   Available at http://base.thep.lu.se/
4740 05 Feb 09 nicklas 8
4740 05 Feb 09 nicklas 9   BASE is free software; you can redistribute it and/or
4740 05 Feb 09 nicklas 10   modify it under the terms of the GNU General Public License
4740 05 Feb 09 nicklas 11   as published by the Free Software Foundation; either version 3
4740 05 Feb 09 nicklas 12   of the License, or (at your option) any later version.
4740 05 Feb 09 nicklas 13
4740 05 Feb 09 nicklas 14   BASE is distributed in the hope that it will be useful,
4740 05 Feb 09 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4740 05 Feb 09 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4740 05 Feb 09 nicklas 17   GNU General Public License for more details.
4740 05 Feb 09 nicklas 18
4740 05 Feb 09 nicklas 19   You should have received a copy of the GNU General Public License
4740 05 Feb 09 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
4740 05 Feb 09 nicklas 21 */
4740 05 Feb 09 nicklas 22 package net.sf.basedb.util.overview.validator;
4740 05 Feb 09 nicklas 23
4740 05 Feb 09 nicklas 24 import net.sf.basedb.core.DbControl;
4740 05 Feb 09 nicklas 25 import net.sf.basedb.util.overview.Failure;
4740 05 Feb 09 nicklas 26 import net.sf.basedb.util.overview.Fix;
4740 05 Feb 09 nicklas 27 import net.sf.basedb.util.overview.OverviewContext;
4740 05 Feb 09 nicklas 28 import net.sf.basedb.util.overview.Validator;
4768 18 Feb 09 nicklas 29 import net.sf.basedb.util.overview.loader.NodeLoader;
4740 05 Feb 09 nicklas 30 import net.sf.basedb.util.overview.node.ChildNodeDirection;
4740 05 Feb 09 nicklas 31 import net.sf.basedb.util.overview.Node;
4740 05 Feb 09 nicklas 32 import net.sf.basedb.util.overview.node.NodeFactory;
4740 05 Feb 09 nicklas 33
4740 05 Feb 09 nicklas 34 /**
4740 05 Feb 09 nicklas 35   A node validator is responsible for checking the "validity" of
4740 05 Feb 09 nicklas 36   a node. The rules that are checked is varying from node to node
4740 05 Feb 09 nicklas 37   depending on what type of item it represents. Two common 
4740 05 Feb 09 nicklas 38   "errors" are missing items and that a user is denied access to
4740 05 Feb 09 nicklas 39   an item. Since this means that there is no item to validate
4740 05 Feb 09 nicklas 40   there are special methods for those two cases.
4740 05 Feb 09 nicklas 41   <p>
4740 05 Feb 09 nicklas 42   
4740 05 Feb 09 nicklas 43   The validation of a node is part of the node creation and happens
4740 05 Feb 09 nicklas 44   in one of the {@link NodeFactory#createMissingNode(Node)},
4740 05 Feb 09 nicklas 45   {@link NodeFactory#createDeniedNode(Node)} or {@link 
4740 05 Feb 09 nicklas 46   NodeFactory#createNode(net.sf.basedb.core.BasicItem, Object, Node, ChildNodeDirection)}
4740 05 Feb 09 nicklas 47   methods. The validation takes place in two steps. The first step calls
4740 05 Feb 09 nicklas 48   one of the three <em>pre</em> methods:
4740 05 Feb 09 nicklas 49   <ul>
4740 05 Feb 09 nicklas 50   <li>{@link #preMissingItem(DbControl, OverviewContext, Node)}
4740 05 Feb 09 nicklas 51   <li>{@link #preDeniedItem(DbControl, OverviewContext, Node)}
4740 05 Feb 09 nicklas 52   <li>{@link #preValidate(DbControl, OverviewContext, Object, Node)}
4740 05 Feb 09 nicklas 53   </ul>
4740 05 Feb 09 nicklas 54   
4740 05 Feb 09 nicklas 55   This happens <em>before</em> a node is created for an item. If the
4740 05 Feb 09 nicklas 56   called method returns <code>false</code> no new node is created
4740 05 Feb 09 nicklas 57   and further processing is stopped. The second step happens after
4740 05 Feb 09 nicklas 58   the node has been created and calls one of the three <em>post</em>
4740 05 Feb 09 nicklas 59   methods:
4740 05 Feb 09 nicklas 60   <ul>
4740 05 Feb 09 nicklas 61   <li>{@link #postMissingItem(DbControl, OverviewContext, Node, Node)}
4740 05 Feb 09 nicklas 62   <li>{@link #postDeniedItem(DbControl, OverviewContext, Node, Node)}
4740 05 Feb 09 nicklas 63   <li>{@link #postValidate(DbControl, OverviewContext, Node, Node)}
4740 05 Feb 09 nicklas 64   </ul>
4740 05 Feb 09 nicklas 65
4740 05 Feb 09 nicklas 66   <p>
4768 18 Feb 09 nicklas 67   The last step is to validate a complete folder. This can't happen from
4768 18 Feb 09 nicklas 68   the {@link NodeFactory} since it only deals with individual nodes. It
4768 18 Feb 09 nicklas 69   is the responsibility of a {@link NodeLoader} to call {@link 
4768 18 Feb 09 nicklas 70   #postValidateFolder(DbControl, OverviewContext, Node, Node)} after it has finished
4768 18 Feb 09 nicklas 71   loading a folder node. NOTE! This should be called even if the folder node 
4768 18 Feb 09 nicklas 72   is null, or if the folder doesn't contain any children (some validators may
4768 18 Feb 09 nicklas 73   want to report on missing items!)
4768 18 Feb 09 nicklas 74
4768 18 Feb 09 nicklas 75   <p>
4740 05 Feb 09 nicklas 76   Validations failures should be registered with the current context
4740 05 Feb 09 nicklas 77   using {@link OverviewContext#createFailure(Validator, Node, String, Fix...)}.
4740 05 Feb 09 nicklas 78   
4740 05 Feb 09 nicklas 79   @author Nicklas
4740 05 Feb 09 nicklas 80   @version 2.10
4740 05 Feb 09 nicklas 81   @base.modified $Date$
4740 05 Feb 09 nicklas 82 */
4740 05 Feb 09 nicklas 83 public interface NodeValidator<I>
4740 05 Feb 09 nicklas 84 {
4740 05 Feb 09 nicklas 85
4740 05 Feb 09 nicklas 86   /**
4740 05 Feb 09 nicklas 87     Validate a missing item before creating a node for it. This usually means 
4740 05 Feb 09 nicklas 88     creating a missing item {@link Failure} for the parent node and registering 
4740 05 Feb 09 nicklas 89     it with the context.
4740 05 Feb 09 nicklas 90     @param dc A DbControl to use if the validation needs to access the database
4740 05 Feb 09 nicklas 91     @param context The current overview context
4740 05 Feb 09 nicklas 92     @param parentNode The parent node that is missing the item
4740 05 Feb 09 nicklas 93     @return TRUE if a node should be created, FALSE if not
4740 05 Feb 09 nicklas 94   */
4740 05 Feb 09 nicklas 95   public boolean preMissingItem(DbControl dc, OverviewContext context, Node parentNode);
4740 05 Feb 09 nicklas 96   
4740 05 Feb 09 nicklas 97   /**
4740 05 Feb 09 nicklas 98     Validate an item that the current user doen't have access to before creating a 
4740 05 Feb 09 nicklas 99     node for it. 
4740 05 Feb 09 nicklas 100     @param dc A DbControl to use if the validation needs to access the database
4740 05 Feb 09 nicklas 101     @param context The current overview context
4740 05 Feb 09 nicklas 102     @param parentNode The parent node that is linked with the item
4740 05 Feb 09 nicklas 103     @return TRUE if a node should be created, FALSE if not
4740 05 Feb 09 nicklas 104   */
4740 05 Feb 09 nicklas 105   public boolean preDeniedItem(DbControl dc, OverviewContext context, Node parentNode);
4740 05 Feb 09 nicklas 106   
4740 05 Feb 09 nicklas 107   /**
4740 05 Feb 09 nicklas 108     Validate an existing item before creating a node for it.
4740 05 Feb 09 nicklas 109     @param dc A DbControl to use if the validation needs to access the database
4740 05 Feb 09 nicklas 110     @param context The current overview context
4740 05 Feb 09 nicklas 111     @param item The item to validate
4740 05 Feb 09 nicklas 112     @param parentNode The parent node that is linked with the item
4740 05 Feb 09 nicklas 113     @return TRUE if a node should be created, FALSE if not
4740 05 Feb 09 nicklas 114   */
4740 05 Feb 09 nicklas 115   public boolean preValidate(DbControl dc, OverviewContext context, I item, Node parentNode);
4740 05 Feb 09 nicklas 116
4740 05 Feb 09 nicklas 117   /**
4740 05 Feb 09 nicklas 118     Validate a missing item after a node has been created for it.
4740 05 Feb 09 nicklas 119     @param dc A DbControl to use if the validation needs to access the database
4740 05 Feb 09 nicklas 120     @param context The current overview context
4740 05 Feb 09 nicklas 121     @param node The node object that represents the missing item
4740 05 Feb 09 nicklas 122     @param parentNode The parent node that is missing the item
4740 05 Feb 09 nicklas 123   */
4740 05 Feb 09 nicklas 124   public void postMissingItem(DbControl dc, OverviewContext context, Node node, Node parentNode);
4740 05 Feb 09 nicklas 125
4740 05 Feb 09 nicklas 126   /**
4740 05 Feb 09 nicklas 127     Validate an item that the current user doen't have access to after a 
4740 05 Feb 09 nicklas 128     node has been created for it. 
4740 05 Feb 09 nicklas 129     @param dc A DbControl to use if the validation needs to access the database
4740 05 Feb 09 nicklas 130     @param context The current overview context
4740 05 Feb 09 nicklas 131     @param node The node object that represents the unaccessible item
4740 05 Feb 09 nicklas 132     @param parentNode The parent node that is linked with the item
4740 05 Feb 09 nicklas 133   */
4740 05 Feb 09 nicklas 134   public void postDeniedItem(DbControl dc, OverviewContext context, Node node, Node parentNode);
4740 05 Feb 09 nicklas 135   
4740 05 Feb 09 nicklas 136   /**
4740 05 Feb 09 nicklas 137     Validate an existing item after a node has been created for it.
4740 05 Feb 09 nicklas 138     @param dc A DbControl to use if the validation needs to access the database
4740 05 Feb 09 nicklas 139     @param context The current overview context
4740 05 Feb 09 nicklas 140     @param node The node object that represents item
4740 05 Feb 09 nicklas 141     @param parentNode The parent node that is linked with the item
4740 05 Feb 09 nicklas 142   */
4740 05 Feb 09 nicklas 143   public void postValidate(DbControl dc, OverviewContext context, Node node, Node parentNode);
4740 05 Feb 09 nicklas 144
4768 18 Feb 09 nicklas 145   /**
4768 18 Feb 09 nicklas 146     Validate a folder node after all child (item-type) nodes has been
4768 18 Feb 09 nicklas 147     added to the folder. This method must be called by node loaders
4768 18 Feb 09 nicklas 148     in all cases were it is theoretically possible that a folder node
4768 18 Feb 09 nicklas 149     can be created. Some validators may, for example, check on missing
4768 18 Feb 09 nicklas 150     items!
4768 18 Feb 09 nicklas 151     
4768 18 Feb 09 nicklas 152     @param dc A DbControl to use for database access
4768 18 Feb 09 nicklas 153     @param context The current overview context
4768 18 Feb 09 nicklas 154     @param folderNode The folder node, or null if no folder has been created
4768 18 Feb 09 nicklas 155     @param parentNode The parent node (never null)
4768 18 Feb 09 nicklas 156   */
4740 05 Feb 09 nicklas 157   public void postValidateFolder(DbControl dc, OverviewContext context, Node folderNode, Node parentNode);
4740 05 Feb 09 nicklas 158
4740 05 Feb 09 nicklas 159 }