Search in sources :

Example 1 with ParameterizedValueBuilder

use of org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder 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 2 with ParameterizedValueBuilder

use of org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder in project drools-wb by kiegroup.

the class GuidedDecisionTableGeneratorListener method assertValueBuildersRowData.

private void assertValueBuildersRowData() {
    // new row is created the GuidedDecisionTableSourceBuilders contain sufficient row data
    if (_sourceBuilders != null) {
        final int rowCount = getRowCount();
        final int columnCount = _sourceBuilders.size();
        for (GuidedDecisionTableSourceBuilder sb : _sourceBuilders) {
            if (sb instanceof GuidedDecisionTableSourceBuilderDirect) {
                final GuidedDecisionTableSourceBuilderDirect sbd = (GuidedDecisionTableSourceBuilderDirect) sb;
                if (sbd.getRowCount() < rowCount) {
                    sbd.addCellValue(rowCount, columnCount, "");
                }
            } else if (sb instanceof GuidedDecisionTableSourceBuilderIndirect) {
                final GuidedDecisionTableSourceBuilderIndirect sbi = (GuidedDecisionTableSourceBuilderIndirect) sb;
                for (ParameterizedValueBuilder pvb : sbi.getValueBuilders().values()) {
                    if (pvb.getColumnData().size() < rowCount) {
                        pvb.addCellValue(rowCount, columnCount, "");
                    }
                }
            }
        }
    }
}
Also used : ParameterizedValueBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder) GuidedDecisionTableSourceBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder) GuidedDecisionTableSourceBuilderDirect(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilderDirect) GuidedDecisionTableSourceBuilderIndirect(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilderIndirect)

Example 3 with ParameterizedValueBuilder

use of org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder in project drools-wb by kiegroup.

the class GuidedDecisionTablePopulater method getOrderedValueBuilders.

private List<ParameterizedValueBuilder> getOrderedValueBuilders() {
    // Get ordered list of ParameterizedValueBuilder for all GuidedDecisionTableSourceBuilderIndirect instances
    // An ordered list of ParameterizedValueBuilder guarantees they are checked in the same order as columns
    // were added to the Guided Decision Table.
    final List<ParameterizedValueBuilder> valueBuilders = new ArrayList<>();
    for (GuidedDecisionTableSourceBuilder sb : sourceBuilders) {
        if (sb instanceof GuidedDecisionTableSourceBuilderIndirect) {
            final GuidedDecisionTableSourceBuilderIndirect isb = (GuidedDecisionTableSourceBuilderIndirect) sb;
            final Set<Integer> sortedIndexes = new TreeSet<>(isb.getValueBuilders().keySet());
            for (Integer index : sortedIndexes) {
                final ParameterizedValueBuilder vb = isb.getValueBuilders().get(index);
                valueBuilders.add(vb);
            }
        }
    }
    return valueBuilders;
}
Also used : ParameterizedValueBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder) GuidedDecisionTableSourceBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) GuidedDecisionTableSourceBuilderIndirect(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilderIndirect)

Example 4 with ParameterizedValueBuilder

use of org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder in project drools-wb by kiegroup.

the class GuidedDecisionTablePopulater method addIndirectSourceBuildersData.

private void addIndirectSourceBuildersData(final int maxRowCount) {
    final List<ParameterizedValueBuilder> valueBuilders = getOrderedValueBuilders();
    final List<BaseColumn> allColumns = dtable.getExpandedColumns();
    for (int iColIndex = 0; iColIndex < allColumns.size(); iColIndex++) {
        final BaseColumn column = allColumns.get(iColIndex);
        if (column instanceof BRLVariableColumn) {
            final String varName = ((BRLVariableColumn) column).getVarName();
            final String varDataType = ((BRLVariableColumn) column).getFieldType();
            assertDecisionTableData(varName, varDataType, valueBuilders, maxRowCount);
        }
    }
}
Also used : ParameterizedValueBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder) BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)

Example 5 with ParameterizedValueBuilder

use of org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder in project drools-wb by kiegroup.

the class GuidedDecisionTablePopulater method assertDecisionTableData.

private void assertDecisionTableData(final String varName, final String varDataType, final List<ParameterizedValueBuilder> valueBuilders, final int maxRowCount) {
    if (varName.equals("")) {
        for (ParameterizedValueBuilder pvb : valueBuilders) {
            if (pvb instanceof LiteralValueBuilder) {
                for (int iRowIndex = 0; iRowIndex < maxRowCount; iRowIndex++) {
                    final int _rowIndex = ruleRowStartIndex + iRowIndex + 1;
                    final int _columnIndex = ruleColumnStartIndex + valueBuilders.indexOf(pvb) + 1;
                    final List<DTCellValue52> fragmentRow = pvb.getColumnData().get(iRowIndex);
                    final List<DTCellValue52> dtableRow = dtable.getData().get(iRowIndex);
                    final DTCellValue52 fragmentCell = fragmentRow.get(0);
                    assertDTCellValue(varDataType, fragmentCell, (final String value, final DataType.DataTypes dataType) -> addConversionMessage(value, dataType, _rowIndex, _columnIndex));
                    dtableRow.add(fragmentCell);
                }
                break;
            }
        }
    } else {
        for (ParameterizedValueBuilder pvb : valueBuilders) {
            final int varNameIndex = pvb.getParameters().indexOf(varName);
            if (varNameIndex > -1) {
                for (int iRowIndex = 0; iRowIndex < maxRowCount; iRowIndex++) {
                    final int _rowIndex = ruleRowStartIndex + iRowIndex + 1;
                    final int _columnIndex = ruleColumnStartIndex + valueBuilders.indexOf(pvb) + 1;
                    final List<DTCellValue52> fragmentRow = pvb.getColumnData().get(iRowIndex);
                    final List<DTCellValue52> dtableRow = dtable.getData().get(iRowIndex);
                    final DTCellValue52 fragmentCell = fragmentRow.get(varNameIndex);
                    assertDTCellValue(varDataType, fragmentCell, (final String value, final DataType.DataTypes dataType) -> addConversionMessage(value, dataType, _rowIndex, _columnIndex));
                    dtableRow.add(fragmentCell);
                }
                break;
            }
        }
    }
}
Also used : ParameterizedValueBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder) LiteralValueBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.LiteralValueBuilder) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)

Aggregations

ParameterizedValueBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.ParameterizedValueBuilder)5 GuidedDecisionTableSourceBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder)3 ArrayList (java.util.ArrayList)2 BRLVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn)2 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)2 GuidedDecisionTableSourceBuilderIndirect (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilderIndirect)2 List (java.util.List)1 TreeSet (java.util.TreeSet)1 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)1 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)1 GuidedDecisionTableRHSBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder)1 GuidedDecisionTableSourceBuilderDirect (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilderDirect)1 LiteralValueBuilder (org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.LiteralValueBuilder)1