Search in sources :

Example 21 with InterpolationVariable

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

the class RHSGeneratorContext method setActionFieldValue.

private void setActionFieldValue(final ActionFieldValue afv) {
    this.afv = afv;
    final Set<InterpolationVariable> vars = new HashSet<InterpolationVariable>();
    final GeneratorContextRuleModelVisitor visitor = new GeneratorContextRuleModelVisitor(vars);
    visitor.visit(afv);
    for (InterpolationVariable var : vars) {
        varsInScope.add(var.getVarName());
    }
    hasNonTemplateOutput = visitor.hasNonTemplateOutput();
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashSet(java.util.HashSet)

Example 22 with InterpolationVariable

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

the class RHSGeneratorContext method setAction.

private void setAction(final IAction action) {
    this.action = action;
    final Set<InterpolationVariable> vars = new HashSet<InterpolationVariable>();
    final GeneratorContextRuleModelVisitor visitor = new GeneratorContextRuleModelVisitor(vars);
    visitor.visit(action);
    for (InterpolationVariable var : vars) {
        varsInScope.add(var.getVarName());
    }
    hasNonTemplateOutput = visitor.hasNonTemplateOutput();
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashSet(java.util.HashSet)

Example 23 with InterpolationVariable

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

the class RuleModelVisitor method parseStringPattern.

private void parseStringPattern(String text) {
    if (text == null || text.length() == 0) {
        return;
    }
    int pos = 0;
    while ((pos = text.indexOf("@{", pos)) != -1) {
        int end = text.indexOf('}', pos + 2);
        if (end != -1) {
            String varName = text.substring(pos + 2, end);
            pos = end + 1;
            InterpolationVariable var = new InterpolationVariable(varName, DataType.TYPE_OBJECT);
            if (!vars.containsKey(var)) {
                vars.put(var, vars.size());
            }
        }
    }
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) 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 24 with InterpolationVariable

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

the class GuidedDTDRLPersistence method hasVariables.

private boolean hasVariables(BRLActionColumn column) {
    Map<InterpolationVariable, Integer> ivs = new HashMap<InterpolationVariable, Integer>();
    RuleModel rm = new RuleModel();
    for (IAction action : column.getDefinition()) {
        rm.addRhsItem(action);
    }
    RuleModelVisitor rmv = new RuleModelVisitor(ivs);
    rmv.visit(rm);
    return ivs.size() > 0;
}
Also used : IAction(org.drools.workbench.models.datamodel.rule.IAction) 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 25 with InterpolationVariable

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

the class GuidedDTDRLPersistence method doAction.

private void doAction(List<BaseColumn> allColumns, BRLActionColumn column, List<LabelledAction> actions, TemplateDataProvider rowDataProvider, List<DTCellValue52> row, RuleModel rm) {
    // Check whether the parameter-less BRL fragment needs inclusion
    if (!hasVariables(column)) {
        final BRLActionVariableColumn variableColumn = column.getChildColumns().get(0);
        final int index = allColumns.indexOf(variableColumn);
        final DTCellValue52 dcv = row.get(index);
        if (dcv.getBooleanValue()) {
            for (IAction action : column.getDefinition()) {
                addAction(action, actions);
            }
        }
    } else {
        for (IAction action : column.getDefinition()) {
            boolean addAction = false;
            // Get interpolation variables used by the Action
            Map<InterpolationVariable, Integer> ivs = new HashMap<InterpolationVariable, Integer>();
            RuleModelVisitor rmv = new RuleModelVisitor(action, ivs);
            rmv.visit(action);
            if (ivs.size() == 0) {
                addAction = true;
            } else if (ivs.size() > 0) {
                // Ensure every key has a value and substitute keys for values
                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 (action instanceof FreeFormLine) {
                    addAction = templateKeyCount == ivs.size();
                } else if (templateKeyCount > 0) {
                    addAction = true;
                }
            }
            if (addAction) {
                addAction(action, actions);
            }
        }
    }
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) IAction(org.drools.workbench.models.datamodel.rule.IAction) RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashMap(java.util.HashMap) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

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