Represents visitor for interpreting input Conditions.
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.
- Version:
- 17.1.1
- Source:
- See:
Example
define([
'bop/js/spi/operation/ConditionVisitor',
'bop/js/api/operation/RelationOperator',
'operation/js/api/Operator'
], function (
ConditionVisitor,
RelationOperator,
Operator
) {
var MyConditionVisitor = function() {
};
MyConditionVisitor.prototype.visitEmptyCondition = function() {
// See example presented in visitEmptyCondition(..) JSDoc
};
MyConditionVisitor.prototype.visitSimpleCondition = function(condition) {
// See example presented in visitSimpleCondition(..) JSDoc
};
MyConditionVisitor.prototype.visitCompositeCondition = function(condition) {
// See example presented in visitCompositeCondition(..) JSDoc
};
return MyConditionVisitor;
});
Methods
visitCompositeCondition(compositeCondition)
stable API
Visit an instance of CompositeCondition.
Please be aware that it's your responsibility to check for deeper sub-Conditions of the given CompositeCondition and call subsequent ConditionVisitor.visitCompositeCondition(..) and ConditionVisitor.visitSimpleCondition(..) by your own.
Parameters:
Name | Type | Description |
---|---|---|
compositeCondition |
bop/js/api/operation/CompositeCondition |
- Version:
- 17.1.1
- Source:
- See:
Example
MyConditionVisitor.prototype.visitCompositeCondition = function(compositeCondition) {
var url = '(';
var subConditions = compositeCondition.getSubConditions();
// Iterating over all sub-conditions and visiting them recursively as well
for (var i = 0; i < subConditions.length; i++) {
var subCondition = subConditions[i];
var subConditionArray = subCondition.getSubConditions();
if (subConditionArray && subConditionArray.length > 0) {
url += self.visitCompositeCondition(subCondition);
} else {
url += self.visitSimpleCondition(subCondition);
}
// Skip including relation operator after the last sub-condition
if (i < subConditions.length - 1) {
switch (compositeCondition.getRelationOperator()) {
case RelationOperator.AND:
url += ' AND ';
break;
case RelationOperator.OR:
url += ' OR ';
break;
}
}
url += ')';
return url;
};
visitEmptyCondition()
stable API
Visiting method for the case where no Condition had been defined.
- Version:
- 17.1.1
- Source:
Example
MyConditionVisitor.prototype.visitEmptyCondition = function() {
return '';
};
visitSimpleCondition(simpleCondition)
stable API
Visit an instance of SimpleCondition.
Parameters:
Name | Type | Description |
---|---|---|
simpleCondition |
bop/js/api/operation/SimpleCondition |
- Version:
- 17.1.1
- Source:
- See:
Example
MyConditionVisitor.prototype.visitSimpleCondition = function(condition) {
var propertyID = condition.getProperty().getId();
var operator = condition.getOperator();
var value = condition.getValue();
// For simplification let's assume only two possible operators are available
switch (operator) {
case Operator.EQUALS:
return propertyID + ' equals ' + value;
case Operator.NOT_EQUALS:
return propertyID + ' notEquals ' + value;
}
};