Search in sources :

Example 1 with InterpolationVariable

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

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

the class TemplateModel method getTableAsArray.

public String[][] getTableAsArray() {
    if (rowsCount <= 0) {
        return new String[0][0];
    }
    // Refresh against interpolation variables
    putInSync();
    String[][] ret = new String[rowsCount][table.size() - 1];
    Map<InterpolationVariable, Integer> vars = getInterpolationVariables();
    for (Map.Entry<InterpolationVariable, Integer> entry : vars.entrySet()) {
        InterpolationVariable var = entry.getKey();
        String varName = var.getVarName();
        if (ID_COLUMN_NAME.equals(varName)) {
            continue;
        }
        int idx = entry.getValue();
        for (int row = 0; row < rowsCount; row++) {
            ret[row][idx] = table.get(varName).get(row);
        }
    }
    return ret;
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with InterpolationVariable

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

the class TemplateModel method putInSync.

public void putInSync() {
    // Nothing to synchronize
    if (table == null) {
        return;
    }
    // vars.KeySet is a set of InterpolationVariable, whereas table.keySet is a set of String
    Map<InterpolationVariable, Integer> vars = getInterpolationVariables();
    // Retain all columns in table that are in vars
    Set<String> requiredVars = new HashSet<String>();
    for (InterpolationVariable var : vars.keySet()) {
        if (table.containsKey(var.getVarName())) {
            requiredVars.add(var.getVarName());
        }
    }
    table.keySet().retainAll(requiredVars);
    // Add empty columns for all vars that are not in table
    List<String> aux = new ArrayList<String>(rowsCount);
    for (int i = 0; i < rowsCount; i++) {
        aux.add("");
    }
    for (InterpolationVariable var : vars.keySet()) {
        if (!requiredVars.contains(var.getVarName())) {
            table.put(var.getVarName(), new ArrayList<String>(aux));
        }
    }
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 4 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 SingleFieldConstraint sfc) {
    final InterpolationVariable var = new InterpolationVariable(sfc.getValue(), sfc.getFieldType(), (factPattern == null ? "" : factPattern.getFactType()), sfc.getFieldName());
    if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfc.getConstraintValueType() && !vars.contains(var)) {
        vars.add(var);
    } else {
        hasNonTemplateOutput = true;
    }
    // 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.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 5 with InterpolationVariable

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

the class GeneratorContextRuleModelVisitor method parseStringPattern.

private void parseStringPattern(final 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) {
            final String varName = text.substring(pos + 2, end);
            pos = end + 1;
            InterpolationVariable var = new InterpolationVariable(varName, DataType.TYPE_OBJECT);
            if (!vars.contains(var)) {
                vars.add(var);
            }
        }
    }
}
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)

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