Search in sources :

Example 1 with QualifiedIdentifierRestriction

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

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

the class VerifierDataMapsTest method testSaveVerifierComponentAndGetForAllRestrictions.

@Test
public void testSaveVerifierComponentAndGetForAllRestrictions() {
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    saveVerifierComponentAndGet(LiteralRestriction.createRestriction(pattern, ""));
    saveVerifierComponentAndGet(new EnumRestriction(pattern));
    saveVerifierComponentAndGet(new QualifiedIdentifierRestriction(pattern));
    saveVerifierComponentAndGet(new ReturnValueRestriction(pattern));
    saveVerifierComponentAndGet(new ReturnValueRestriction(pattern));
    saveVerifierComponentAndGet(new VariableRestriction(pattern));
}
Also used : Pattern(org.drools.verifier.components.Pattern) SubPattern(org.drools.verifier.components.SubPattern) VariableRestriction(org.drools.verifier.components.VariableRestriction) EnumRestriction(org.drools.verifier.components.EnumRestriction) ReturnValueRestriction(org.drools.verifier.components.ReturnValueRestriction) QualifiedIdentifierRestriction(org.drools.verifier.components.QualifiedIdentifierRestriction) Test(org.junit.Test)

Aggregations

EnumRestriction (org.drools.verifier.components.EnumRestriction)2 QualifiedIdentifierRestriction (org.drools.verifier.components.QualifiedIdentifierRestriction)2 EnumField (org.drools.verifier.components.EnumField)1 Import (org.drools.verifier.components.Import)1 ObjectType (org.drools.verifier.components.ObjectType)1 Pattern (org.drools.verifier.components.Pattern)1 PatternVariable (org.drools.verifier.components.PatternVariable)1 ReturnValueRestriction (org.drools.verifier.components.ReturnValueRestriction)1 SubPattern (org.drools.verifier.components.SubPattern)1 Variable (org.drools.verifier.components.Variable)1 VariableRestriction (org.drools.verifier.components.VariableRestriction)1 Test (org.junit.Test)1