The site validator can be used to check for proper configuration and the existence of certain objects to ensure your application will run properly, such as:
- required schema objects, such as tables and columns
- the existence of required data in tables
A validator can either be site wide, or scoped to run at a specific container level. When scoped to a container, you can control whether or not it is applicable for a given container. The boolean flag isSiteScope() controls whether the validator is site-scoped. The boolean flag shouldRun() controls whether the validator is applicable to a given container.
Your validator should implement SiteValidationProvider, or more likely, the subclass SiteValidationProviderImpl. The methods getName() and getDescription() implement the name and description for the validator. The method runValidation() returns a SiteValidationResultList of validation messages that will be displayed on the validation page at
Admin > Site > Admin Console > Site Validation. The messages can be set at different levels of severity: info, warn, or error. Errors will appear in red on the validation page. There are helper methods on SiteValidationResultList to aid in building the list. To build compound messages, SiteValidationResult behaves much like a StringBuilder, with an append() that returns itself.
Implementation Steps:
- Implement SiteValidationProvider
- Implement runValidation():
- Instantiate a SiteValidationResultList
- For each of your validation steps, call SiteValidationResultList.addInfo(), addWarn() or addError()
- In your module's doStartup(), call SiteValidationService.registerProvider() to register your validator
Sample Code
An example validator that checks whether any Guest users have read or edit permissions:
PermissionsValidator.java.