use of org.drools.verifier.components.EnumField in project drools by kiegroup.
the class VerifierDataMapsTest method testSaveVerifierComponentAndGetForAllFields.
@Test
public void testSaveVerifierComponentAndGetForAllFields() {
saveVerifierComponentAndGet(new EnumField(new PackageDescr("testPackage1")));
saveVerifierComponentAndGet(new Field(new PackageDescr("testPackage1")));
}
use of org.drools.verifier.components.EnumField 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);
}
}
Aggregations