4740 |
05 Feb 09 |
nicklas |
1 |
/** |
4740 |
05 Feb 09 |
nicklas |
$Id$ |
4740 |
05 Feb 09 |
nicklas |
3 |
|
4740 |
05 Feb 09 |
nicklas |
Copyright (C) 2008 Nicklas Nordborg |
4740 |
05 Feb 09 |
nicklas |
5 |
|
4740 |
05 Feb 09 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4740 |
05 Feb 09 |
nicklas |
Available at http://base.thep.lu.se/ |
4740 |
05 Feb 09 |
nicklas |
8 |
|
4740 |
05 Feb 09 |
nicklas |
BASE is free software; you can redistribute it and/or |
4740 |
05 Feb 09 |
nicklas |
modify it under the terms of the GNU General Public License |
4740 |
05 Feb 09 |
nicklas |
as published by the Free Software Foundation; either version 3 |
4740 |
05 Feb 09 |
nicklas |
of the License, or (at your option) any later version. |
4740 |
05 Feb 09 |
nicklas |
13 |
|
4740 |
05 Feb 09 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4740 |
05 Feb 09 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4740 |
05 Feb 09 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4740 |
05 Feb 09 |
nicklas |
GNU General Public License for more details. |
4740 |
05 Feb 09 |
nicklas |
18 |
|
4740 |
05 Feb 09 |
nicklas |
You should have received a copy of the GNU General Public License |
4740 |
05 Feb 09 |
nicklas |
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 |
A node validator is responsible for checking the "validity" of |
4740 |
05 Feb 09 |
nicklas |
a node. The rules that are checked is varying from node to node |
4740 |
05 Feb 09 |
nicklas |
depending on what type of item it represents. Two common |
4740 |
05 Feb 09 |
nicklas |
"errors" are missing items and that a user is denied access to |
4740 |
05 Feb 09 |
nicklas |
an item. Since this means that there is no item to validate |
4740 |
05 Feb 09 |
nicklas |
there are special methods for those two cases. |
4740 |
05 Feb 09 |
nicklas |
<p> |
4740 |
05 Feb 09 |
nicklas |
42 |
|
4740 |
05 Feb 09 |
nicklas |
The validation of a node is part of the node creation and happens |
4740 |
05 Feb 09 |
nicklas |
in one of the {@link NodeFactory#createMissingNode(Node)}, |
4740 |
05 Feb 09 |
nicklas |
{@link NodeFactory#createDeniedNode(Node)} or {@link |
4740 |
05 Feb 09 |
nicklas |
NodeFactory#createNode(net.sf.basedb.core.BasicItem, Object, Node, ChildNodeDirection)} |
4740 |
05 Feb 09 |
nicklas |
methods. The validation takes place in two steps. The first step calls |
4740 |
05 Feb 09 |
nicklas |
one of the three <em>pre</em> methods: |
4740 |
05 Feb 09 |
nicklas |
<ul> |
4740 |
05 Feb 09 |
nicklas |
<li>{@link #preMissingItem(DbControl, OverviewContext, Node)} |
4740 |
05 Feb 09 |
nicklas |
<li>{@link #preDeniedItem(DbControl, OverviewContext, Node)} |
4740 |
05 Feb 09 |
nicklas |
<li>{@link #preValidate(DbControl, OverviewContext, Object, Node)} |
4740 |
05 Feb 09 |
nicklas |
</ul> |
4740 |
05 Feb 09 |
nicklas |
54 |
|
4740 |
05 Feb 09 |
nicklas |
This happens <em>before</em> a node is created for an item. If the |
4740 |
05 Feb 09 |
nicklas |
called method returns <code>false</code> no new node is created |
4740 |
05 Feb 09 |
nicklas |
and further processing is stopped. The second step happens after |
4740 |
05 Feb 09 |
nicklas |
the node has been created and calls one of the three <em>post</em> |
4740 |
05 Feb 09 |
nicklas |
methods: |
4740 |
05 Feb 09 |
nicklas |
<ul> |
4740 |
05 Feb 09 |
nicklas |
<li>{@link #postMissingItem(DbControl, OverviewContext, Node, Node)} |
4740 |
05 Feb 09 |
nicklas |
<li>{@link #postDeniedItem(DbControl, OverviewContext, Node, Node)} |
4740 |
05 Feb 09 |
nicklas |
<li>{@link #postValidate(DbControl, OverviewContext, Node, Node)} |
4740 |
05 Feb 09 |
nicklas |
</ul> |
4740 |
05 Feb 09 |
nicklas |
65 |
|
4740 |
05 Feb 09 |
nicklas |
<p> |
4768 |
18 Feb 09 |
nicklas |
The last step is to validate a complete folder. This can't happen from |
4768 |
18 Feb 09 |
nicklas |
the {@link NodeFactory} since it only deals with individual nodes. It |
4768 |
18 Feb 09 |
nicklas |
is the responsibility of a {@link NodeLoader} to call {@link |
4768 |
18 Feb 09 |
nicklas |
#postValidateFolder(DbControl, OverviewContext, Node, Node)} after it has finished |
4768 |
18 Feb 09 |
nicklas |
loading a folder node. NOTE! This should be called even if the folder node |
4768 |
18 Feb 09 |
nicklas |
is null, or if the folder doesn't contain any children (some validators may |
4768 |
18 Feb 09 |
nicklas |
want to report on missing items!) |
4768 |
18 Feb 09 |
nicklas |
74 |
|
4768 |
18 Feb 09 |
nicklas |
<p> |
4740 |
05 Feb 09 |
nicklas |
Validations failures should be registered with the current context |
4740 |
05 Feb 09 |
nicklas |
using {@link OverviewContext#createFailure(Validator, Node, String, Fix...)}. |
4740 |
05 Feb 09 |
nicklas |
78 |
|
4740 |
05 Feb 09 |
nicklas |
@author Nicklas |
4740 |
05 Feb 09 |
nicklas |
@version 2.10 |
4740 |
05 Feb 09 |
nicklas |
@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 |
Validate a missing item before creating a node for it. This usually means |
4740 |
05 Feb 09 |
nicklas |
creating a missing item {@link Failure} for the parent node and registering |
4740 |
05 Feb 09 |
nicklas |
it with the context. |
4740 |
05 Feb 09 |
nicklas |
@param dc A DbControl to use if the validation needs to access the database |
4740 |
05 Feb 09 |
nicklas |
@param context The current overview context |
4740 |
05 Feb 09 |
nicklas |
@param parentNode The parent node that is missing the item |
4740 |
05 Feb 09 |
nicklas |
@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 |
Validate an item that the current user doen't have access to before creating a |
4740 |
05 Feb 09 |
nicklas |
node for it. |
4740 |
05 Feb 09 |
nicklas |
@param dc A DbControl to use if the validation needs to access the database |
4740 |
05 Feb 09 |
nicklas |
@param context The current overview context |
4740 |
05 Feb 09 |
nicklas |
@param parentNode The parent node that is linked with the item |
4740 |
05 Feb 09 |
nicklas |
@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 |
Validate an existing item before creating a node for it. |
4740 |
05 Feb 09 |
nicklas |
@param dc A DbControl to use if the validation needs to access the database |
4740 |
05 Feb 09 |
nicklas |
@param context The current overview context |
4740 |
05 Feb 09 |
nicklas |
@param item The item to validate |
4740 |
05 Feb 09 |
nicklas |
@param parentNode The parent node that is linked with the item |
4740 |
05 Feb 09 |
nicklas |
@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 |
Validate a missing item after a node has been created for it. |
4740 |
05 Feb 09 |
nicklas |
@param dc A DbControl to use if the validation needs to access the database |
4740 |
05 Feb 09 |
nicklas |
@param context The current overview context |
4740 |
05 Feb 09 |
nicklas |
@param node The node object that represents the missing item |
4740 |
05 Feb 09 |
nicklas |
@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 |
Validate an item that the current user doen't have access to after a |
4740 |
05 Feb 09 |
nicklas |
node has been created for it. |
4740 |
05 Feb 09 |
nicklas |
@param dc A DbControl to use if the validation needs to access the database |
4740 |
05 Feb 09 |
nicklas |
@param context The current overview context |
4740 |
05 Feb 09 |
nicklas |
@param node The node object that represents the unaccessible item |
4740 |
05 Feb 09 |
nicklas |
@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 |
Validate an existing item after a node has been created for it. |
4740 |
05 Feb 09 |
nicklas |
@param dc A DbControl to use if the validation needs to access the database |
4740 |
05 Feb 09 |
nicklas |
@param context The current overview context |
4740 |
05 Feb 09 |
nicklas |
@param node The node object that represents item |
4740 |
05 Feb 09 |
nicklas |
@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 |
Validate a folder node after all child (item-type) nodes has been |
4768 |
18 Feb 09 |
nicklas |
added to the folder. This method must be called by node loaders |
4768 |
18 Feb 09 |
nicklas |
in all cases were it is theoretically possible that a folder node |
4768 |
18 Feb 09 |
nicklas |
can be created. Some validators may, for example, check on missing |
4768 |
18 Feb 09 |
nicklas |
items! |
4768 |
18 Feb 09 |
nicklas |
151 |
|
4768 |
18 Feb 09 |
nicklas |
@param dc A DbControl to use for database access |
4768 |
18 Feb 09 |
nicklas |
@param context The current overview context |
4768 |
18 Feb 09 |
nicklas |
@param folderNode The folder node, or null if no folder has been created |
4768 |
18 Feb 09 |
nicklas |
@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 |
} |