Search in sources :

Example 41 with BRLConditionVariableColumn

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

the class BRLConditionColumnDefinitionBuilder method generateDefinition.

@Override
public void generateDefinition(final GuidedDecisionTableView.Presenter dtPresenter, final BaseColumn column, final Callback<String> afterGenerationCallback) {
    if (!(column instanceof BRLConditionVariableColumn)) {
        return;
    }
    final GuidedDecisionTable52 existingModel = dtPresenter.getModel();
    final BRLConditionVariableColumn brlVariableColumn = (BRLConditionVariableColumn) column;
    final BRLConditionColumn brlColumn = existingModel.getBRLColumn(brlVariableColumn);
    final GuidedDecisionTable52 partialModel = new GuidedDecisionTable52();
    final ColumnUtilities columnUtilities = new ColumnUtilities(existingModel, dtPresenter.getDataModelOracle());
    partialModel.getConditions().add(brlColumn);
    partialModel.getData().add(makeRowData(columnUtilities, brlColumn));
    generateDefinitionOnServer(partialModel, dtPresenter.getCurrentPath(), (String drl) -> afterGenerationCallback.callback(getLHS(drl)));
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) ColumnUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 42 with BRLConditionVariableColumn

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

the class BRLConditionColumnDefinitionBuilder method makeRowData.

private List<DTCellValue52> makeRowData(final ColumnUtilities columnUtilities, final BRLConditionColumn brlColumn) {
    final List<DTCellValue52> row = new ArrayList<>();
    row.add(new DTCellValue52(1));
    row.add(new DTCellValue52("desc"));
    for (BRLConditionVariableColumn brlVariableColumn : brlColumn.getChildColumns()) {
        final DataType.DataTypes dataType = columnUtilities.getDataType(brlVariableColumn);
        row.add(makeCell(dataType));
    }
    return row;
}
Also used : ArrayList(java.util.ArrayList) DataType(org.kie.soup.project.datamodel.oracle.DataType) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 43 with BRLConditionVariableColumn

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

the class DependentEnumsUtilities 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(final Context context) {
    Map<String, String> currentValueMap = new HashMap<String, String>();
    final int iBaseRowIndex = context.getRowIndex();
    final int iBaseColIndex = context.getColumnIndex();
    final List<DTCellValue52> rowData = this.model.getData().get(iBaseRowIndex);
    // Get the column for the cell being edited
    final List<BaseColumn> allColumns = this.model.getExpandedColumns();
    final BaseColumn baseColumn = allColumns.get(iBaseColIndex);
    // Get values for all Constraints or Actions on the same pattern as the baseColumn
    if (baseColumn instanceof BRLConditionVariableColumn) {
        final BRLConditionVariableColumn baseBRLConditionColumn = (BRLConditionVariableColumn) baseColumn;
        final BRLConditionColumn brl = model.getBRLColumn(baseBRLConditionColumn);
        final RuleModel rm = new RuleModel();
        IPattern[] lhs = new IPattern[brl.getDefinition().size()];
        brl.getDefinition().toArray(lhs);
        rm.lhs = lhs;
        final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(rm, baseBRLConditionColumn.getVarName());
        List<ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
        // Add other variables values
        for (ValueHolder valueHolder : peerVariables) {
            switch(valueHolder.getType()) {
                case TEMPLATE_KEY:
                    final BRLConditionVariableColumn vc = getConditionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
                    final int iCol = allColumns.indexOf(vc);
                    final DTCellValue52 dcv = rowData.get(iCol);
                    final String field = vc.getFactField();
                    currentValueMap.put(field, cellUtilities.asString(dcv));
                    break;
                case VALUE:
                    currentValueMap.put(valueHolder.getFieldName(), valueHolder.getValue());
            }
        }
    } else if (baseColumn instanceof BRLActionVariableColumn) {
        final BRLActionVariableColumn baseBRLActionColumn = (BRLActionVariableColumn) baseColumn;
        final BRLActionColumn brl = model.getBRLColumn(baseBRLActionColumn);
        final RuleModel rm = new RuleModel();
        IAction[] rhs = new IAction[brl.getDefinition().size()];
        brl.getDefinition().toArray(rhs);
        rm.rhs = rhs;
        final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(rm, baseBRLActionColumn.getVarName());
        List<ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
        // Add other variables values
        for (ValueHolder valueHolder : peerVariables) {
            switch(valueHolder.getType()) {
                case TEMPLATE_KEY:
                    final BRLActionVariableColumn vc = getActionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
                    final int iCol = allColumns.indexOf(vc);
                    final DTCellValue52 dcv = rowData.get(iCol);
                    final String field = vc.getFactField();
                    currentValueMap.put(field, cellUtilities.asString(dcv));
                    break;
                case VALUE:
                    currentValueMap.put(valueHolder.getFieldName(), valueHolder.getValue());
            }
        }
    } else if (baseColumn instanceof ConditionCol52) {
        final ConditionCol52 baseConditionColumn = (ConditionCol52) baseColumn;
        final Pattern52 basePattern = this.model.getPattern(baseConditionColumn);
        for (ConditionCol52 cc : basePattern.getChildColumns()) {
            final int iCol = allColumns.indexOf(cc);
            final DTCellValue52 dcv = rowData.get(iCol);
            currentValueMap.put(cc.getFactField(), cellUtilities.asString(dcv));
        }
    } else if (baseColumn instanceof ActionSetFieldCol52) {
        ActionSetFieldCol52 baseActionColumn = (ActionSetFieldCol52) baseColumn;
        final String binding = baseActionColumn.getBoundName();
        for (ActionCol52 ac : this.model.getActionCols()) {
            if (ac instanceof ActionSetFieldCol52) {
                final ActionSetFieldCol52 asf = (ActionSetFieldCol52) ac;
                if (asf.getBoundName().equals(binding)) {
                    final int iCol = allColumns.indexOf(asf);
                    final DTCellValue52 dcv = rowData.get(iCol);
                    currentValueMap.put(asf.getFactField(), cellUtilities.asString(dcv));
                }
            }
        }
    } else if (baseColumn instanceof ActionInsertFactCol52) {
        ActionInsertFactCol52 baseActionColumn = (ActionInsertFactCol52) baseColumn;
        final String binding = baseActionColumn.getBoundName();
        for (ActionCol52 ac : this.model.getActionCols()) {
            if (ac instanceof ActionInsertFactCol52) {
                final ActionInsertFactCol52 aif = (ActionInsertFactCol52) ac;
                if (aif.getBoundName().equals(binding)) {
                    final int iCol = allColumns.indexOf(aif);
                    final DTCellValue52 dcv = rowData.get(iCol);
                    currentValueMap.put(aif.getFactField(), cellUtilities.asString(dcv));
                }
            }
        }
    }
    return currentValueMap;
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) HashMap(java.util.HashMap) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) ValueHolder(org.drools.workbench.screens.guided.template.client.editor.RuleModelPeerVariableVisitor.ValueHolder) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) RuleModelPeerVariableVisitor(org.drools.workbench.screens.guided.template.client.editor.RuleModelPeerVariableVisitor) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) List(java.util.List) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)

