Search in sources :

Example 1 with Variable

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

the class ExprConstraintDescrVisitor method createVariableRestriction.

private void createVariableRestriction(int orderNumber, String value, Operator operator) {
    Variable variable = data.getVariableByRuleAndVariableName(pattern.getRuleName(), value);
    VariableRestriction restriction = new VariableRestriction(pattern);
    restriction.setPatternIsNot(pattern.isPatternNot());
    restriction.setFieldPath(field.getPath());
    restriction.setOperator(operator);
    restriction.setVariable(variable);
    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) Variable(org.drools.verifier.components.Variable) FieldVariable(org.drools.verifier.components.FieldVariable)

Example 2 with Variable

use of org.drools.verifier.components.Variable 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 3 with Variable

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

the class TestBase method assertContainsVariable.

protected void assertContainsVariable(String ruleName, String variableName) {
    Variable variable = verifierData.getVariableByRuleAndVariableName(ruleName, variableName);
    assertNotNull(String.format("Could not find Variable : %s ", variableName), variable);
}
Also used : Variable(org.drools.verifier.components.Variable)

Aggregations

Variable (org.drools.verifier.components.Variable)3 EnumField (org.drools.verifier.components.EnumField)1 EnumRestriction (org.drools.verifier.components.EnumRestriction)1 FieldVariable (org.drools.verifier.components.FieldVariable)1 Import (org.drools.verifier.components.Import)1 ObjectType (org.drools.verifier.components.ObjectType)1 PatternVariable (org.drools.verifier.components.PatternVariable)1 QualifiedIdentifierRestriction (org.drools.verifier.components.QualifiedIdentifierRestriction)1 VariableRestriction (org.drools.verifier.components.VariableRestriction)1