Search in sources :

Example 6 with LiteralRestrictionDescr

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);
}
Also used : FieldValue(org.drools.core.spi.FieldValue) LiteralRestrictionDescr(org.drools.compiler.lang.descr.LiteralRestrictionDescr)

Example 7 with LiteralRestrictionDescr

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());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) FieldConstraintDescr(org.drools.compiler.lang.descr.FieldConstraintDescr) Cheese(org.drools.compiler.Cheese) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) LiteralRestrictionDescr(org.drools.compiler.lang.descr.LiteralRestrictionDescr) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) CompositeObjectSinkAdapterTest(org.drools.core.reteoo.CompositeObjectSinkAdapterTest) Test(org.junit.Test)

Aggregations

LiteralRestrictionDescr (org.drools.compiler.lang.descr.LiteralRestrictionDescr)7 AndDescr (org.drools.compiler.lang.descr.AndDescr)4 FieldConstraintDescr (org.drools.compiler.lang.descr.FieldConstraintDescr)4 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)4 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)4 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)4 Cheese (org.drools.compiler.Cheese)3 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)3 Test (org.junit.Test)3 PredicateConstraint (org.drools.core.rule.PredicateConstraint)2 EvaluatorConstraint (org.drools.core.rule.constraint.EvaluatorConstraint)2 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)2 NegConstraint (org.drools.core.rule.constraint.NegConstraint)2 XpathConstraint (org.drools.core.rule.constraint.XpathConstraint)2 Constraint (org.drools.core.spi.Constraint)2 FieldValue (org.drools.core.spi.FieldValue)2 ParserError (org.drools.compiler.compiler.ParserError)1 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)1 ValueType (org.drools.core.base.ValueType)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1