Changes between Initial Version and Version 1 of ValidationHook


Ignore:
Timestamp:
08/02/12 13:08:55 (12 years ago)
Author:
heikki
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ValidationHook

    v1 v1  
     1= Dependendy Injection =
     2
     3|| '''Date''' || 2012/08/03 ||
     4|| '''Contact(s)''' || [http://wiki.osgeo.org/wiki/User:Heikki Heikki Doeleman] ||
     5|| '''Last edited''' || ||
     6|| '''Status''' || draft ||
     7|| '''Assigned to release''' || 2.8.1 ||
     8|| '''Resources''' || [http://www.agiv.be/gis/ AGIV] ||
     9|| '''Code''' ||  ||
     10|| '''Ticket''' || TBD ||
     11
     12== Overview ==
     13
     14Some users wish to add custom code to be invoked right after validation took place. A pluggable hook mechanism can provide for this while making it easy for them to keep their specific implementation code separate from the standard GeoNetwork code, thus easing future migration efforts for them. The pluggable validation hook mechanism is similar to the existing pluggable !StatusActions hook. No default implementation will be provided.
     15
     16=== Proposal Type ===
     17 * '''Type''': !GeoNetwork
     18 * '''App''': !GeoNetwork
     19 * '''Module''': web
     20
     21=== Links ===
     22 
     23 * '''Email discussions''':
     24 * '''IRC discussions''':
     25 
     26=== Voting History ===
     27
     28 * None as yet
     29
     30----
     31
     32== Motivations ==
     33
     34Pluggable 'hooks' are a mechanism that allows users to plug in their own, specific extensions to !GeoNetwork code, that will be executed at a specific point in the !GeoNetwork program flow, if any implementation is provided by the users. It makes it more easy for said users to extend !GeoNetwork without mixing up their own code with the !GeoNetwork code. This makes future migrations to new versions of !GeoNetwork easier. If users create an implementation that's deemed useful to the general audience, these might be made part of the !GeoNetwork code base, as ready-made, optional extensions.
     35
     36The existing !StatusActions hook is an example of such a pluggable hook in !GeoNetwork.
     37
     38== Proposal ==
     39
     40Currently, a standard post-validation is invoked from 2 places in !DataManager, 'saveValidationStatus' which saves a summary of the validation result to the database. This proposal would replace these calls with a call to a new method 'postValidation' which first does the same as does 'saveValidationStatus' now, and then invokes the pluggable Validation hook, if any is configured.
     41
     42It does this in a manner similar to the !StatusActions hook: a Factory class takes the class name of the hook implementation from config.xml. If none is configured, nothing happens and the program behaves exactly as without this proposal. If one is configured, reflection is used to instantiate the class, execute an 'init()' method, and execute an 'onValidate' method.
     43
     44User-provided implementations of the Validation hook must conform to the contract of this interface:
     45
     46{{{
     47public interface IValidationHook {
     48
     49    /**
     50     * Invoked when validation has finished. The variable length Object arguments should accommodate any required
     51     * input among different implementations.
     52     *
     53     * @param args zero or more implementation-dependent arguments
     54     * @throws ValidationHookException hmm
     55     */
     56    public void onValidate(Object... args) throws ValidationHookException;
     57
     58    /**
     59     * Initializes validation hook.
     60     *
     61     * @param context
     62     * @param dbms
     63     * @throws ValidationHookException
     64     */
     65    public void init(ServiceContext context, Dbms dbms) throws ValidationHookException;
     66}
     67}}}
     68
     69As you can see the 'onValidate' method can take any number of arguments, of any type, which should allow maximum flexibility for users' needs.
     70
     71
     72For convenience, an abstract class implementing this interface's 'init()' method is provided in !GeoNetwork. This implementation just provides some of the usual suspects that are necessary to have at hand to do almost anything in !GeoNetwork, namely the !ServiceContext, !AccessManager, !DataManager, and Dbms. Note that user implementations of the Validation hook are not required to use this abstract base class if they have different needs; they can just implement the interface directly.
     73
     74The abstract base class is
     75
     76{{{
     77public abstract class AbstractValidationHook implements IValidationHook {
     78
     79    private ServiceContext context;
     80    private AccessManager am;
     81    private DataManager dm;
     82    private Dbms dbms;
     83
     84    /**
     85     * Initializes the ValidationHook class with external info from GeoNetwork.
     86     *
     87     * @param context
     88     * @param dbms
     89     */
     90    public void init(ServiceContext context, Dbms dbms) {
     91        System.out.println("AbstractValidationHook init");
     92        this.context = context;
     93        this.dbms = dbms;
     94
     95        GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
     96        am = gc.getAccessManager();
     97        dm = gc.getDataManager();
     98    }
     99
     100}
     101}}}
     102
     103
     104=== Advantages: ===
     105
     106   * The pluggable Validation hook provides a non-intrusive extension point to !GeoNetwork where users may plug in their own implementation, should they want to.
     107
     108=== Use cases: ===
     109
     110   * At least 1 user wants to have this functionality so they can easily extend !GeoNetwork without mixing in their own code with !GeoNetwork's.
     111
     112=== Disadvantages: ===
     113   * none
     114
     115
     116=== Configuration ===
     117
     118In config.xml's appHandler element, a Validation hook implementation can be specified, as follows (example):
     119
     120{{{
     121
     122<appHandler class="org.fao.geonet.Geonetwork">
     123   ...
     124   <param name="validationHook" value="com.esri.geonetwork.extensions.MyValidationHook"/>
     125   ...
     126</appHandler>
     127
     128}}}
     129
     130
     131=== Backwards Compatibility Issues ===
     132
     133None.
     134
     135== Risks ==
     136
     137 * none
     138
     139== Participants ==
     140 * As above