Search in sources :

Example 1 with PatternVariable

use of org.drools.verifier.components.PatternVariable in project drools by kiegroup.

the class FieldConstraintDescrVisitor method visit.

/**
 * End
 * <p/>
 * Foo( bar == $bar )<br>
 * $bar is a VariableRestrictionDescr
 *
 * @param descr
 */
private void visit(VariableRestrictionDescr descr) {
    PatternVariable patternVariable = (PatternVariable) data.getVariableByRuleAndVariableName(pattern.getRuleName(), descr.getIdentifier());
    VariableRestriction restriction = new VariableRestriction(pattern);
    restriction.setPatternIsNot(pattern.isPatternNot());
    restriction.setFieldPath(field.getPath());
    restriction.setOperator(Operator.determineOperator(descr.getEvaluator(), descr.isNegated()));
    restriction.setVariable(patternVariable);
    restriction.setOrderNumber(orderNumber);
    restriction.setParentPath(pattern.getPath());
    restriction.setParentType(pattern.getVerifierComponentType());
    // Set field value, if it is unset.
    field.setFieldType(Field.VARIABLE);
    data.add(restriction);
    solvers.addPatternComponent(restriction);
}
Also used : VariableRestriction(org.drools.verifier.components.VariableRestriction) PatternVariable(org.drools.verifier.components.PatternVariable)

Example 2 with PatternVariable

use of org.drools.verifier.components.PatternVariable in project drools by kiegroup.

the class PatternDescrVisitor method visitPatternDescr.

private Pattern visitPatternDescr(PatternDescr descr, VerifierComponent parent, int orderNumber) throws UnknownDescriptionException {
    objectType = data.getObjectTypeByFullName(descr.getObjectType());
    if (objectType == null) {
        Import objectImport = data.getImportByName(descr.getObjectType());
        if (objectImport != null) {
            objectType = ObjectTypeFactory.createObjectType(descr, objectImport);
        } else {
            objectType = ObjectTypeFactory.createObjectType(descr, descr.getObjectType());
        }
        data.add(objectType);
    }
    pattern = new Pattern(descr, rule);
    if (parent != null) {
        pattern.setParentPath(parent.getPath());
        pattern.setParentType(parent.getVerifierComponentType());
    }
    pattern.setObjectTypePath(objectType.getPath());
    pattern.setName(objectType.getName());
    pattern.setPatternNot(solvers.getRuleSolver().isChildNot());
    pattern.setPatternExists(solvers.getRuleSolver().isExists());
    pattern.setPatternForall(solvers.getRuleSolver().isForall());
    pattern.setOrderNumber(orderNumber);
    if (descr.getIdentifier() != null) {
        PatternVariable patternVariable = new PatternVariable(rule);
        patternVariable.setName(descr.getIdentifier());
        patternVariable.setParentPath(pattern.getPath());
        patternVariable.setParentType(pattern.getVerifierComponentType());
        data.add(patternVariable);
    }
    // visit source.
    if (descr.getSource() != null) {
        visit(descr.getSource());
    } else {
        if (workingMemory == null) {
            workingMemory = new WorkingMemory();
            data.add(workingMemory);
        }
        pattern.setSourcePath(workingMemory.getPath());
        pattern.setSourceType(workingMemory.getVerifierComponentType());
    }
    solvers.startPatternSolver(pattern);
    visit(descr.getConstraint());
    solvers.endPatternSolver();
    data.add(pattern);
    return pattern;
}
Also used : Pattern(org.drools.verifier.components.Pattern) PatternVariable(org.drools.verifier.components.PatternVariable) Import(org.drools.verifier.components.Import) WorkingMemory(org.drools.verifier.components.WorkingMemory)

Example 3 with PatternVariable

use of org.drools.verifier.components.PatternVariable in project drools by kiegroup.

the class FieldConstraintDescrVisitor method visit.

/**
 * End
 *
 * @param descr
 */
