BPS Script API  2.24.4
bps::FieldValidator Class Reference

This class implements the BPS table field validator. More...

Public Types

enum  Status { StatusOK = 0 , StatusMissing = 1 , StatusInvalid = 2 , StatusDuplicate = 3 , StatusBadRef = 4 }
 Return status from check function. More...
 

Public Member Functions

Boolean checkDelete (Object aRecord)
 Checks if the record data is valid for delete. More...
 
Boolean checkInsert (Object aRecord)
 Checks if the record data is valid for insert. More...
 
Boolean checkUpdate (Object aRecord)
 Checks if the record data is valid for update. More...
 
 FieldValidator (Datastore aDatastore, String aTable)
 
String message (Status aStatus)
 Get standard message for a status. More...
 

Properties

String lastColumn
 Column on which the the last error occurred. More...
 
Status lastStatus
 The status set by the recent called check method. More...
 

Detailed Description

This class implements the BPS table field validator.

The validator must be registered in the central system settings: In folder Validators there must be a key/value pair where the key is the table name, and the value the path to the validation script.

Check out the standard validators in directory [bpsdir]/scripts/validators as reference how to implement a validator.

Example usage:

var ds = new bps.Datastore();
with (ds) {
connection = 'pgprod';
username = 'prod';
password = 'prod1234';
if (!loadConnection())
throw Error("Invalid connection.\nKnown connections are: "+bps.Datastore.connections);
connect();
purgeActors();
checkin();
}
var rec = { c_key: 100, c_code: 'CH', c_name: 'Switzerland' };
var fv = new bps.FieldValidator(ds,'t_countries');
print(fv.checkUpdate(rec));
print(fv.lastStatus);
print(fv.lastColumn);
ds.checkout();
ds.disconnect();
void print(...)
Print the expressions (applying toString() if necessary) to the console standard output (stdout),...
void importExtension(String aExtensionName)
Imports the named extension into the script engine.
The datastore class is used to access the BPS databases.
Definition: bps.Datastore.js:10
Array connections
A list of all connections that have been declared in the BPS configuration program.
Definition: bps.Datastore.js:147
This class implements the BPS table field validator.
Definition: bps.FieldValidator.js:40
The bps extension is a namespace assembling general BPS properties and functions.
Definition: bps.AsyncIO.js:1
@ Error
Some unspecified error happened.
Definition: bps.js:26

Member Enumeration Documentation

◆ Status

Return status from check function.

Enumerator
StatusOK 

All checks passed ok.

StatusMissing 

Mandatory field, but no value (null/empty).

StatusInvalid 

The input is invalid (too short, too long, wrong data).

StatusDuplicate 

Unique field, but same value found in other record.

StatusBadRef 

Key not found in referenced relation table.

Constructor & Destructor Documentation

◆ FieldValidator()

bps::FieldValidator::FieldValidator ( Datastore  aDatastore,
String  aTable 
)
Parameters
aDatastoreThe datastore connection to use.
aTableThe name of the table to validate for.

Member Function Documentation

◆ checkDelete()

Boolean bps::FieldValidator::checkDelete ( Object  aRecord)

Checks if the record data is valid for delete.

Stops on first fail and sets the values for lastStatus() and lastColumn().

Parameters
aRecordThe record to check, where the properties hold the column values.
Returns
True if all column checks passed, false otherwise.

◆ checkInsert()

Boolean bps::FieldValidator::checkInsert ( Object  aRecord)

Checks if the record data is valid for insert.

Stops on first fail and sets the values for lastStatus() and lastColumn().

Parameters
aRecordThe record to check, where the properties hold the column values.
Returns
True if all column checks passed, false otherwise.

◆ checkUpdate()

Boolean bps::FieldValidator::checkUpdate ( Object  aRecord)

Checks if the record data is valid for update.

Stops on first fail and sets the values for lastStatus() and lastColumn().

Parameters
aRecordThe record to check, where the properties hold the column values.
Returns
True if all column checks passed, false otherwise.

◆ message()

String bps::FieldValidator::message ( Status  aStatus)

Get standard message for a status.

Parameters
aStatusThe status to get the message for.
Returns
Standard message for failure status. For StatusOK an empty string is returned.

Property Documentation

◆ lastColumn

String bps::FieldValidator::lastColumn
read

Column on which the the last error occurred.

Empty in case last check passed.

◆ lastStatus

Status bps::FieldValidator::lastStatus
read

The status set by the recent called check method.

 


The documentation for this class was generated from the following file: