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