new bop/js/api/operation/OperationBuilder(params)
stable API
Builds Operation instance which can be registered into custom BOP.
Building Operation means describing exactly what the underlying REST call is capable to do. The whole ABCS UI is going to be set based on the configuration done here.
The real REST call is being made by Operation.perform(..) method which is the function you pass into constructors "performs" object literal attribute. This REST-call function is expected to be able of doing everything described by the Operation configuration which you're building here.
Few examples of how different configurations can affect resulted Abcs UI and how that affects real REST call.
All Operations with type set to READ_MANY
will be available when ABCS Business User is dropping table onto an empty page. Furthermore:
- Each Operation of type READ_MANY also has to define for which Entity it returns actual records. And that can be done using OperationBuilder.returns(..). From that point when ABCS client drops Collection component into the page and select that Entity, your Operation will be listed and become available for selection.
- If such Operation is also described using OperationBuilder.paginates(..), the Collection itself will have pagination enabled.
- If such Operation is also described using OperationBuilder.takes(..) method and the given OperationInput object is configured so that the Operation suppports sorting on certain fields, then table Wizard and PI will adapt accordingly and allow ABCS Business User to set sorting to all fields that were configured as sortable.
- If such Operation is also described using OperationBuilder.takes(..) method and the given OperationInput object is configured so that some parameters supports multiple type of Operators, all related UIs like Default Query, Advanced Search etc. will all contain all supported Operators.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object | Object literal with all possible parameters. Properties
|
- Version:
- 17.1.1
- Source:
- See:
Example
var functionToRun = function() {
// Make any REST call here which performs the real operation and creates new Employee record
return new Promise(function(fulfil, reject) {
$.ajax({
url: 'http://example.com/includeYourEmployee',
type: 'PUT',
data: 'ID=1&Firstname=Martin&Lastname=Janicek&Age=29'
}).done(function(response) {
fulfil(OperationResult.success(response));
}).fail(function(error) {
var message = "Whoops, something went wrong! " + error.message;
reject(OperationResult.failure(message, error.code));
});
});
};
var operation = new OperationBuilder({
name: 'Create Employee',
type: Operation.Type.CREATE,
performs: functionToRun
}).build();
Methods
build() → {operation/js/api/Operation}
stable API
- Version:
- 17.1.1
- Source:
Returns:
description(description) → {bop/js/api/operation/OperationBuilder}
stable API
Sets the description of the build Operation.
The description is used as more detailed information (in tooltips etc.) of the Operation across ABCS UI. It should help ABCS client to understand what's the business meaning of the Operation itself.
Parameters:
Name | Type | Description |
---|---|---|
description |
String | More detailed text information about the build Operation. |
- Version:
- 17.1.1
- Source:
Returns:
a reference to this object to allow method chaining
Example
var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var functionToRun = function(operationData) {
var baseURL = 'http://example.com/employees';
var resultURL = new MyConditionVisitor(baseURL).visit(operationData.getCondition());
// Include REST call here which performs the real operation retrieving your Employee data
return new Promise(function(fulfil, reject) {
$.ajax({
url: resultURL,
type: 'GET'
}).done(function(response) {
fulfil(OperationResult.success(response));
}).fail(function(error) {
reject(OperationResult.failure(error.message, error.code));
});
});
};
var operation = new OperationBuilder({
name: 'Read Employees',
type: Operation.Type.READ_MANY,
performs: functionToRun
}).description('Some long description of what the operation does in detail. It will be showed in some ABCS UI elements (e.g. in tooltips)').
returns(employee).
build();
paginates(pagination) → {bop/js/api/operation/OperationBuilder}
stable API
Sets the type of the Pagination the build Operation supports.
This method is relevant only in case of Operation.Type being set to Operation.Type.READ_MANY, otherwise pagination configuration is meaningless and the OperationBuilder throws an exception.
If OperationBuilder.paginates(..) method is not explicitely called, resulted operation is by default configured with pagination being unsupported.
Parameters:
Name | Type | Description |
---|---|---|
pagination |
bop/js/api/operation/Pagination | Type of the Pagination the built Operation supports. |
- Version:
- 17.1.1
- Source:
Returns:
a reference to this object to allow method chaining
Example
var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var functionToRun = function(operationData) {
var baseURL = 'http://example.com/employees';
var resultURL = new MyConditionVisitor(baseURL).visit(operationData.getCondition());
// Include REST call here which performs the real operation retrieving your Employee data
return new Promise(function(fulfil, reject) {
$.ajax({
url: resultURL,
type: 'GET'
}).done(function(response) {
fulfil(OperationResult.success(response));
}).fail(function(error) {
reject(OperationResult.failure(error.message, error.code));
});
});
};
var operation = new OperationBuilder({
name: 'Read Employees',
type: Operation.Type.READ_MANY,
performs: functionToRun
}).returns(employee).
paginates(Pagination.STANDARD).
build();
returns(param) → {bop/js/api/operation/OperationBuilder}
stable API
Sets either Entity or just a sub-set of it by passing OperationOutput instance, whose records the built Operation returns.
Check OperationBuilder documentation for more details of how this impacts on ABCS UI capabilities.
Parameters:
Name | Type | Description |
---|---|---|
param |
entity/js/api/Entity | bop/js/api/operation/OperationOutput | If an Entity instance is passed, all its Properties are automatically included into operation output description. If you need to restrict these somehow (e.g. your Operation returns only certain sub-set of Properties), instance of OperationOutput can be configured and passed instead. |
- Version:
- 17.1.1
- Source:
- See:
-
- Entity
- OperationOutput
- OperationOutput.parameter(..)
Returns:
a reference to this object to allow method chaining
Examples
var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var functionToRun = function(operationData) {
var baseURL = 'http://example.com/employees';
var resultURL = new MyConditionVisitor(baseURL).visit(operationData.getCondition());
// Include REST call here which performs the real operation retrieving your Employee data
return new Promise(function(fulfil, reject) {
$.ajax({
url: resultURL,
type: 'GET'
}).done(function(response) {
fulfil(OperationResult.success(response));
}).fail(function(error) {
reject(OperationResult.failure(error.message, error.code));
});
});
};
var operation = new OperationBuilder({
name: 'Read Employees',
type: Operation.Type.READ_MANY,
performs: functionToRun
}).returns(employee).build();
// Let's assume, Employee entity has a lot of properties but our operation returns just two of them ("Firstname", "Lastname")
var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var outputBuilder = new OperationOutput({
entity: employee
}).property(firstname).
property(lastname);
var functionToRun = function(operationData) {
var baseURL = 'http://example.com/employees';
var resultURL = new MyConditionVisitor(baseURL).visit(operationData.getCondition());
// Include REST call here which performs the real operation retrieving your Employee data
return new Promise(function(fulfil, reject) {
$.ajax({
url: resultURL,
type: 'GET'
}).done(function(response) {
fulfil(OperationResult.success(response));
}).fail(function(error) {
reject(OperationResult.failure(error.message, error.code));
});
});
};
var operation = new OperationBuilder({
name: 'Read only basic information about Employees',
type: Operation.Type.READ_MANY,
performs: functionToRun
}).returns(outputBuilder).build();
sortableBy(value) → {bop/js/api/operation/OperationBuilder}
stable API
Defines the given Property(or Properties) as sortable option(s) supported by the build Operation.
Argument is allowed to be passed in two different forms:
- Single Property instance which is automatically assumed to be sortable option.
- Array of Properties making all of them automatically assumed to be sortable options.
Please be aware that the value given here is tightly connected to what you specified within the OperationBuilder.returns(..) method. Only Properties that are defined as an ouput of the Operation can be specified for sorting.
Parameters:
Name | Type | Description |
---|---|---|
value |
entity/js/api/Property | Array.<entity/js/api/Property> | sortable options for the build Operation. |
- Version:
- 17.1.1
- Source:
- See:
Returns:
a reference to this object to allow method chaining
Example
var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var firstname = employee.getProperty('Firstname');
var lastname = employee.getProperty('Lastname');
// Assuming Employee entity contains three properties: Firstname, Lastname and Age
// Using this description only two of them will be available for sorting
var operation = new OperationBuilder({
name: 'Read Employees',
type: Operation.Type.READ_MANY,
performs: function() {
// This performs the REST call
}
}).returns(employee).
sortableBy(firstname).
sortableBy(lastname).
build();
sortableByAll() → {bop/js/api/operation/OperationBuilder}
stable API
Defines the build Operation to be sortable by all Properties available in the configured Entity.
Please be aware that the value given here is tightly connected to what you specified within the OperationBuilder.returns(..) method. All Properties that were defined as an ouput of the Operation (= all Properties assigned to the Entity given into the OperationBuilder.returns(..) method) will be available for sorting.
- Version:
- 17.1.1
- Source:
- See:
Returns:
a reference to this object to allow method chaining
Example
var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var operation = new OperationBuilder({
name: 'Read Employees',
type: Operation.Type.READ_MANY,
performs: function() {
// This performs the REST call
}
}).returns(employee).
sortableByAll().
build();
specialType(specialType) → {bop/js/api/operation/OperationBuilder}
stable API
Sets the SpecialType of the build Operation.
Special type is relevant only in cases of Operation instance with standard type set to either Operation.Type.READ_MANY or Operation.Type.READ_ONE. For all other Operation.Types, this information is unsupported and resulted behavior is not guaranteed by ABCS.
Only one Operation of each Operation.SpecialType is expected for a single Entity. If your BOP will provide more Operations of this type for the same Entity, the behavior is not guaranteed by ABCS.
For detailed information of how different SpecialTypes affects ABCS capabilities please check SpecialType documentation.
Parameters:
Name | Type | Description |
---|---|---|
specialType |
operation/js/api/Operation.SpecialType |
- Version:
- 17.1.1
- Source:
Returns:
a reference to this object to allow method chaining
Example
// Let's just assume Employee has four properties (ID, Firstname, Lastname, Age)
var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var functionToRun = function(operationData) {
// Include REST call here which performs the real operation retrieving your Employee data
// In this case your REST call:
// --> Has to be capable to manage ID, Firstname, Lastname, Age input parameters
// --> Has to be capable to manage all possible combinations AND/OR of these input parameters
var baseURL = 'http://example.com/employees';
var resultURL = new MyConditionVisitor(baseURL).visit(operationData.getCondition());
// Include REST call here which performs the real operation retrieving your Employee data
return new Promise(function(fulfil, reject) {
$.ajax({
url: resultURL,
type: 'GET'
}).done(function(response) {
fulfil(OperationResult.success(response));
}).fail(function(error) {
reject(OperationResult.failure(error.message, error.code));
});
});
};
var inputBuilder = new OperationInput({
entity: employee
})
var operation = new OperationBuilder({
name: 'Read Employees',
type: Operation.Type.READ_MANY,
performs: functionToRun
}).returns(employee).
takes(inputBuilder).
specialType(Operation.SpecialType.QUERY_BY_ANYTHING).
build();
takes(operationInput) → {bop/js/api/operation/OperationBuilder}
stable API
Sets the input configuration of the build Operation.
Creating comprehensive OperationInput is absolutely necessary to make resulted Operation behaving correctly inside ABCS UI. Usually this is complex mainly for operations of type READ_MANY as those need to describe querying, sorting and pagination capabilities. For other Operation.Types, it's fine for the given OperationInput instance to have only input Entity configured.
Parameters:
Name | Type | Description |
---|---|---|
operationInput |
bop/js/api/operation/OperationInput |
- Version:
- 17.1.1
- Source:
- See:
Returns:
a reference to this object to allow method chaining
Examples
var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var firstname = employee.getProperty('Firstname');
var lastname = employee.getProperty('Lastname');
var functionToRun = function(operationData) {
// Include REST call here which performs the real operation retrieving your Employee data
// In this case your REST call:
// --> Has to be capable to manage Firstname and Lastname input parameters with EQUALS operator only
var baseURL = 'http://example.com/employees';
var resultURL = new MyConditionVisitor(baseURL).visit(operationData.getCondition());
// Include REST call here which performs the real operation retrieving your Employee data
return new Promise(function(fulfil, reject) {
$.ajax({
url: resultURL,
type: 'GET'
}).done(function(response) {
fulfil(OperationResult.success(response));
}).fail(function(error) {
reject(OperationResult.failure(error.message, error.code));
});
});
};
var inputBuilder = new OperationInput({
entity: employee
}).parameter(firstname).
parameter(lastname);
var operation = new OperationBuilder({
name: 'Read Employees',
type: Operation.Type.READ_MANY,
performs: functionToRun
}).returns(employee).
takes(inputBuilder).
build();
var textOperators = [
Operator.EQUALS,
Operator.NOT_EQUALS,
Operator.CONTAINS,
Operator.NOT_CONTAINS,
Operator.STARTS_WITH,
Operator.ENDS_WITH
];
var numberOperators = [
Operator.EQUALS,
Operator.NOT_EQUALS,
Operator.LESS,
Operator.LESS_OR_EQUAL,
Operator.MORE,
Operator.MORE_OR_EQUAL
];
var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var firstname = employee.getProperty('Firstname'); // Let's assume this is PropertyType.TEXT
var lastname = employee.getProperty('Lastname'); // Let's assume this is PropertyType.TEXT
var age = employee.getProperty('Age'); // Let's assume this is PropertyType.NUMBER
var functionToRun = function(operationData) {
// Include REST call here which performs the real operation retrieving your Employee data
// In this case your REST call:
// --> Has to be capable to manage Firstname, Lastname and Age input parameters
// --> Has to be capable to manage all "textOperators" for Firstname and Lastname input parameters
// --> Has to be capable to manage all "numberOperators" for Age input parameter
var baseURL = 'http://example.com/employees';
var resultURL = new MyConditionVisitor(baseURL).visit(operationData.getCondition());
// Include REST call here which performs the real operation retrieving your Employee data
return new Promise(function(fulfil, reject) {
$.ajax({
url: resultURL,
type: 'GET'
}).done(function(response) {
fulfil(OperationResult.success(response));
}).fail(function(error) {
reject(OperationResult.failure(error.message, error.code));
});
});
};
var inputBuilder = new OperationInput({
entity: employee
}).parameter(age).
parameter(firstname).
parameter(lastname).
operatorsForType(PropertyType.TEXT, textOperators).
operatorsForType(PropertyType.NUMBER, numberOperators);
var operation = new OperationBuilder({
name: 'Read Employees',
type: Operation.Type.READ_MANY,
performs: functionToRun
}).returns(employee).
takes(inputBuilder).
build();