Search in sources :

Example 6 with InterpolationVariable

use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools by kiegroup.

the class RuleModelVisitor method visitSingleFieldConstraint.

private void visitSingleFieldConstraint(SingleFieldConstraint sfc) {
    InterpolationVariable var = new InterpolationVariable(sfc.getValue(), sfc.getFieldType(), (factPattern == null ? "" : factPattern.getFactType()), sfc.getFieldName());
    if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfc.getConstraintValueType() && !vars.containsKey(var)) {
        vars.put(var, vars.size());
    }
    // Visit Connection constraints
    if (sfc.getConnectives() != null) {
        for (int i = 0; i < sfc.getConnectives().length; i++) {
            final ConnectiveConstraint cc = sfc.getConnectives()[i];
            InterpolationVariable ccVar = new InterpolationVariable(cc.getValue(), cc.getFieldType(), (factPattern == null ? "" : factPattern.getFactType()), cc.getFieldName());
            if (BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey(ccVar)) {
                vars.put(ccVar, vars.size());
            }
        }
    }
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 7 with InterpolationVariable

use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools by kiegroup.

the class RuleModelVisitor method visitSingleFieldConstraint.

private void visitSingleFieldConstraint(SingleFieldConstraintEBLeftSide sfexp) {
    String genericType = sfexp.getExpressionLeftSide().getGenericType();
    String factType = sfexp.getExpressionLeftSide().getPreviousClassType();
    if (factType == null) {
        factType = sfexp.getExpressionLeftSide().getClassType();
    }
    InterpolationVariable var = new InterpolationVariable(sfexp.getValue(), genericType, factType, sfexp.getFieldName());
    if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfexp.getConstraintValueType() && !vars.containsKey(var)) {
        vars.put(var, vars.size());
    }
    // Visit Connection constraints
    if (sfexp.getConnectives() != null) {
        for (int i = 0; i < sfexp.getConnectives().length; i++) {
            final ConnectiveConstraint cc = sfexp.getConnectives()[i];
            InterpolationVariable ccVar = new InterpolationVariable(cc.getValue(), genericType, factType, cc.getFieldName());
            if (BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey(ccVar)) {
                vars.put(ccVar, vars.size());
            }
        }
    }
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 8 with InterpolationVariable

use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools by kiegroup.

the class GuidedDTDRLPersistence method doCondition.

private void doCondition(List<BaseColumn> allColumns, BRLConditionColumn column, List<IPattern> patterns, TemplateDataProvider rowDataProvider, List<DTCellValue52> row, RuleModel rm) {
    // Check whether the parameter-less BRL fragment needs inclusion
    if (!hasVariables(column)) {
        final BRLConditionVariableColumn variableColumn = column.getChildColumns().get(0);
        final int index = allColumns.indexOf(variableColumn);
        final DTCellValue52 dcv = row.get(index);
        if (dcv != null && dcv.getBooleanValue()) {
            for (IPattern pattern : column.getDefinition()) {
                patterns.add(pattern);
            }
        }
    } else {
        for (IPattern pattern : column.getDefinition()) {
            boolean addPattern = false;
            // Get interpolation variables used by the Pattern
            Map<InterpolationVariable, Integer> ivs = new HashMap<InterpolationVariable, Integer>();
            RuleModelVisitor rmv = new RuleModelVisitor(pattern, ivs);
            rmv.visit(pattern);
            if (ivs.size() == 0) {
                addPattern = true;
            } else if (ivs.size() > 0) {
                int templateKeyCount = 0;
                for (InterpolationVariable variable : ivs.keySet()) {
                    String value = rowDataProvider.getTemplateKeyValue(variable.getVarName());
                    if (!"".equals(value)) {
                        templateKeyCount++;
                    }
                }
                // Ensure at least one key has a value (FreeFormLines need all values to be provided)
                if (pattern instanceof FreeFormLine) {
                    addPattern = templateKeyCount == ivs.size();
                } else if (templateKeyCount > 0) {
                    addPattern = true;
                }
            }
            if (addPattern) {
                patterns.add(pattern);
            }
        }
    }
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashMap(java.util.HashMap) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 9 with InterpolationVariable

use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools by kiegroup.

the class GuidedDTDRLPersistence method hasVariables.

private boolean hasVariables(BRLConditionColumn column) {
    Map<InterpolationVariable, Integer> ivs = new HashMap<InterpolationVariable, Integer>();
    RuleModel rm = new RuleModel();
    for (IPattern pattern : column.getDefinition()) {
        rm.addLhsItem(pattern);
    }
    RuleModelVisitor rmv = new RuleModelVisitor(ivs);
    rmv.visit(rm);
    return ivs.size() > 0;
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashMap(java.util.HashMap) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel)

Example 10 with InterpolationVariable

use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.

the class TemplateDataCellValueFactory method makeRowData.

/**
 * Construct a new row of data for the underlying model
 *
 * @return
 */
public List<String> makeRowData() {
    List<String> data = new ArrayList<String>();
    InterpolationVariable[] variables = model.getInterpolationVariablesList();
    for (InterpolationVariable var : variables) {
        TemplateDataColumn column = makeModelColumn(var);
        String dcv = makeModelCellValue(column);
        data.add(dcv);
    }
    return data;
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) ArrayList(java.util.ArrayList)

Aggregations

InterpolationVariable (org.drools.workbench.models.datamodel.rule.InterpolationVariable)31 HashMap (java.util.HashMap)14 RuleModelVisitor (org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor)10 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)8 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)8 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)6 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)6 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)6 Map (java.util.Map)4 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)4 IAction (org.drools.workbench.models.datamodel.rule.IAction)3 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)3 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)3 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)3 BRLRuleModel (org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel)3 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)2 BRLVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn)2 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)2