use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools by kiegroup.
the class RuleModelVisitor method visitSingleFieldConstraint.
private void visitSingleFieldConstraint(SingleFieldConstraint sfc) {
InterpolationVariable var = new InterpolationVariable(sfc.getValue(), sfc.getFieldType(), (factPattern == null ? "" : factPattern.getFactType()), sfc.getFieldName());
if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfc.getConstraintValueType() && !vars.containsKey(var)) {
vars.put(var, vars.size());
}
// 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.containsKey(ccVar)) {
vars.put(ccVar, vars.size());
}
}
}
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools by kiegroup.
the class RuleModelVisitor method visitSingleFieldConstraint.
private void visitSingleFieldConstraint(SingleFieldConstraintEBLeftSide sfexp) {
String genericType = sfexp.getExpressionLeftSide().getGenericType();
String factType = sfexp.getExpressionLeftSide().getPreviousClassType();
if (factType == null) {
factType = sfexp.getExpressionLeftSide().getClassType();
}
InterpolationVariable var = new InterpolationVariable(sfexp.getValue(), genericType, factType, sfexp.getFieldName());
if (BaseSingleFieldConstraint.TYPE_TEMPLATE == sfexp.getConstraintValueType() && !vars.containsKey(var)) {
vars.put(var, vars.size());
}
// 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.containsKey(ccVar)) {
vars.put(ccVar, vars.size());
}
}
}
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable 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);
}
}
}
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable 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;
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.
the class TemplateDataCellValueFactory method makeRowData.
/**
* Construct a new row of data for the underlying model
*
* @return
*/
public List<String> makeRowData() {
List<String> data = new ArrayList<String>();
InterpolationVariable[] variables = model.getInterpolationVariablesList();
for (InterpolationVariable var : variables) {
TemplateDataColumn column = makeModelColumn(var);
String dcv = makeModelCellValue(column);
data.add(dcv);
}
return data;
}
Aggregations