Example 44 with BRLConditionVariableColumn

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

the class BRLConditionColumnSynchronizer method update.

@Override
public List<BaseColumnFieldDiff> update(final ColumnMetaData originalMetaData, final ColumnMetaData editedMetaData) throws VetoException {
    // Check operation is supported
    if (!(handlesUpdate(originalMetaData) && handlesUpdate(editedMetaData))) {
        return Collections.emptyList();
    }
    // Check whether any discarded bindings were used. If so veto the update.
    final BRLConditionColumn originalColumn = (BRLConditionColumn) originalMetaData.getColumn();
    final BRLConditionColumn editedColumn = (BRLConditionColumn) editedMetaData.getColumn();
    final Set<String> originalBindings = getPatternBindings(originalColumn);
    final Set<String> editedBindings = getPatternBindings(editedColumn);
    originalBindings.removeAll(editedBindings);
    for (String binding : originalBindings) {
        if (rm.isBoundFactUsed(binding)) {
            throw new VetoUpdatePatternInUseException();
        }
    }
    final List<BaseColumnFieldDiff> diffs = originalColumn.diff(editedColumn);
    // Copy existing data for re-use if applicable
    final Map<String, List<DTCellValue52>> originalColumnsData = new HashMap<>();
    for (BRLConditionVariableColumn variable : originalColumn.getChildColumns()) {
        int iColumnIndex = model.getExpandedColumns().indexOf(variable);
        final List<DTCellValue52> originalColumnData = new ArrayList<>();
        final String key = makeUpdateBRLConditionColumnKey(variable);
        for (List<DTCellValue52> row : model.getData()) {
            originalColumnData.add(row.get(iColumnIndex));
        }
        originalColumnsData.put(key, originalColumnData);
    }
    // Insert new columns setting data from that above, if applicable. Column visibility is handled here too.
    model.getConditions().add(model.getConditions().indexOf(originalColumn), editedColumn);
    for (BRLConditionVariableColumn childModelColumn : editedColumn.getChildColumns()) {
        final String key = makeUpdateBRLConditionColumnKey(childModelColumn);
        if (originalColumnsData.containsKey(key)) {
            final List<DTCellValue52> originalColumnData = originalColumnsData.get(key);
            synchroniseAppendColumn(childModelColumn, originalColumnData);
        } else {
            synchroniseAppendColumn(childModelColumn);
        }
    }
    // Delete columns for the original definition
    doDelete(originalColumn);
    // Signal patterns changed event to Decision Table Widget
    final BoundFactsChangedEvent pce = new BoundFactsChangedEvent(rm.getLHSBoundFacts());
    eventBus.fireEvent(pce);
    return diffs;
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VetoUpdatePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoUpdatePatternInUseException) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) BoundFactsChangedEvent(org.drools.workbench.screens.guided.dtable.client.widget.table.events.gwt.BoundFactsChangedEvent) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) ArrayList(java.util.ArrayList) List(java.util.List)

Example 45 with BRLConditionVariableColumn

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

the class BRLConditionColumnSynchronizer method append.

@Override
public void append(final ColumnMetaData metaData) throws VetoException {
    // Check operation is supported
    if (!handlesAppend(metaData)) {
        return;
    }
    final BRLConditionColumn column = (BRLConditionColumn) metaData.getColumn();
    model.getConditions().add(column);
    for (BRLConditionVariableColumn childModelColumn : column.getChildColumns()) {
        synchroniseAppendColumn(childModelColumn);
    }
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Aggregations

BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)69 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)53 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)28 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)24 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)23 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)23 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)23 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)23 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)18 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)15 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)15 IOException (java.io.IOException)11 InputStream (java.io.InputStream)11 ExcelParser (org.drools.decisiontable.parser.xls.ExcelParser)11 DataListener (org.drools.template.parser.DataListener)11 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)11 ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)11 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)11