You set restrictions on Orders
by specifying the criteria or “rules” that an Order
must meet if it is to be placed. The functionality for this Order
restriction system relies on the following Oracle ATG Web Commerce classes in package atg.commerce.expression
:
Rule, which represents the rule.
ExpressionParser, which parses the expression (rule).
RuleEvaluator, which evaluates the expression to either to True or False.
ProcPropertyRestriction, which evaluates the rule using the
ExpressionParser
andRuleEvaluator
.
Rule
The atg.commerce.expression.Rule
class represents a rule. A Rule
object contains RuleExpressions
(operands) and an operator, which together are evaluated to either True or False.
ExpressionParser
The atg.commerce.expression.ExpressionParser
class is used to parse expressions. ExpressionParser
supports the following operators: =, >, <, >=, <=, !=, contains
, and containsKey
. It does not support & (and) or | (or). The ExpressionParser.parseExpression()
method takes a string containing an expression to parse, such as the following:
Order.priceInfo.amount > Profile.maxAmountAllowed
Profile.approvalRequired = true
Order.id = null
Order.specialInstructions.shippingInfo.size != 1000
After parsing the expression, the parseExpression()
method returns a Rule
object, which is then passed to the RuleEvaluator for evaluation.
Oracle ATG Web Commerce provides a globally-scoped instance of ExpressionParser
, which is located in Nucleus at /atg/commerce/util/
.
RuleEvaluator
The atg.commerce.expression.RuleEvaluator
class is used to evaluate a given rule. After the ExpressionParser parses an expression, it returns a Rule
object and passes it to the RuleEvaluator
. The RuleEvaluator.evaluateRule()
method then evaluates the rule to True or False.
The RuleEvaluator
class supports all primitive data types in Java. These are long
, double
, int
, short
, float
, boolean
, char
, and String
. If two incompatible data types are evaluated, such as a double and boolean, then an EvaluationExpression
is thrown.
Oracle ATG Web Commerce provides a globally-scoped instance of RuleEvaluator
, which is located in Nucleus at /atg/commerce/util/
.
ProcPropertyRestriction
The atg.commerce.expression.ProcPropertyRestriction
class resolves all references in the rule set in ProcPropertyRestriction.ruleExpression
using the ExpressionParser and then evaluates the rule using the RuleEvaluator. The processor then returns a value based on whether the rule evaluates to True or False. The specific value returned is determined by its returnValueForTrueEvaluation
and returnValueForFalseEvaluation
properties.
Additionally, if the expression evaluates to True and the addErrorToResultOnTrueEval
property is set to True, then the value in the errorMessage
property is added to the PipelineResult
object, keyed by the string in the pipelineResultErrorMessageKey
property. (See the table below for more information on these properties.)
The ProcPropertyRestriction
processor has the following properties:
Property | Description |
---|---|
| The expression that is passed to the |
| The If null, the |
| The If null, the |
| The integer to return when the expression evaluates to False. |
| The integer to return when the expression evaluates to True. |
| A boolean property that controls whether the |
| The error message to add to the |
| The key to use when adding the |