Input mappings allow you to add parameters to a query so that you can set the parameter value when executing the query. For example, when you define a query as
SELECT *, FROM TEST_TABLE, WHERE ID=1, an input mapping is a parameter that sets the value of ID.
Clicking the Add New Input Mappings link brings up the following page.
It provides the following options:
Note that ARRAY parameter type cannot be used with the QUERY_STRING data type (SQL type).
Default values help you automatically assign a value to a parameter when a user has not entered a specific parameter value in a request. Default values are added when defining queries. Therefore, this value gets automatically added to the q uery if it is ignored by the user.
You can refer to Internal Property Values using Default Values. You can use special system variables that are defined as default values. At the moment, it only provides a variable for retreiving the username of the current user authenticated in a secured data service. You can access this variable as follows:
For a demonstration of the usage of default values, see Default Values Sample.
Validators are added to individual input mappings in a query. Input validation allows data services to validate the input parameters in a request and stop the execution of the request if the input doesn’t meet required criteria. WSO2 Data Service Server provides a set of built-in validators for some of the most common use cases. It also provides an extension mechanism to write custom validators.
Validates if an integer value is in the specified range. The validator requires a minimum and a maximum value to set the range. For example,
Validates if a floating point is in the specified range. The validator requires a minimum and a maximum value to set the range. For example,
Validates the string length of a given parameter against a specified length. For example,
Validates the string value of the parameter against a given regular expression. For example,
Used to add your own validation logic by implementing the interface
org.wso2.carbon.dataservices.core.validation.Validator. The definition of the interface is as follows:
If the validation fails, the validate method in the interface by default throws an exception of type
ValidationException . The parameters of the method are as follows:
ValidationContext, which contains information about the full set of parameters passed into the request. When the validation logic depends on other parameters, the validation context can be used to check the names/values of the rest of the parameters.
ParamType, which represents the value of the parameter to be validated. It is either
After creating a custom validator class, package it in a JAR file and place in in
<DSS_HOME>/repository/component/lib directory, which is the server's classpath location for external libraries.