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;
}
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;
}
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));
}
}
}
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;
}
}
}
}
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);
}
}
}
}
Aggregations