Search in sources :

Example 1 with NegConstraint

use of org.drools.core.rule.constraint.NegConstraint in project drools by kiegroup.

the class PatternBuilder method buildExpression.

protected Constraint buildExpression(final RuleBuildContext context, final Pattern pattern, final BaseDescr d, final String expr, final Map<String, OperatorDescr> aliases) {
    if ("_.neg".equals(expr)) {
        pattern.setHasNegativeConstraint(true);
        return new NegConstraint();
    } else if ("!_.neg".equals(expr)) {
        pattern.setHasNegativeConstraint(true);
        return new NegConstraint(false);
    }
    RelationalExprDescr relDescr = d instanceof RelationalExprDescr ? (RelationalExprDescr) d : null;
    boolean simple = isSimpleExpr(relDescr);
    if (// simple means also relDescr is != null
    simple && !ClassObjectType.Map_ObjectType.isAssignableFrom(pattern.getObjectType()) && !ClassObjectType.Match_ObjectType.isAssignableFrom(pattern.getObjectType())) {
        String normalizedExpr = normalizeExpression(context, pattern, relDescr, expr);
        return buildRelationalExpression(context, pattern, relDescr, normalizedExpr, aliases);
    }
    // Or it's a Map and we have to treat it as a special case
    return createAndBuildPredicate(context, pattern, d, rewriteOrExpressions(context, pattern, d, expr), aliases);
}
Also used : NegConstraint(org.drools.core.rule.constraint.NegConstraint) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr)

Example 2 with NegConstraint

use of org.drools.core.rule.constraint.NegConstraint in project drools by kiegroup.

the class PatternBuilder method build.

/**
 * Build a pattern for the given descriptor in the current
 * context and using the given utils object
 */
public RuleConditionElement build(RuleBuildContext context, PatternDescr patternDescr, Pattern prefixPattern) {
    if (patternDescr.getObjectType() == null) {
        lookupObjectType(context, patternDescr);
    }
    if (patternDescr.getObjectType() == null || patternDescr.getObjectType().equals("")) {
        registerDescrBuildError(context, patternDescr, "ObjectType not correctly defined");
        return null;
    }
    ObjectType objectType = getObjectType(context, patternDescr);
    if (objectType == null) {
        // if the objectType doesn't exist it has to be query
        return buildQuery(context, patternDescr, patternDescr);
    }
    Pattern pattern = buildPattern(context, patternDescr, objectType);
    processClassObjectType(context, objectType, pattern);
    processAnnotations(context, patternDescr, pattern);
    processSource(context, patternDescr, pattern);
    processConstraintsAndBinds(context, patternDescr, pattern);
    processBehaviors(context, patternDescr, pattern);
    if (!pattern.hasNegativeConstraint() && "on".equals(System.getProperty("drools.negatable"))) {
        // this is a non-negative pattern, so we must inject the constraint
        pattern.addConstraint(new NegConstraint(false));
    }
    // poping the pattern
    context.getDeclarationResolver().popBuildStack();
    return pattern;
}
Also used : AcceptsClassObjectType(org.drools.core.spi.AcceptsClassObjectType) FactTemplateObjectType(org.drools.core.facttemplates.FactTemplateObjectType) ObjectType(org.drools.core.spi.ObjectType) ClassObjectType(org.drools.core.base.ClassObjectType) Pattern(org.drools.core.rule.Pattern) NegConstraint(org.drools.core.rule.constraint.NegConstraint)

Aggregations

NegConstraint (org.drools.core.rule.constraint.NegConstraint)2 RelationalExprDescr (org.drools.compiler.lang.descr.RelationalExprDescr)1 ClassObjectType (org.drools.core.base.ClassObjectType)1 FactTemplateObjectType (org.drools.core.facttemplates.FactTemplateObjectType)1 Pattern (org.drools.core.rule.Pattern)1 AcceptsClassObjectType (org.drools.core.spi.AcceptsClassObjectType)1 ObjectType (org.drools.core.spi.ObjectType)1