BPS Script API  2.24.4
bps::validator::Base Class Reference

The Base class serves as base for all field validators. 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...
 

Protected Member Functions

 Base (Datastore aDatastore, String aTable)
 
Boolean checkLength (Object aRecord, String aColumn)
 Checks if the value length exceeds the maximum column length. More...
 
Boolean checkMask (Object aRecord, String aColumn)
 Checks if the column value is valid for the mask. More...
 
Boolean checkNotNull (Object aRecord, String aColumn)
 Checks if the given column is not null. More...
 
Boolean checkReference (Object aRecord, String aColumn, String aRefTable)
 Checks if the given column is either null, or references the primary key of an existing row in aRefTable. More...
 
Boolean checkUnique (Object aRecord, String aColumn)
 Checks if the column value is unique within the whole table. More...
 
Boolean checkUnique2 (Object aRecord, String aColumn1, String aColumn2)
 Checks if the combination of 2 columns is unique. More...
 
Boolean checkUniqueNotDeleted (Object aRecord, String aColumn)
 Checks if the column value is unique within the whole table, excluding records with "deleted" status from the check ('d' in column c_status). More...
 
Boolean checkUniqueOrNull (Object aRecord, String aColumn)
 Checks if the column value is either NULL or unique within the whole table. More...
 
void clear ()
 Clears the status by setting lastStatus = bps.FieldValidator.StatusOK and lastColumn = ''. More...
 

Properties

Datastore datastore
 [protected] Datastore object used by the validator. More...
 
String lastColumn
 Column on which an error occurred, set by the check() execution. More...
 
Status lastStatus
 The status set by the check() execution. More...
 
Object masks
 [protected] Mask cache used by checkMask(). More...
 
String table
 [protected] The main table handled by the validator. More...
 

Detailed Description

The Base class serves as base for all field validators.

The validator needs to be implemented in a distinct js file and placed somewhere in the file system, typically in the BPS program folder under scripts/validators. The file must be registered in the global system settings in folder Validators as key / value pair, where the key is the table name and the value is the absolute or relative script file path/name.

Below is a complete sample validator implementation for the t_countries table. (Check out scripts/validators/default/‍* for more samples)

// Load validator base class:
importExtension('bps.validator');
// Implement validator, name must be 'BpsFieldValidator' in any case:
function BpsFieldValidator(aDatastore)
{
// call constructor of the base class:
bps.validator.Base.call(this, aDatastore, 't_countries');
} // BpsFieldValidator
// Set prototype of our validator to be the base class:
BpsFieldValidator.prototype = new bps.validator.Base();
// Implement our custom check method, using the properties and
// messages of the base class:
BpsFieldValidator.prototype.checkUpdate = function(aRecord)
{
// Clear the last results
this.lastColumn = '';
// Do the checks, returning true on success:
return this.checkMask(aRecord, 'c_code')
&& this.checkUnique(aRecord, 'c_code')
&& this.checkMask(aRecord, 'c_name');
} // checkUpdate
void importExtension(String aExtensionName)
Imports the named extension into the script engine.
This class implements the BPS table field validator.
Definition: bps.FieldValidator.js:40
@ StatusOK
All checks passed ok.
Definition: bps.FieldValidator.js:47
The Base class serves as base for all field validators.
Definition: bps.validator.js:51
Boolean checkMask(Object aRecord, String aColumn)
Checks if the column value is valid for the mask.
String lastColumn
Column on which an error occurred, set by the check() execution.
Definition: bps.validator.js:58
Status lastStatus
The status set by the check() execution.
Definition: bps.validator.js:58
Boolean checkUnique(Object aRecord, String aColumn)
Checks if the column value is unique within the whole table.
Boolean checkUpdate(Object aRecord)
Checks if the record data is valid for update.
The bps.validator extension is a namespace holding the base class for field validators.
Definition: bps.validator.js:7
The bps extension is a namespace assembling general BPS properties and functions.
Definition: bps.AsyncIO.js:1

Constructor & Destructor Documentation

◆ Base()

bps::validator::Base::Base ( Datastore  aDatastore,
String  aTable 
)
protected
Parameters
aDatastoreDatastore object in connected state.
aTableName of the main table the validator operates on.

Member Function Documentation

◆ checkDelete()

Boolean bps::validator::Base::checkDelete ( Object  aRecord)

Checks if the record data is valid for delete.

Stops on first fail and sets the values of properties 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::validator::Base::checkInsert ( Object  aRecord)

Checks if the record data is valid for insert.

Stops on first fail and sets the values of properties lastStatus and lastColumn.

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

◆ checkLength()

Boolean bps::validator::Base::checkLength ( Object  aRecord,
String  aColumn 
)
protected

Checks if the value length exceeds the maximum column length.

