Search in sources :

Example 21 with BRLActionVariableColumn

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

the class BRLActionColumnDefinitionBuilder method generateDefinition.

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

Example 22 with BRLActionVariableColumn

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

the class BRLActionColumnDefinitionBuilder method makeRowData.

private List<DTCellValue52> makeRowData(final ColumnUtilities columnUtilities, final BRLActionColumn brlColumn) {
    final List<DTCellValue52> row = new ArrayList<>();
    row.add(new DTCellValue52(1));
    row.add(new DTCellValue52("desc"));
    for (BRLActionVariableColumn 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) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)

Example 23 with BRLActionVariableColumn

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

the class BRLActionColumnSynchronizer 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();
    }
    final BRLActionColumn originalColumn = (BRLActionColumn) originalMetaData.getColumn();
    final BRLActionColumn editedColumn = (BRLActionColumn) editedMetaData.getColumn();
    final List<BaseColumnFieldDiff> diffs = originalColumn.diff(editedColumn);
    // Copy existing data for re-use if applicable
    final Map<String, List<DTCellValue52>> originalColumnsData = new HashMap<String, List<DTCellValue52>>();
    for (BRLActionVariableColumn variable : originalColumn.getChildColumns()) {
        int iColumnIndex = model.getExpandedColumns().indexOf(variable);
        final List<DTCellValue52> originalColumnData = new ArrayList<DTCellValue52>();
        final String key = makeUpdateBRLActionColumnKey(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.getActionCols().add(model.getActionCols().indexOf(originalColumn), editedColumn);
    for (BRLActionVariableColumn childModelColumn : editedColumn.getChildColumns()) {
        final String key = makeUpdateBRLActionColumnKey(childModelColumn);
        if (originalColumnsData.containsKey(key)) {
            final List<DTCellValue52> originalColumnData = originalColumnsData.get(key);
            synchroniseAppendColumn(childModelColumn, originalColumnData);
        } else {
            synchroniseAppendColumn(childModelColumn);
        }
    }
    // Delete columns for the original definition
    delete(originalMetaData);
    return diffs;
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) HashMap(java.util.HashMap) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)

Example 24 with BRLActionVariableColumn

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

the class BRLActionColumnSynchronizer method isBRLFragment.

private boolean isBRLFragment(final List<? extends MetaData> metaData) {
    if (!metaData.stream().allMatch((c) -> (c instanceof MoveColumnToMetaData))) {
        return false;
    }
    if (!metaData.stream().allMatch((c) -> ((MoveColumnToMetaData) c).getColumn() instanceof BRLActionVariableColumn)) {
        return false;
    }
    final MoveColumnToMetaData md = (MoveColumnToMetaData) metaData.get(0);
    final BRLActionVariableColumn srcModelColumn = (BRLActionVariableColumn) md.getColumn();
    final BRLActionColumn srcModelPattern = model.getBRLColumn(srcModelColumn);
    return srcModelPattern.getChildColumns().size() == metaData.size();
}
Also used : BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) HashMap(java.util.HashMap) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) ArrayList(java.util.ArrayList) ModelSynchronizer(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) List(java.util.List) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) Dependent(javax.enterprise.context.Dependent) Map(java.util.Map) Collections(java.util.Collections) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)

Example 25 with BRLActionVariableColumn

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

the class GuidedDecisionTablePresenterTest method addBrlInsertActionToModel.

private void addBrlInsertActionToModel(final GuidedDecisionTable52 model, final String factType, final String field) {
    final BRLActionColumn brlAction = new BRLActionColumn();
    final ActionInsertFact aif = new ActionInsertFact(factType);
    final ActionFieldValue afv = new ActionFieldValue(field, "$var", DataType.TYPE_STRING);
    afv.setNature(FieldNatureType.TYPE_VARIABLE);
    aif.addFieldValue(afv);
    brlAction.setDefinition(Collections.singletonList(aif));
    BRLActionVariableColumn variableColumn = new BRLActionVariableColumn("$var", DataType.TYPE_STRING, factType, field);
    brlAction.getChildColumns().add(variableColumn);
    model.getActionCols().add(brlAction);
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)

Aggregations

BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)63 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)51 Test (org.junit.Test)38 ArrayList (java.util.ArrayList)27 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)27 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)21 IAction (org.drools.workbench.models.datamodel.rule.IAction)19 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)18 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)18 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)17 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)16 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)15 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)14 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)11 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)11 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)11 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 ExcelParser (org.drools.decisiontable.parser.xls.ExcelParser)10 DataListener (org.drools.template.parser.DataListener)10