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

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

ruleExpression

The expression that is passed to the ExpressionParser, such as Order.priceInfo.amount > 1000.0. This is the rule against which the processor evaluates the Order.

expressionParser

The ExpressionParser Nucleus component.

If null, the ProcPropertyRestriction processor creates a new instance of atg.commerce.expression.ExpressionParser for its use.

ruleEvaluator

The RuleEvaluator Nucleus component.

If null, the ProcPropertyRestriction processor creates a new instance of atg.commerce.expression.RuleEvaluator for its use.

returnValueForFalseEvaluation

The integer to return when the expression evaluates to False.

returnValueForTrueEvaluation

The integer to return when the expression evaluates to True.

addErrorToResultOnTrueEval

A boolean property that controls whether the errorMessage is added to the PipelineResult object when the expression evaluates to True.

errorMessage

The error message to add to the PipelineResult object when the expression evaluates to True.

pipelineResultErrorMessageKey

The key to use when adding the errorMessage to the PipelineResult object.


Copyright © 1997, 2012 Oracle and/or its affiliates. All rights reserved.

Legal Notices