use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn in project drools-wb by kiegroup.
the class BRLActionColumnPluginChildColumnUpdateTest method getBrlActionColumnWithNoTemplateValues.
private BRLActionColumn getBrlActionColumnWithNoTemplateValues() {
final BRLActionColumn brlActionColumn = new BRLActionColumn();
final ActionInsertFact actionInsertFact = new ActionInsertFact("Person");
actionInsertFact.setBoundName("$a");
final ActionFieldValue afv1 = new ActionFieldValue("name", "Toni", DataType.TYPE_STRING);
afv1.setNature(FieldNatureType.TYPE_LITERAL);
actionInsertFact.addFieldValue(afv1);
final ActionFieldValue afv2 = new ActionFieldValue("age", "12", DataType.TYPE_STRING);
afv2.setNature(FieldNatureType.TYPE_LITERAL);
actionInsertFact.addFieldValue(afv2);
brlActionColumn.getDefinition().add(actionInsertFact);
final BRLActionVariableColumn variableColumn = new BRLActionVariableColumn("", BRLActionVariableColumn.FIELD_VAR_NAME);
variableColumn.setDefaultValue(new DTCellValue52("test"));
brlActionColumn.getChildColumns().add(variableColumn);
return brlActionColumn;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn in project drools-wb by kiegroup.
the class DecisionTableColumnViewUtilsTest method testColumnManagementGroupTitleBrlAction.
@Test
public void testColumnManagementGroupTitleBrlAction() throws Exception {
final BRLActionColumn column = mock(BRLActionColumn.class);
assertEquals(GuidedDecisionTableConstants.INSTANCE.BrlActions(), DecisionTableColumnViewUtils.getColumnManagementGroupTitle(column));
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn in project drools-wb by kiegroup.
the class GuidedDecisionTablePopulater method addIndirectSourceBuildersColumns.
private void addIndirectSourceBuildersColumns() {
// Extract BRLVariableColumn and SourceBuilders for respective sections of the rule
final List<BRLVariableColumn> variableColumns = new ArrayList<>();
final List<GuidedDecisionTableLHSBuilder> lhsBuilders = new ArrayList<>();
final List<GuidedDecisionTableRHSBuilder> rhsBuilders = new ArrayList<>();
for (GuidedDecisionTableSourceBuilder sb : sourceBuilders) {
if (sb instanceof GuidedDecisionTableSourceBuilderIndirect) {
for (BRLVariableColumn variableColumn : ((GuidedDecisionTableSourceBuilderIndirect) sb).getVariableColumns()) {
variableColumns.add(variableColumn);
}
}
if (sb instanceof GuidedDecisionTableLHSBuilder) {
lhsBuilders.add((GuidedDecisionTableLHSBuilder) sb);
}
if (sb instanceof GuidedDecisionTableRHSBuilder) {
rhsBuilders.add((GuidedDecisionTableRHSBuilder) sb);
}
}
// -- PROCESS LHS PATTERNS
// For each GuidedDecisionTableLHSBuilder gather IPatterns generated
// from each accumulative iteration and convert to RuleModel
int previousPatternCount = 0;
for (int i = 0; i < lhsBuilders.size(); i++) {
// Construct DRL for this and previous builders
final String rule = assembleRuleDRL(i, lhsBuilders, Collections.emptyList());
final RuleModel rm = RuleModelDRLPersistenceImpl.getInstance().unmarshal(rule, Collections.emptyList(), dmo);
if (Objects.nonNull(rm.lhs)) {
final Map<IPattern, Map<InterpolationVariable, Integer>> patternTemplateKeys = new HashMap<>();
final BRLConditionColumn column = new BRLConditionColumn();
dtable.getConditions().add(column);
// Extract Template Keys for Patterns in iteration
boolean allPatternsHaveTemplateKeys = true;
for (int iPattern = previousPatternCount; iPattern < rm.lhs.length; iPattern++) {
final IPattern pattern = rm.lhs[iPattern];
final Map<InterpolationVariable, Integer> templateKeys = new HashMap<>();
final RuleModelVisitor rmv = new RuleModelVisitor(templateKeys);
rmv.visit(pattern);
patternTemplateKeys.put(pattern, templateKeys);
if (templateKeys.isEmpty()) {
allPatternsHaveTemplateKeys = false;
}
}
// If ALL patterns in the iteration have Template keys we can use IPattern otherwise fallback to FreeFormLine
if (allPatternsHaveTemplateKeys) {
for (int iPattern = previousPatternCount; iPattern < rm.lhs.length; iPattern++) {
final IPattern pattern = rm.lhs[iPattern];
column.getDefinition().add(pattern);
}
} else {
final FreeFormLine ffl = new FreeFormLine();
ffl.setText(lhsBuilders.get(i).getResult());
column.setDefinition(Collections.singletonList(ffl));
}
// Copy variables to column
for (int iPattern = previousPatternCount; iPattern < rm.lhs.length; iPattern++) {
final IPattern pattern = rm.lhs[iPattern];
final Map<InterpolationVariable, Integer> templateKeys = patternTemplateKeys.get(pattern);
if (Objects.nonNull(templateKeys)) {
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 (Objects.equals(iv.getVarName(), variableColumn.getVarName())) {
final BRLConditionVariableColumn source = (BRLConditionVariableColumn) variableColumn;
final BRLConditionVariableColumn target = makeBRLConditionVariableColumn(source, iv);
column.getChildColumns().add(target);
ivsIts.remove();
}
}
}
}
}
// Give the column a header
if (column.getChildColumns().isEmpty()) {
setZeroParameterConditionColumnHeader(column, variableColumns);
} else {
setCompositeColumnHeader(column);
}
}
previousPatternCount = rm.lhs.length;
}
// -- PROCESS RHS ACTIONS
final String rule = assembleRuleDRL(lhsBuilders.size() - 1, lhsBuilders, rhsBuilders);
final RuleModel rm = RuleModelDRLPersistenceImpl.getInstance().unmarshal(rule, Collections.emptyList(), dmo, true);
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);
}
}
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn 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<>();
for (BRLActionVariableColumn variable : originalColumn.getChildColumns()) {
int iColumnIndex = model.getExpandedColumns().indexOf(variable);
final List<DTCellValue52> originalColumnData = new ArrayList<>();
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.BRLActionColumn in project drools-wb by kiegroup.
the class BRLActionColumnSynchronizer method delete.
@Override
public void delete(final ColumnMetaData metaData) throws VetoException {
// Check operation is supported
if (!handlesDelete(metaData)) {
return;
}
final BRLActionColumn column = (BRLActionColumn) metaData.getColumn();
if (column.getChildColumns().size() > 0) {
// Need to reverse the iteration and remove from the last to first or the indexes are wrong.
for (int iColumnIndex = column.getChildColumns().size() - 1; iColumnIndex >= 0; iColumnIndex--) {
synchroniseDeleteColumn(model.getExpandedColumns().indexOf(column.getChildColumns().get(iColumnIndex)));
}
}
model.getActionCols().remove(column);
}
Aggregations