Search in sources :

Example 1 with BRLVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn in project drools by kiegroup.

the class GuidedDecisionTableUpgradeHelper3 method upgrade.

/**
 * Convert the Default Values in the Decision Table model
 *
 * @param source
 * @return The new DTModel
 */
public GuidedDecisionTable52 upgrade(GuidedDecisionTable52 source) {
    final GuidedDecisionTable52 destination = source;
    for (BaseColumn column : source.getExpandedColumns()) {
        DTColumnConfig52 dtColumn = null;
        if (column instanceof MetadataCol52) {
            dtColumn = (DTColumnConfig52) column;
        } else if (column instanceof AttributeCol52) {
            dtColumn = (DTColumnConfig52) column;
        } else if (column instanceof ConditionCol52) {
            dtColumn = (DTColumnConfig52) column;
        } else if (column instanceof ActionCol52) {
            dtColumn = (DTColumnConfig52) column;
        }
        if (dtColumn instanceof LimitedEntryCol) {
            dtColumn = null;
        }
        if (dtColumn instanceof BRLVariableColumn) {
            dtColumn = null;
        }
        if (dtColumn != null) {
            final String legacyDefaultValue = dtColumn.defaultValue;
            if (legacyDefaultValue != null) {
                dtColumn.setDefaultValue(new DTCellValue52(legacyDefaultValue));
                dtColumn.defaultValue = null;
            }
        }
    }
    return destination;
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) DTColumnConfig52(org.drools.workbench.models.guided.dtable.shared.model.DTColumnConfig52) BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol)

Example 2 with BRLVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn in project drools-wb by kiegroup.

the class DecisionTableAnalyzer method getColumnIndex.

private int getColumnIndex(final BaseColumn baseColumn) {
    List<BaseColumn> cols = model.getExpandedColumns();
    final int indexOf = cols.indexOf(baseColumn);
    if (indexOf < 0) {
        if (baseColumn instanceof BRLConditionColumn) {
            for (final BaseColumn column : model.getExpandedColumns()) {
                if (column instanceof BRLConditionVariableColumn) {
                    if (((BRLConditionColumn) baseColumn).getChildColumns().contains(column)) {
                        return model.getExpandedColumns().indexOf(column);
                    }
                }
            }
            throw new IllegalArgumentException("Could not find BRLConditionColumn: " + baseColumn.toString());
        }
        if (baseColumn instanceof BRLActionColumn) {
            for (final BaseColumn column : model.getExpandedColumns()) {
                if (column instanceof BRLActionVariableColumn) {
                    if (((BRLActionColumn) baseColumn).getChildColumns().contains(column)) {
                        return model.getExpandedColumns().indexOf(column);
                    }
                }
            }
            throw new IllegalArgumentException("Could not find BRLActionColumn: " + baseColumn.toString());
        } else if (baseColumn instanceof BRLVariableColumn) {
            return model.getExpandedColumns().indexOf(model.getBRLColumn((BRLVariableColumn) baseColumn));
        } else {
            throw new IllegalArgumentException("Could not find baseColumn: " + baseColumn.toString());
        }
    } else {
        return indexOf;
    }
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 3 with BRLVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn 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);
            }
        }
    }
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) GuidedDecisionTableRHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder) IAction(org.drools.workbench.models.datamodel.rule.IAction) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GuidedDecisionTableSourceBuilderIndirect(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilderIndirect) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) GuidedDecisionTableSourceBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder) RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) GuidedDecisionTableLHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder)

Example 4 with BRLVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn in project drools-wb by kiegroup.

the class GuidedDecisionTablePopulater method createActionRetractFactChildColumns.

