Samples > Starter stores > Starter store enhancements > IBM Gift Center for the Madisons starter store > Work with the sample store pages


IBM Gift Center for Madisons: Creating a custom business validation rule

IBM Gift Center for the Madisons starter store provides a business rule validation framework that you can customize. If the default set of Gift Center business validation rules do not meet the needs, you can create new rules for the gift registry or modify the existing rules.

When customers create, edit, or delete gift registries, their actions are validated against a set of rules. If their actions do not meet the rule definition, an error message displays and the changes are not saved to the database. Here are a few examples of default Gift Center business validation rules:

For a complete list of default business validation rules for Gift Center for the Madisons starter store, see the class summaries in Gift Center rules validation classes.

The Gift Center business rule validation framework validates Create, Update and Delete actions for gift lists. By customizing the framework, you can impose any kind of business rules for these actions when they occur. When creating a new business validation rule, specify whether the validation applies on a Create, Update, or Delete action, or on a combination of these actions. The framework executes business validation rules for Create actions automatically. For Delete and Update actions, business validation rules must be explicitly invoked from the mediators. The reason for this difference is that when Create actions occur, all gift list data is available to validate against the rule; however, when Update or Delete actions occur, only partial gift list data might be available.


Example

Consider a store that is promoting the gift registry feature to customers free of cost, but with the following limitation: a customer can create only one gift registry per event type. The available event types are Wedding, Birthday, Anniversary, or Other. This limitation requires a new business validation rule that prevents customers from creating more than one gift registry per event type. The customization procedures in this section provide code samples that illustrate how to implement this customization scenario.

  1. IBM Gift Center for Madisons: Adding the new business validation rule to the GRREGRULE table
    To implement a new business validation rule, add an entry for the rule to the GRREGRULE table. This table contains all Gift Center business validation rules. Each rule must be represented by an ID in the table.

  2. IBM Gift Center for Madisons: Creating a new validator class for the business validation rule
    Create a Java class containing the logic to interpret the business validation rule and report an error when customers break the rule on the storefront. This class can either implement the GiftListRulesValidator interface or extend from the AbstractGiftListRulesValidator class.

  3. IBM Gift Center for Madisons: Registering the new business validation rule
    Register the new rule in the rule validator extension configuration file, wc-GiftList-RuleValidator-ext.xml. This file is provided for customization to map business validation rules in the GRREGRULE table to the correct validator class.

Related reference

IBM Gift Center for Madisons: Directory structure

Customize IBM Gift Center for Madisons


+

Search Tips   |   Advanced Search