Validating property values

Introduction

The "Validation" property of a property definition specifies the mechanism for validating the values of this property.

In most cases, properties are validated while the flow is being designed or just before it is activated. If there are any invalid properties, Switch refuses to activate the flow. For performance reasons, Switch does assume that the result of design-time validation remains valid for the duration of flow activation. While this assumption is correct in most production environments, it is not strictly true for all data types; for example a file path becomes invalid when the target file is removed.

Properties that contain a variable or a script expression are validated while the flow is running, since their value cannot be determined at design time. Just before each invocation of the jobArrived entry point, Switch performs run-time validation for all properties of the flow element that contain a variable or a script expression. If a property value is invalid, Switch fails the job with an appropriate error message.

Note that there is NO run-time validation before calling the timerFired entry point (or any of the other entry points). Using non-static property values from those entry points is risky anyway since there is no job context (and referencing job context from a script expression or variable in those circumstances has undefined results).

Validation at design time

Validation of a particular property value is performed at design time if isPropertyValueStatic() returns true for that property.

The following table describes the standard design-time validation for values entered by a particular property editor. Note that all property values are of data type string or string list.

Property editor

Design-time validation requires that the value…

Single-line text

Is non-empty

Password

Is non-empty

Number

Is non-empty and contains only decimal digits

Hours and minutes

Is non-empty and has the format "hh:mm" (including the colon) where h and m stand for a decimal digit, hh and mm include leading zero if needed, hh is in range 00..23 and mm is in range 00..59

No-yes list

Is one of the strings "No" or "Yes" (exact spelling and case)

Dropdown list

Is one of the custom strings provided for the dropdown list

Literal

Is the fixed string value selected from a predefined list

Choose file

Represents a valid absolute path and that a file exists at the path

Choose folder

Represents a valid absolute path and that a folder exists at the path

Regular expression

Is non-empty and has valid regular expression syntax

File type

Is non-empty and has valid filename pattern syntax

Select from library

Is one of the strings returned by the getLibraryForProperty entry point in the script

Multi-line text

Is non-empty

Script expression

N/A

Single-line text with variables

N/A (if the value contains no variables: Is non-empty)

Multi-line text with variables

N/A (if the value contains no variables: Is non-empty)

Condition with variables

N/A

File patterns

Has at least one item and each item has valid filename pattern syntax

Folder patterns

Has at least one item and each item has valid filename pattern syntax

File types

Has at least one item and each item has valid filename pattern syntax

String list

Has at least one item and each item is non-empty

Select many from library

Has at least one item and each item is one of the strings returned by the getLibraryForProperty entry point in the script

External editor

Represents a valid absolute path and that a file exists at the path

Validation at run time

Validation of a particular property value is performed at run time if isPropertyValueStatic() returns false for that property.

In this case the property editor used to enter the source value (example: the script expression or text with variables) is no indication for the appropriate validation scheme. Therefore, as a general principle, standard run-time validation allows the computed property value to conform to the validation scheme of ANY of the property's property editors.

Specifically, the validation algorithm works as follows:


Property editor

Run-time validation scheme

Single-line text

--

Password

--

Number

Same as design-time scheme

Hours and minutes

Same as design-time scheme

No-yes list

Same as design-time scheme, or a Boolean value (*)

Dropdown list

Same as design-time scheme

Literal

Same as design-time scheme

Choose file

Same as design-time scheme

Choose folder

Same as design-time scheme

Regular expression

Same as design-time scheme, or a Boolean value (*)

File type

Same as design-time scheme

Select from library

Same as design-time scheme

Multi-line text

--

Script expression

--

Single-line text with variables

--

Multi-line text with variables

--

Condition with variables

--

File patterns

Same as design-time scheme (for one item), or a Boolean value (*)

Folder patterns

Same as design-time scheme (for one item), or a Boolean value (*)

File types

Same as design-time scheme (for one item), or a Boolean value (*)

String list

--

Select many from library

Same as design-time scheme (for one item)

External editor

Same as design-time scheme

(*) a Boolean value is represented by one of the strings "true" or "false"

Validation example

Consider a property that specifies a property set which can be provided as a file or it can be part of an external library. The property is set to standard validation and it has the following property editors:


For the first two editors, validation is always performed at design time. For the last two editors, validation is performed at run time (except if the single-line text does not contain any variables). In all cases, the property value is guaranteed to contain one of the following:


For most use cases it can be assumed that these values are mutually exclusive, and that the script code can tell the data types apart from looking at the value. If needed however, the script code can check which editor has been used to enter the value.