private void visit(QualifiedIdentifierRestrictionDescr descr) {
    String text = descr.getText();
    String base = text.substring(0, text.indexOf("."));
    String fieldName = text.substring(text.indexOf("."));
    Variable patternVariable = data.getVariableByRuleAndVariableName(pattern.getRuleName(), base);
    if (patternVariable != null) {
        QualifiedIdentifierRestriction restriction = new QualifiedIdentifierRestriction(pattern);
        restriction.setPatternIsNot(pattern.isPatternNot());
        restriction.setFieldPath(field.getPath());
        restriction.setOperator(Operator.determineOperator(descr.getEvaluator(), descr.isNegated()));
        restriction.setVariablePath(patternVariable.getPath());
        restriction.setVariableName(base);
        restriction.setVariablePath(fieldName);
        restriction.setOrderNumber(orderNumber);
        restriction.setParentPath(pattern.getPath());
        restriction.setParentType(pattern.getVerifierComponentType());
        // Set field value, if it is not set.
        field.setFieldType(Field.VARIABLE);
        data.add(restriction);
        solvers.addPatternComponent(restriction);
    } else {
        EnumField enumField = (EnumField) data.getFieldByObjectTypeAndFieldName(base, fieldName);
        if (enumField == null) {
            ObjectType objectType = data.getObjectTypeByFullName(base);
            if (objectType == null) {
                Import objectImport = data.getImportByName(base);
                if (objectImport != null) {
                    objectType = ObjectTypeFactory.createObjectType(descr, objectImport);
                } else {
                    objectType = ObjectTypeFactory.createObjectType(descr, base);
                }
                data.add(objectType);
            }
            enumField = new EnumField(descr);
            enumField.setObjectTypePath(objectType.getPath());
            enumField.setObjectTypeName(objectType.getName());
            enumField.setName(fieldName);
            objectType.getFields().add(enumField);
            data.add(enumField);
        }
        EnumRestriction restriction = new EnumRestriction(pattern);
        restriction.setPatternIsNot(pattern.isPatternNot());
        restriction.setFieldPath(field.getPath());
        restriction.setOperator(Operator.determineOperator(descr.getEvaluator(), descr.isNegated()));
        restriction.setEnumBasePath(enumField.getPath());
        restriction.setEnumBase(base);
        restriction.setEnumName(fieldName);
        restriction.setOrderNumber(orderNumber);
        restriction.setParentPath(pattern.getPath());
        restriction.setParentType(pattern.getVerifierComponentType());
        // Set field value, if it is not set.
        field.setFieldType(Field.ENUM);
        data.add(restriction);
        solvers.addPatternComponent(restriction);
    }
}
Also used : EnumField(org.drools.verifier.components.EnumField) ObjectType(org.drools.verifier.components.ObjectType) Variable(org.drools.verifier.components.Variable) PatternVariable(org.drools.verifier.components.PatternVariable) Import(org.drools.verifier.components.Import) EnumRestriction(org.drools.verifier.components.EnumRestriction) QualifiedIdentifierRestriction(org.drools.verifier.components.QualifiedIdentifierRestriction)

Example 4 with PatternVariable

use of org.drools.verifier.components.PatternVariable in project drools by kiegroup.

the class VerifierDataMapsTest method testSaveVerifierComponentAndGetForAllComponentTypes.

