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)));
}
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;
}
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;
}
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();
}
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);
}
Aggregations