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