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);
}
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);
}
}
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);
}
Aggregations