The PayloadSchemaRegistry can assign validators for simple properties, such as a primitive, a primitive wrapper, a date or a string. If the PayloadSchemaRegistry can determine the class of the property and there is a default validator for that class, it can automatically assign validators for simple properties. The include-all-simple flag indicates if all simple properties should be included when returning values. When the include-all-simple attribute is set to true on the schema or bean-property tag, the PayloadSchemaRegistry tries to create validators for all simple properties. Unless you use the include-all-simple flag, the automatic assigning of validator classes is optional. Note that you can also specify types and validator classes manually.

The default validators for simple properties are as follows. Note that these validators can be overridden by sub-classes that include customization logic to create target items, add additional constraints or perform other actions:

Simple Class

Default Validator

Boolean or boolean

Validators.BooleanValidator

Date

Validators.TimestampValidator

Double or double

Validators.DoubleValidator

Float or float

Validators.FloatValidator

Integer or int

Validators.IntegerValidator

Long or long

Validators.LongValidator

Short or short

Validators.ShortValidator

String

Validators.StringValidator

How to Validate Simple Properties

The property tag validates simple properties. In the following example the PayloadSchemaRegistry reviews stringOne and assigns a default validator for the string. By default, included properties appear in the output and can be updated:

<payload-schemas>
  <schema id="id1">
    <bean class="atg.my.TestBean"/>
    <property name="stringOne" required="true"/>
  </schema>
</payload-schemas>

If you want to expose the simple property of a sub-bean as a property of its parent, use the internal-property-name attribute to specify a different internal name. For example, to expose a longDescription property from a bean’s backing repositoryItem property:

<property name="longDescription" internal-property-name="repositoryItem.
    longDescription"/>

Or, if you wanted to expose a map entry as a top-level property from a map, you might do the following:

<property name="greeting" internal-property-name="additionalAttributes.greeting"
    class="String"/>

You can extend the payload schema by using XML-combine and writing custom validators to support new data types or validation behavior. Validators are located in the atg.service.validator.Validator class.

How to Extend Simple Property Validators

The payload schema configuration can be extended using XML-combine, which creates custom validators that can be implemented to support new data types or behaviors. It is best to check for an existing validator before creating a new one.

Simple property validators should extend Validators.RequiredValidator and override the validateValue method. Start with a super.validateValue method to check for a required value. Validators that represent one of a limited number of options should extend Validators.OptionValidator, as it provides error messages that include a list of available options.

Non-updating validators, which are validators that do not implement UpdatingValidator, are used during updates to retrieve the value that will be set on the target item.

The following is an example of a simple property validator:

@Override
public Object validateValue(String pPropertyName, Object pPropertyValue,
     ValidatorContext<?> pContext) {
  Object value = super.validateValue(pPropertyName, pPropertyValue, pContext);

  if (value != null) {
    if (!isValidValue(value)) {
      String errorTxt =
        ValidationConstants.getResource(
          ValidationConstants.INVALID_VALUE,
          pContext.getPropertyPath(pPropertyName), value.toString());
      pContext.addException(this, errorTxt, pPropertyName, null);
      value = null;
    }
  }
  return value;
}

If the value returned is not null, the example code validates the value. Note that the value might be null because the super.validateValue method may find an error, or because the original value was null. If, instead, the input value is invalid, an error is entered using the ValidatorContext.addException method and returned as null.

You can extend a validator to handle dynamic properties by using the include-all-simple attribute on the schema or bean-property tag. Then use a property tag with writable="true" on the simple properties that should not be accepted as input. Use the Dynamo Server Admin to access the PayloadSchemaRegistry to identify the properties found.


Copyright © 1997, 2017 Oracle and/or its affiliates. All rights reserved. Legal Notices