Search in sources :

Example 16 with InterpolationVariable

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

the class BRLConditionColumnPlugin method convertInterpolationVariables.

private List<BRLConditionVariableColumn> convertInterpolationVariables(Map<InterpolationVariable, Integer> ivs) {
    // If there are no variables add a boolean column to specify whether the fragment should apply
    if (ivs.isEmpty()) {
        BRLConditionVariableColumn variable = new BRLConditionVariableColumn("", DataType.TYPE_BOOLEAN);
        variable.setHeader(editingCol.getHeader());
        variable.setHideColumn(editingCol.isHideColumn());
        List<BRLConditionVariableColumn> variables = new ArrayList<BRLConditionVariableColumn>();
        variables.add(variable);
        return variables;
    }
    // Convert to columns for use in the Decision Table
    BRLConditionVariableColumn[] variables = new BRLConditionVariableColumn[ivs.size()];
    for (Map.Entry<InterpolationVariable, Integer> me : ivs.entrySet()) {
        InterpolationVariable iv = me.getKey();
        int index = me.getValue();
        BRLConditionVariableColumn variable = new BRLConditionVariableColumn(iv.getVarName(), iv.getDataType(), iv.getFactType(), iv.getFactField());
        variable.setHeader(editingCol.getHeader());
        variable.setHideColumn(editingCol.isHideColumn());
        variables[index] = variable;
    }
    // Convert the array into a mutable list (Arrays.toList provides an immutable list)
    List<BRLConditionVariableColumn> variableList = new ArrayList<BRLConditionVariableColumn>();
    for (BRLConditionVariableColumn variable : variables) {
        variableList.add(variable);
    }
    return variableList;
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) ArrayList(java.util.ArrayList) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with InterpolationVariable

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

the class GeneratorContextRuleModelVisitor method visitSingleFieldConstraint.

private void visitSingleFieldConstraint(final SingleFieldConstraintEBLeftSide sfexp) {
    final String genericType = sfexp.getExpressionLeftSide().getGenericType();
    String factType = sfexp.getExpressionLeftSide().getPreviousClassType();
    if (factType == null) {
        factType = sfexp.getExpressionLeftSide().getClassType();
    }
    final InterpolationVariable var = new InterpolationVariable(sfexp.getValue(), genericType, factType, sfexp.getFieldName());
    if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfexp.getConstraintValueType() && !vars.contains(var)) {
        vars.add(var);
    } else {
        hasNonTemplateOutput = true;
    }
    // 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.contains(ccVar)) {
                vars.add(ccVar);
            } else {
                hasNonTemplateOutput = true;
            }
        }
    }
}
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 18 with InterpolationVariable

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

the class LHSGeneratorContext method setPattern.

private void setPattern(final IPattern pattern) {
    this.pattern = pattern;
    this.varsInScope.clear();
    final Set<InterpolationVariable> vars = new HashSet<InterpolationVariable>();
    final GeneratorContextRuleModelVisitor visitor = new GeneratorContextRuleModelVisitor(vars);
    visitor.visit(pattern);
    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 19 with InterpolationVariable

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

the class LHSGeneratorContext method setFieldConstraint.

private void setFieldConstraint(final FieldConstraint fieldConstraint) {
    this.fieldConstraint = fieldConstraint;
    this.varsInScope.clear();
    final Set<InterpolationVariable> vars = new HashSet<InterpolationVariable>();
    final GeneratorContextRuleModelVisitor visitor = new GeneratorContextRuleModelVisitor(vars);
    visitor.visit(fieldConstraint);
    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 20 with InterpolationVariable

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

the class RuleTemplateModelDRLPersistenceImpl method marshalRuleHeader.

@Override
protected void marshalRuleHeader(final RuleModel model, final StringBuilder buf) {
    // Append Template header
    TemplateModel templateModel = (TemplateModel) model;
    buf.append("template header\n");
    InterpolationVariable[] interpolationVariables = templateModel.getInterpolationVariablesList();
    if (interpolationVariables.length == 0) {
        buf.append("test_var").append('\n');
    } else {
        for (InterpolationVariable var : interpolationVariables) {
            buf.append(var.getVarName()).append('\n');
        }
    }
    buf.append("\n");
    // Append Package header
    super.marshalPackageHeader(model, buf);
    // Append Template definition
    buf.append("\ntemplate \"").append(super.marshalRuleName(templateModel)).append("\"\n\n");
    super.marshalRuleHeader(model, buf);
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel)

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