JavaScript Extension Development API for Oracle Visual Builder Cloud Service - Classic Applications

Class: operation/js/api/Condition

General representation of condition useable for data restriction.

Conditon is basically filtering rule which can be applied by the client to fetch only records matching some restriction. Conditon is always either simple (represented by a single filtering rule) or composite (represented by multiple filtering rules combined using AND/OR operators) object.

Version:
  • 15.4.5
Source:
See:

Methods

visit(conditionVisitor)

stable API

Interpret this Condition by the given ConditionVisitor.

Allows author of the BOP to interpret incoming Conditions and transform them into proper URL query or generally process them any way (s)he need.

Parameters:
Name Type Description
conditionVisitor bop/js/spi/operation/ConditionVisitor

ConditionVisitor to interpret this Condition

Version:
  • 17.1.1
Source:
See:
Example

Using ConditionVisitor instance in Operation.perform(..) method implementation to turn incoming Condition instance into proper URL querying resulted data.

Let's assume MyConditionVisitor is implemented so that the query is always appended at the end of the URL. For example if the Condition is declared to "Find all employees where Firstname equals 'Martin' AND Lastname equals 'Janicek'", the resulted URL can look like this: 'http://example.com/employee?q= Firstname EQ Martin & Lastname EQ Janicek'

define([
    'operation/js/api/OperationResult',
    '{{package}}/js/MyConditionVisitor'
], function (
    OperationResult,
    MyConditionVisitor
) {

    var Employee = function() {
    };

    Employee.find = function(operationData) {
        var results = [];
        var baseURL = 'http://example.com/employee';
        var condition = operationData.getQuery().getCondition();

        // The visitor is there to turn Condition abstraction into
        // whatever shape data provider expects on it's input
        var resultURL = condition.visit(new MyConditionVisitor(baseURL));

        $.ajax({
            url: resultURL,
            type: 'GET'
        }).done(function(response) {
            // Because the URL was change by the visitor, we should have filtered results here
            fulfil(OperationResult.success(response));
        });
    };

    return Employee;
});