Search in sources :

Example 1 with RuleModelVisitor

use of org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor 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 2 with RuleModelVisitor

use of org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor 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 3 with RuleModelVisitor

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

the class TemplateModel method getInterpolationVariables.

private Map<InterpolationVariable, Integer> getInterpolationVariables() {
    Map<InterpolationVariable, Integer> result = new HashMap<InterpolationVariable, Integer>();
    new RuleModelVisitor(result).visit(this);
    InterpolationVariable id = new InterpolationVariable(ID_COLUMN_NAME, DataType.TYPE_NUMERIC_LONG);
    result.put(id, result.size());
    return result;
}
Also used : RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashMap(java.util.HashMap)

Example 4 with RuleModelVisitor

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

the class BRLActionColumnPlugin method getDefinedVariables.

boolean getDefinedVariables(RuleModel ruleModel) {
    Map<InterpolationVariable, Integer> ivs = new HashMap<InterpolationVariable, Integer>();
    RuleModelVisitor rmv = new RuleModelVisitor(ivs);
    rmv.visit(ruleModel);
    // Update column and UI
    editingCol.setChildColumns(convertInterpolationVariables(ivs));
    return ivs.size() > 0;
}
Also used : RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashMap(java.util.HashMap)

Example 5 with RuleModelVisitor

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

the class BRLConditionColumnPlugin method getDefinedVariables.

boolean getDefinedVariables(RuleModel ruleModel) {
    Map<InterpolationVariable, Integer> ivs = new HashMap<InterpolationVariable, Integer>();
    RuleModelVisitor rmv = new RuleModelVisitor(ivs);
    rmv.visit(ruleModel);
    // Update column and UI
    editingCol.setChildColumns(convertInterpolationVariables(ivs));
    return ivs.size() > 0;
}
Also used : RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)10 InterpolationVariable (org.drools.workbench.models.datamodel.rule.InterpolationVariable)10 RuleModelVisitor (org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor)10 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 BRLRuleModel (org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel)3 ArrayList (java.util.ArrayList)2 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)2 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)2 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)2 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)2 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)2 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)2 BRLVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn)2 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)2 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)1 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)1 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)1 GuidedDecisionTableLHSBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder)1