Sets lastStatus and lastColumn in case the check fails, and returns false.

The check is only done when aRecord contains aColumn as property, otherwise it will just return true.

Parameters
aRecordThe record to check, where the properties hold the column values.
aColumnName of the column value to check.
Returns
True if ok, false otherwise.

◆ checkMask()

Boolean bps::validator::Base::checkMask ( Object  aRecord,
String  aColumn 
)
protected

Checks if the column value is valid for the mask.

Sets lastStatus and lastColumn in case the check fails, and returns false.

The check is only done when the mask for aColumn is found and aRecord contains aColumn as property, otherwise it will just return true.

Parameters
aRecordThe record to check, where the properties hold the column values.
aColumnName of the column value to check.
Returns
True if ok, false otherwise.

◆ checkNotNull()

Boolean bps::validator::Base::checkNotNull ( Object  aRecord,
String  aColumn 
)
protected

Checks if the given column is not null.

Parameters
aRecordThe record to check, where the properties hold the column values.
aColumnName of the column value to check.
Returns
True if ok, false otherwise.

◆ checkReference()

Boolean bps::validator::Base::checkReference ( Object  aRecord,
String  aColumn,
String  aRefTable 
)
protected

Checks if the given column is either null, or references the primary key of an existing row in aRefTable.

Parameters
aRecordThe record to check, where the properties hold the column values.
aColumnName of the column value to check.
aRefTableName of the referenced table.
Returns
True if ok, false otherwise.

◆ checkUnique()

Boolean bps::validator::Base::checkUnique ( Object  aRecord,
String  aColumn 
)
protected

Checks if the column value is unique within the whole table.

Sets lastStatus and lastColumn in case the check fails, and returns false. The check is only done when aRecord contains c_key and aColumn as properties, otherwise it will return true.

Parameters
aRecordThe record to check, where the properties hold the column values.
aColumnName of the column value to check.
Returns
True if ok, false otherwise.

◆ checkUnique2()

Boolean bps::validator::Base::checkUnique2 ( Object  aRecord,
String  aColumn1,
String  aColumn2 
)
protected

Checks if the combination of 2 columns is unique.

Sets lastStatus and lastColumn in case the check fails, and returns false.

The check is only done when aRecord contains c_key, aColumn1 and aColumn2 as properties, otherwise it will return true.

Parameters
aRecordThe record to check, where the properties hold the column values.
aColumn1Name of the first column.
aColumn2Name of the second column.
Returns
True if ok, false otherwise.

◆ checkUniqueNotDeleted()

Boolean bps::validator::Base::checkUniqueNotDeleted ( Object  aRecord,
String  aColumn 
)
protected

Checks if the column value is unique within the whole table, excluding records with "deleted" status from the check ('d' in column c_status).

Used to check the column c_id in tables t_articles and t_partners for example. Sets lastStatus and lastColumn in case the check fails, and returns false.

Parameters
aRecordThe record to check, where the properties hold the column values.
aColumnName of the column value to check.
Returns
True if ok, false otherwise.

◆ checkUniqueOrNull()

Boolean bps::validator::Base::checkUniqueOrNull ( Object  aRecord,
String  aColumn 
)
protected

Checks if the column value is either NULL or unique within the whole table.

Sets lastStatus and lastColumn in case the check fails, and returns false.

The check is only done when aRecord contains c_key and aColumn as properties, otherwise it will return true.

Parameters
aRecordThe record to check, where the properties hold the column values.
aColumnName of the column value to check.
Returns
True if ok, false otherwise.

◆ checkUpdate()

Boolean bps::validator::Base::checkUpdate ( Object  aRecord)

Checks if the record data is valid for update.

Stops on first fail and sets the values of properties lastStatus and lastColumn.

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

◆ clear()

void bps::validator::Base::clear ( )
protected

Clears the status by setting lastStatus = bps.FieldValidator.StatusOK and lastColumn = ''.

Usually called at begin of check().

Property Documentation

◆ datastore

Datastore bps::validator::Base::datastore
read

[protected] Datastore object used by the validator.

To be set via constructor only, dont change after.

◆ lastColumn

String bps::validator::Base::lastColumn
readwrite

Column on which an error occurred, set by the check() execution.

Empty in case all checks passed.

◆ lastStatus

Status bps::validator::Base::lastStatus
readwrite

The status set by the check() execution.

Set to bps.FieldValidator.StatusOK when all checks passed.

◆ masks

Object bps::validator::Base::masks
readwrite

[protected] Mask cache used by checkMask().

Properties are the already fetched masks for columns previously processed. For columns where no mask was found, an empty string is stored as mask.

◆ table

String bps::validator::Base::table
read

[protected] The main table handled by the validator.

To be set via constructor only, dont change after.


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