Validation package

Guidewire provides the following validation-related classes and interfaces in the gw.validation package.

Class or Interface

Description

PCValidation

Interface that all validation classes must implement.

PCValidationContext

Class that takes a ValidationLevel and creates a new PCValidationResult object during initialization.

PCValidationBase

Abstract convenience class that takes a PCValidationContext instance.

PCValidationResult

Class that contains the object methods to use in generating warnings and errors.

The following object diagram illustrates these relationships.


Object diagram of PolicyCenter validation classes

PCValidation

All Gosu validation classes must implement the PCValidation interface. Any Gosu class (or any interface defined in Gosu) that implements PCValidation can perform validation logic. This interface contains a single validate method.

Classes that implement this interface can create methods that test for a single issue and call those method from their implementation of the validate method. For an example, see PALineDriversValidator.gs. Through object inheritance, the method doValidate does the validation:

override function doValidate() {
  qualifiedGoodDriver()
  appliedGoodDriverDiscount()
  licenseInfoRequired()
  ...
}

PCValidationBase

Class PCValidationBase is a convenience class that implements PCValidation. Its constructor takes a validation context (PCValidationContext) instance that holds the level at which to perform validation and the validation results (warnings and errors).

PCValidationBase provides a number of getter property methods. Some of the more important are:

property get Context() : PCValidationContext
property get Level()   : ValidationLevel
property get Result()  : PCValidationResult

PCValidationContext

Class PCValidationContext takes a ValidationLevel and creates a new PCValidationResult during initialization.

This class has several important methods for use in managing validation. The following list describes each briefly. However, for the most complete information, consult the Gosu API Reference documentation associated with the method.

Method

Description

addToVisited(validation, methodName)

Use to track a complete listing of the checks that PolicyCenter performed during the validation. The method returns false if the given validation.Name and methodName have been visited before. You can use this to determine that this particular validation method does not need to be checked again.

This method only checks against the class name, not the validation object itself (using hasVisited). Thus, for example, if you are validating multiple vehicles, you can not discern whether a method has been visited for a specific vehicle.

hasVisited(className, methodName)

Use to test whether the given combination of validation class name and method name have been seen before. If so, the method returns true.

isAtLeast(ValLevel)

Use to perform a test to determine if the level specified by ValidationContext is at least valLevel. This method does not actually perform validation. Instead, you use the information to determine whether you want to perform validation.

showVisited()

Use to produce a string that lists the validation methods that were visited as validation was performed with the provided Context. You can then use this string for debugging.

resetVisited()

Resets the set of visited validation methods.

raiseExceptionIfProblemsFound()

Throws an EntityValidationException if either errors or warnings have been added to the validation context.

raiseExceptionIfErrorsFound()

Throws an EntityValidationException only if errors have been added to the validation context.

PCValidationResult

Class PCValidationResult holds the warnings and errors added by the validation implementation classes as problems are discovered. Warnings are non-blocking. The user can clear warnings and continue. In contrast, errors block further progress until the user resolves the problem.

PCValidationResult contains a number of object methods that you use in generating warnings and errors. The following list describes the more important ones briefly. However, for the most complete information, consult the Gosu API Reference documentation associated with the method.

Method

Description

addError

Use to add a general error message. This method takes the following arguments, of which the first three are mandatory and the last optional:

  • keyable bean (entity) that is the source of the error
  • validation level associated with the error
  • error reason to display to users
  • ID of the wizard step where the error can be corrected

If you supply a wizardstepID, the method creates a link to the wizard step with ID wizardStepId if the error is not in the current step.

addFieldError

Use to add an error message specifically associated with a field on the given keyable bean as defined by the relative FieldPath. This method takes the following arguments:

  • keyable bean (entity) that is the source of the error
  • field path to the field that must be changed to resolve the error
  • validation level associated with the error
  • error reason to display to users
  • ID of the wizard step where the error can be corrected

If you supply a wizardstepID, the method creates a link to the wizard step with ID wizardStepId if the error is not in the current step.

addWarning

Similar to the addError method, except that it generates a warning rather than an error.

addFieldWarning

Similar to the addFieldError method except that it generates a warning rather than an error.

PCValidationResult inherits several different forms of the reject method from the (platform) ValidationResult class (which it subclasses).

Method form

Description

reject

Indicates a problem and provides an error message, but does not point to a specific field.

rejectField

Indicates a problem with a particular field, provides an error message, and indicates the correct field to fix.