Custom Validation for the Admin Application

This section defines how you configure the custom validation for the KonaKart Admin application

CustomValidaton.properties file

From release 2.2.3.0 of KonaKart it is possible to modify the default field validation in certain parts of the Admin App.

A new properties file is provided, called CustomValidation.properties. You will find this in the classes directory of the konakartadmin webapp.

The format and description of this file is defined within the file itself, but an extract is as follows:


# ------------------------------------------------------------------
#
#  K O N A K A R T   C U S T O M   V A L I D A T I O N
#
# ------------------------------------------------------------------
# Parameters to define custom validation in the KonaKart Admin App
# ------------------------------------------------------------------

# ------------------------------------------------------------------
# If no custom validations are defined (or this file is removed) the
# default validation rules are used in the KonaKart Admin App.
#
# If you define custom validations in this file they will override
# the default rules defined in the KonaKart Admin App.
# Therefore, you only need to define the custom validation rules
# that are different to the defaults.
# ------------------------------------------------------------------

# ------------------------------------------------------------------
# If your intention is to increase the number of characters allowed
# in the database for a certain quantity, you will have to modify 
# the characteristics of that column in the database first.   If you
# then wish to validate the attribute in the KonaKart Admin App to
# allow for the increased column width... you also need to add your
# custom validation to this file
# ------------------------------------------------------------------

# ------------------------------------------------------------------
# Format:
#
# ClassName.Attribute = [min];[max]
#
# If min or max are not specified they will not be checked.
# 

Therefore, if you wanted to change the validation on the Product SKU field in the Admin App, you would specify:


Product.sku               = 1;18

Fields Supported by Custom Validation

Only a certain subset of fields can have their validation overridden in this way, but if you need other fields to be made available for validation please get in touch with support at KonaKart.

All of these fields currently supported are listed in the CustomValidation.properties file. By default they are commented out.

CustomValidaton Using a Custom Engine

If you have validation requirements that cannot be satisfied using the simpler properties-file-based techniques described above you can add custom validation using a Custom KKAdmin engine.

In order to do this you need to know which APIs are called when you save a record in the Admin App. Which API is used is usually obvious from the name (eg. editCustomer, updateCustomer etc) but if not you can establish this by enabling the DEBUG logging on the konakartadmin webapp. Once you know the interface move the Custom Engine implementation java source file from the "custom/adminengine/gensrc" directory tree to the "custom/adminengine/src" tree and rebuild your custom engine. Refer to the "Engine Customization" section in the User Guide for details).

For example, if you want to add some validation before saving an Order you should move ".\custom\adminengine\gensrc\com\konakartadmin\app\UpdateOrder.java" to ".\custom\adminengine\src\com\konakartadmin\app\UpdateOrder.java". (Other Order-saving APIs may also need to be moved and customised depending on what's being saved).

Having moved the source file you need to add your validation code. An example is:


public void updateOrder(String sessionId, int orderId, int orderStatus, String comments, 
                        boolean notifyCustomer, AdminOrderUpdate updateOrder) 
                                                                    throws KKAdminException
{
    /**
        Add your custom validation before the record is saved by updateOrder.
     */

    if (Your_Own_Custom_Validation(orderId) == false)
    {
        // Validation failed so we throw an exception back to the Admin App
        throw new KKAdminException("Validation Exception", true /* hideMoreDetails button */);
    }

    /**
        Process normally because the validation was successful.
     */

    kkAdminEng.updateOrder(sessionId, orderId, orderStatus, comments, notifyCustomer, 
                           updateOrder);
}

Note that when throwing an exception in your custom engine code you have the choice to "HideMoreDetails" (see the throw statement in the example above). This allows you to hide the default "More Details" button on the error message dialog box in the Admin App when this exception is caught. This allows you to hide technical validation details from the user (that are displayed by default when the "More Details" button is clicked) if you so wish.