Search in sources :

Example 31 with BRLActionColumn

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;
}
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) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)

Example 32 with 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));
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) Test(org.junit.Test)

Example 33 with BRLActionColumn

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);
            }
        }
    }
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) HashMap(java.util.HashMap) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) ArrayList(java.util.ArrayList) GuidedDecisionTableSourceBuilderIndirect(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilderIndirect) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) GuidedDecisionTableRHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableRHSBuilder) IAction(org.drools.workbench.models.datamodel.rule.IAction) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) GuidedDecisionTableSourceBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableSourceBuilder) BRLVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn) GuidedDecisionTableLHSBuilder(org.drools.workbench.screens.dtablexls.backend.server.conversion.builders.GuidedDecisionTableLHSBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with BRLActionColumn

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;
}
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 35 with BRLActionColumn

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);
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)

Aggregations

BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)78 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)56 Test (org.junit.Test)53 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)33 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)26 ArrayList (java.util.ArrayList)24 IAction (org.drools.workbench.models.datamodel.rule.IAction)22 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)20 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)20 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)19 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)18 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)17 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)17 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)17 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)15 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)15 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)14 RuleNameColumn (org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn)14 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)13 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)12