use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.
the class TemplateDropDownManager method getCurrentValueMap.
/**
* Create a map of Field Values keyed on Field Names used by
* SuggestionCompletionEngine.getEnums(String, String, Map<String, String>)
* to drive dependent enumerations.
* @param context The Context of the cell being edited containing physical
* coordinate in the data-space.
*/
@Override
public Map<String, String> getCurrentValueMap(Context context) {
Map<String, String> currentValueMap = new HashMap<String, String>();
final int iBaseRowIndex = context.getIndex();
final int iBaseColIndex = context.getColumn();
// Get variable for the column being edited
InterpolationVariable[] allVariables = this.model.getInterpolationVariablesList();
InterpolationVariable baseVariable = allVariables[iBaseColIndex];
final String baseVariableName = baseVariable.getVarName();
// Get other variables (and literals) in the same scope as the base variable
final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(model, baseVariableName);
List<RuleModelPeerVariableVisitor.ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
// Add other variables values
for (RuleModelPeerVariableVisitor.ValueHolder valueHolder : peerVariables) {
switch(valueHolder.getType()) {
case TEMPLATE_KEY:
final int iCol = getVariableColumnIndex(valueHolder.getValue());
final InterpolationVariable variable = allVariables[iCol];
final String field = variable.getFactField();
// The generic class CellValue can have different data-types so
// we need to convert the cell's value to a String used by the
// dependent enumerations services
final CellValue<?> cv = this.data.get(iBaseRowIndex).get(iCol);
final TemplateDataColumn column = cellValueFactory.makeModelColumn(variable);
final String value = cellValueFactory.convertToModelCell(column, cv);
currentValueMap.put(field, value);
break;
case VALUE:
currentValueMap.put(valueHolder.getFieldName(), valueHolder.getValue());
}
}
return currentValueMap;
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.
the class BRLActionColumnPlugin method getDefinedVariables.
boolean getDefinedVariables(RuleModel ruleModel) {
Map<InterpolationVariable, Integer> ivs = new HashMap<InterpolationVariable, Integer>();
RuleModelVisitor rmv = new RuleModelVisitor(ivs);
rmv.visit(ruleModel);
// Update column and UI
editingCol.setChildColumns(convertInterpolationVariables(ivs));
return ivs.size() > 0;
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.
the class BRLActionColumnPlugin method convertInterpolationVariables.
private List<BRLActionVariableColumn> convertInterpolationVariables(Map<InterpolationVariable, Integer> ivs) {
// If there are no variables add a boolean column to specify whether the fragment should apply
if (ivs.isEmpty()) {
BRLActionVariableColumn variable = new BRLActionVariableColumn("", DataType.TYPE_BOOLEAN);
variable.setHeader(editingCol.getHeader());
variable.setHideColumn(editingCol.isHideColumn());
List<BRLActionVariableColumn> variables = new ArrayList<BRLActionVariableColumn>();
variables.add(variable);
return variables;
}
// Convert to columns for use in the Decision Table
BRLActionVariableColumn[] variables = new BRLActionVariableColumn[ivs.size()];
for (Map.Entry<InterpolationVariable, Integer> me : ivs.entrySet()) {
InterpolationVariable iv = me.getKey();
int index = me.getValue();
BRLActionVariableColumn variable = new BRLActionVariableColumn(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<BRLActionVariableColumn> variableList = new ArrayList<BRLActionVariableColumn>();
for (BRLActionVariableColumn variable : variables) {
variableList.add(variable);
}
return variableList;
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.
the class BRLConditionColumnPlugin method getDefinedVariables.
boolean getDefinedVariables(RuleModel ruleModel) {
Map<InterpolationVariable, Integer> ivs = new HashMap<InterpolationVariable, Integer>();
RuleModelVisitor rmv = new RuleModelVisitor(ivs);
rmv.visit(ruleModel);
// Update column and UI
editingCol.setChildColumns(convertInterpolationVariables(ivs));
return ivs.size() > 0;
}
use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.
the class GuidedDecisionTablePopulater method addIndirectSourceBuildersColumns.
private void addIndirectSourceBuildersColumns() {
final List<BRLVariableColumn> variableColumns = new ArrayList<BRLVariableColumn>();
for (GuidedDecisionTableSourceBuilder sb : sourceBuilders) {
if (sb instanceof GuidedDecisionTableSourceBuilderIndirect) {
for (BRLVariableColumn variableColumn : ((GuidedDecisionTableSourceBuilderIndirect) sb).getVariableColumns()) {
variableColumns.add(variableColumn);
}
}
}
// Convert the DRL to a RuleModel from which we construct BRLFragment columns
final StringBuilder rule = new StringBuilder();
if (!(dmo.getPackageName() == null || dmo.getPackageName().isEmpty())) {
rule.append("package ").append(dmo.getPackageName()).append("\n");
}
rule.append("rule 'temp' \n").append("when \n");
for (GuidedDecisionTableSourceBuilder sb : sourceBuilders) {
if (sb instanceof GuidedDecisionTableLHSBuilder) {
rule.append(sb.getResult());
}
}
rule.append("\nthen \n");
for (GuidedDecisionTableSourceBuilder sb : sourceBuilders) {
if (sb instanceof GuidedDecisionTableRHSBuilder) {
rule.append(sb.getResult());
}
}
rule.append("end");
final RuleModel rm = RuleModelDRLPersistenceImpl.getInstance().unmarshal(rule.toString(), Collections.emptyList(), dmo);
if (rm.lhs != null) {
for (IPattern pattern : rm.lhs) {
final BRLConditionColumn column = new BRLConditionColumn();
column.getDefinition().add(pattern);
dtable.getConditions().add(column);
final Map<InterpolationVariable, Integer> templateKeys = new HashMap<>();
final RuleModelVisitor rmv = new RuleModelVisitor(templateKeys);
rmv.visit(pattern);
final List<InterpolationVariable> ivs = new ArrayList<>(templateKeys.keySet());
for (BRLVariableColumn variableColumn : variableColumns) {
final Iterator<InterpolationVariable> ivsIts = ivs.iterator();
while (ivsIts.hasNext()) {
final InterpolationVariable iv = ivsIts.next();
if (iv.getVarName().equals(variableColumn.getVarName())) {
final BRLConditionVariableColumn source = (BRLConditionVariableColumn) variableColumn;
final BRLConditionVariableColumn target = makeBRLConditionVariableColumn(source, iv);
column.getChildColumns().add(target);
ivsIts.remove();
}
}
}
if (column.getChildColumns().isEmpty()) {
setZeroParameterConditionColumnHeader(column, variableColumns);
} else {
setCompositeColumnHeader(column);
}
}
}
if (rm.rhs != null) {
for (IAction action : rm.rhs) {
final BRLActionColumn column = new BRLActionColumn();
column.getDefinition().add(action);
dtable.getActionCols().add(column);
if (action instanceof ActionRetractFact) {
final ActionRetractFact arf = (ActionRetractFact) action;
createActionRetractFactChildColumns(arf, column, variableColumns);
} else {
createRHSChildColumns(rm, action, column, variableColumns);
}
if (column.getChildColumns().isEmpty()) {
setZeroParameterActionColumnHeader(column, variableColumns);
} else {
setCompositeColumnHeader(column);
}
}
}
}
Aggregations