@Test
public void testSaveVerifierComponentAndGetForAllComponentTypes() {
    RulePackage rulePackage = VerifierComponentMockFactory.createPackage1();
    saveVerifierComponentAndGet(rulePackage);
    VerifierRule rule = VerifierComponentMockFactory.createRule1();
    saveVerifierComponentAndGet(rule);
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    saveVerifierComponentAndGet(pattern);
    saveVerifierComponentAndGet(new InlineEvalDescr(pattern));
    saveVerifierComponentAndGet(new ObjectType(new PackageDescr("testPackage1")));
    saveVerifierComponentAndGet(new RuleOperatorDescr(new AndDescr(), rule, OperatorDescrType.AND));
    saveVerifierComponentAndGet(new PatternOperatorDescr(pattern, OperatorDescrType.AND));
    saveVerifierComponentAndGet(new SubPattern(pattern, 0));
    saveVerifierComponentAndGet(new ReturnValueFieldDescr(pattern));
    saveVerifierComponentAndGet(new SubRule(rule, 0));
    saveVerifierComponentAndGet(new TextConsequence(rule));
    saveVerifierComponentAndGet(new PatternVariable(rule));
    saveVerifierComponentAndGet(new VerifierAccessorDescr(rule));
    saveVerifierComponentAndGet(new VerifierAccumulateDescr(pattern));
    saveVerifierComponentAndGet(new VerifierCollectDescr(pattern));
    saveVerifierComponentAndGet(new RuleEval(rule));
    saveVerifierComponentAndGet(new VerifierFieldAccessDescr(rule));
    saveVerifierComponentAndGet(new VerifierFromDescr(pattern));
    saveVerifierComponentAndGet(new VerifierMethodAccessDescr(rule));
    saveVerifierComponentAndGet(new PatternEval(pattern));
}
Also used : Pattern(org.drools.verifier.components.Pattern) SubPattern(org.drools.verifier.components.SubPattern) TextConsequence(org.drools.verifier.components.TextConsequence) PatternVariable(org.drools.verifier.components.PatternVariable) VerifierMethodAccessDescr(org.drools.verifier.components.VerifierMethodAccessDescr) ReturnValueFieldDescr(org.drools.verifier.components.ReturnValueFieldDescr) SubRule(org.drools.verifier.components.SubRule) VerifierFieldAccessDescr(org.drools.verifier.components.VerifierFieldAccessDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) VerifierAccumulateDescr(org.drools.verifier.components.VerifierAccumulateDescr) VerifierRule(org.drools.verifier.components.VerifierRule) VerifierFromDescr(org.drools.verifier.components.VerifierFromDescr) SubPattern(org.drools.verifier.components.SubPattern) RuleEval(org.drools.verifier.components.RuleEval) RulePackage(org.drools.verifier.components.RulePackage) PatternEval(org.drools.verifier.components.PatternEval) ObjectType(org.drools.verifier.components.ObjectType) PatternOperatorDescr(org.drools.verifier.components.PatternOperatorDescr) RuleOperatorDescr(org.drools.verifier.components.RuleOperatorDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) VerifierCollectDescr(org.drools.verifier.components.VerifierCollectDescr) VerifierAccessorDescr(org.drools.verifier.components.VerifierAccessorDescr) InlineEvalDescr(org.drools.verifier.components.InlineEvalDescr) Test(org.junit.Test)

Aggregations

PatternVariable (org.drools.verifier.components.PatternVariable)4 Import (org.drools.verifier.components.Import)2 ObjectType (org.drools.verifier.components.ObjectType)2 Pattern (org.drools.verifier.components.Pattern)2 AndDescr (org.drools.compiler.lang.descr.AndDescr)1 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)1 EnumField (org.drools.verifier.components.EnumField)1 EnumRestriction (org.drools.verifier.components.EnumRestriction)1 InlineEvalDescr (org.drools.verifier.components.InlineEvalDescr)1 PatternEval (org.drools.verifier.components.PatternEval)1 PatternOperatorDescr (org.drools.verifier.components.PatternOperatorDescr)1 QualifiedIdentifierRestriction (org.drools.verifier.components.QualifiedIdentifierRestriction)1 ReturnValueFieldDescr (org.drools.verifier.components.ReturnValueFieldDescr)1 RuleEval (org.drools.verifier.components.RuleEval)1 RuleOperatorDescr (org.drools.verifier.components.RuleOperatorDescr)1 RulePackage (org.drools.verifier.components.RulePackage)1 SubPattern (org.drools.verifier.components.SubPattern)1 SubRule (org.drools.verifier.components.SubRule)1 TextConsequence (org.drools.verifier.components.TextConsequence)1 Variable (org.drools.verifier.components.Variable)1