use of org.drools.compiler.lang.descr.LiteralRestrictionDescr in project drools by kiegroup.
the class PatternBuilder method normalizeExpression.
private String normalizeExpression(RuleBuildContext context, Pattern pattern, RelationalExprDescr subDescr, String subExpr) {
String leftValue = findLeftExpressionValue(subDescr);
String operator = subDescr.getOperator();
if (isDateType(context, pattern, leftValue)) {
String rightValue = findRightExpressionValue(subDescr);
FieldValue fieldValue = getFieldValue(context, ValueType.DATE_TYPE, rightValue);
if (fieldValue != null) {
subExpr = subExpr.replace(rightValue, getNormalizeDate(fieldValue));
}
return subExpr;
}
if (operator.equals("str")) {
String rightValue = findRightExpressionValue(subDescr);
return normalizeStringOperator(leftValue, rightValue, new LiteralRestrictionDescr(operator, subDescr.isNegated(), subDescr.getParameters(), rightValue, LiteralRestrictionDescr.TYPE_STRING));
}
// resolve ambiguity between mvel's "empty" keyword and constraints like: List(empty == ...)
return normalizeEmptyKeyword(subExpr, operator);
}
use of org.drools.compiler.lang.descr.LiteralRestrictionDescr in project drools by kiegroup.
the class KnowledgeBuilderTest method testNull.
@Test
public void testNull() {
final KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
final PackageDescr packageDescr = new PackageDescr("p1");
final RuleDescr ruleDescr = new RuleDescr("rule-1");
packageDescr.addRule(ruleDescr);
final AndDescr lhs = new AndDescr();
ruleDescr.setLhs(lhs);
final PatternDescr patternDescr = new PatternDescr(Cheese.class.getName(), "stilton");
final FieldConstraintDescr literalDescr = new FieldConstraintDescr("type");
literalDescr.addRestriction(new LiteralRestrictionDescr("==", null));
patternDescr.addConstraint(literalDescr);
ruleDescr.setConsequence("");
builder.addPackage(packageDescr);
InternalKnowledgePackage pkg = builder.getPackage(packageDescr.getName());
final RuleImpl rule = pkg.getRule("rule-1");
assertLength(0, builder.getErrors().getErrors());
}
Aggregations