private void createActionRetractFactChildColumns(final ActionRetractFact arf, final BRLActionColumn column, final List<BRLVariableColumn> variableColumns) {
    // Check whether the ActionRetractFact column has been defined as a parameter in the XLS.
    // This is unsupported in the Guided Rule Editor (Guided Decision Table Editor BRLFragments)
    // and hence the source column needs to be updated to reflect what is supported.
    final String var = arf.getVariableName();
    final Set<String> templateKeys = parameterUtilities.extractTemplateKeys(var);
    final String templateKey = templateKeys.isEmpty() ? var : templateKeys.iterator().next();
    final List<ParameterizedValueBuilder> valueBuilders = getOrderedValueBuilders();
    for (BRLVariableColumn variableColumn : variableColumns) {
        if (templateKey.equals(variableColumn.getVarName())) {
            final BRLActionVariableColumn source = (BRLActionVariableColumn) variableColumn;
            final BRLActionVariableColumn target = new BRLActionVariableColumn(templateKey, DataType.TYPE_BOOLEAN);
            target.setHeader(source.getHeader());
            target.setHideColumn(source.isHideColumn());
            column.getChildColumns().add(target);
            for (GuidedDecisionTableSourceBuilder sb : sourceBuilders) {
                if (sb instanceof GuidedDecisionTableRHSBuilder) {
                    final GuidedDecisionTableRHSBuilder rhs = (GuidedDecisionTableRHSBuilder) sb;
                    for (ParameterizedValueBuilder pvb : rhs.getValueBuilders().values()) {
                        if (pvb.getParameters().contains(templateKey)) {
                            Optional<String> firstBinding = Optional.empty();
                            final int pvbIndex = pvb.getParameters().indexOf(templateKey);
                            final List<List<DTCellValue52>> pvbData = pvb.getColumnData();
                            for (int iRowIndex = 0; iRowIndex < pvbData.size(); iRowIndex++) {
                                final List<DTCellValue52> pvbRow = pvbData.get(iRowIndex);
                                final String binding = pvbRow.get(pvbIndex).getStringValue();
                                if (!(binding == null || binding.isEmpty())) {
                                    if (!arf.getVariableName().equals(binding)) {
                                        final int _rowIndex = ruleRowStartIndex + iRowIndex + 1;
                                        final int _columnIndex = ruleColumnStartIndex + valueBuilders.indexOf(pvb) + 1;
                                        if (firstBinding.isPresent()) {
                                            addConversionMessage("Removing Retract binding for " + binding + ". See previous conversion messages for details.", _rowIndex, _columnIndex);
                                            pvbRow.get(pvbIndex).clearValues();
                                        } else {
                                            addConversionMessage("Setting Retract to use first binding, " + binding + ". Others will be removed.", _rowIndex, _columnIndex);
                                            arf.setVariableName(binding);
                                            pvbRow.get(pvbIndex).setBooleanValue(true);
                                            firstBinding = Optional.of(binding);
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
            break;
        }
    }
}
Also used : GuidedDecisionTableRHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) ParameterizedValueBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder) GuidedDecisionTableSourceBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder) BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) ArrayList(java.util.ArrayList) List(java.util.List) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)

Example 5 with BRLVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn in project drools-wb by kiegroup.

the class GuidedDecisionTableLHSBuilder method addBRLFragmentColumn.

private List<BRLVariableColumn> addBRLFragmentColumn(final ParameterizedValueBuilder vb) {
    final List<BRLVariableColumn> variableColumns = new ArrayList<BRLVariableColumn>();
    for (String parameter : vb.getParameters()) {
        final BRLConditionVariableColumn parameterColumn = new BRLConditionVariableColumn(parameter, DataType.TYPE_OBJECT);
        variableColumns.add(parameterColumn);
    }
    // Store DRL fragment for use by GuidedDecisionTableRHSBuilder
    drlFragments.add(vb.getTemplate());
    return variableColumns;
}
Also used : BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) ArrayList(java.util.ArrayList) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Aggregations

BRLVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn)13 ArrayList (java.util.ArrayList)10 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)6 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)6 TreeSet (java.util.TreeSet)3 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)3 HashMap (java.util.HashMap)2 InterpolationVariable (org.drools.workbench.models.datamodel.rule.InterpolationVariable)2 RuleModelVisitor (org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor)2 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)2 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)2 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)2 GuidedDecisionTableRHSBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder)2 GuidedDecisionTableSourceBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder)2 ParameterizedValueBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder)2 List (java.util.List)1 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)1 IAction (org.drools.workbench.models.datamodel.rule.IAction)1 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)1 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)1