Search in sources :

Example 1 with EnumField

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")));
}
Also used : EnumField(org.drools.verifier.components.EnumField) EnumField(org.drools.verifier.components.EnumField) Field(org.drools.verifier.components.Field) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 2 with EnumField

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

Aggregations

EnumField (org.drools.verifier.components.EnumField)2 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)1 EnumRestriction (org.drools.verifier.components.EnumRestriction)1 Field (org.drools.verifier.components.Field)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 Variable (org.drools.verifier.components.Variable)1 Test (org.junit.Test)1