Search in sources :

Example 71 with ActionInsertFactCol52

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

the class ActionInsertFactFieldsPageViewImpl method makeNewActionColumn.

private ActionInsertFactCol52 makeNewActionColumn(final AvailableField f) {
    final GuidedDecisionTable52.TableFormat format = presenter.getTableFormat();
    if (format == GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY) {
        final ActionInsertFactCol52 a = new ActionInsertFactCol52();
        a.setBoundName(chosenPatternsSelection.getBoundName());
        a.setFactType(chosenPatternsSelection.getFactType());
        a.setFactField(f.getName());
        a.setType(f.getType());
        return a;
    } else {
        final LimitedEntryActionInsertFactCol52 a = new LimitedEntryActionInsertFactCol52();
        a.setBoundName(chosenPatternsSelection.getBoundName());
        a.setFactType(chosenPatternsSelection.getFactType());
        a.setFactField(f.getName());
        a.setType(f.getType());
        return a;
    }
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) LimitedEntryActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52) LimitedEntryActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)

Example 72 with ActionInsertFactCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52 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 73 with ActionInsertFactCol52

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

the class GuidedDecisionTablePresenterTest method updateActionColumn.

@Test
public void updateActionColumn() throws VetoException {
    final ActionInsertFactCol52 column = new ActionInsertFactCol52();
    column.setFactType("FactType");
    column.setFactField("field");
    column.setHeader("header");
    when(oracle.getFieldType(eq("FactType"), eq("field"))).thenReturn(DataType.TYPE_STRING);
    dtPresenter.appendColumn(column);
    reset(modellerPresenter);
    final ActionInsertFactCol52 update = new ActionInsertFactCol52();
    update.setFactType("NewType");
    update.setFactField("newField");
    update.setHeader("newHeader");
    when(oracle.getFieldType(eq("NewType"), eq("newField"))).thenReturn(DataType.TYPE_STRING);
    dtPresenter.updateColumn(column, update);
    verify(synchronizer, times(1)).updateColumn(eq(column), eq(update));
    verify(modellerPresenter, times(1)).updateLinks();
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) Test(org.junit.Test)

Example 74 with ActionInsertFactCol52

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

the class ColumnManagementViewTest method testRenderColumnActionsNotEditable.

@Test
public void testRenderColumnActionsNotEditable() throws Exception {
    final BRLActionColumn brlActionColumn = mock(BRLActionColumn.class);
    final ActionInsertFactCol52 actionInsertFactColumn = mock(ActionInsertFactCol52.class);
    final ActionRetractFactCol52 retractFactColumn = mock(ActionRetractFactCol52.class);
    final Map<String, List<BaseColumn>> columnGroups = new HashMap<String, List<BaseColumn>>() {

        {
            put(GuidedDecisionTableConstants.INSTANCE.BrlConditions(), Arrays.asList(brlActionColumn, actionInsertFactColumn, retractFactColumn));
        }
    };
    final ColumnLabelWidget columnLabel = mockColumnLabelWidget();
    doReturn(columnLabel).when(view).newColumnLabelWidget(anyString());
    view.renderColumns(columnGroups);
    verify(view).renderColumn(brlActionColumn);
    verify(view).renderColumn(actionInsertFactColumn);
    verify(view).renderColumn(retractFactColumn);
    // There are three action columns
    verify(horizontalPanel, times(3)).add(columnLabel);
    verify(view, times(3)).editAnchor(any(ClickHandler.class));
    verify(view, never()).deleteAnchor(eq("one"), any(Command.class));
    verify(view, never()).deleteAnchor(eq("two"), any(Command.class));
    verify(view, never()).deleteAnchor(eq("three"), any(Command.class));
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) HashMap(java.util.HashMap) Command(com.google.gwt.user.client.Command) List(java.util.List) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 75 with ActionInsertFactCol52

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

the class ColumnManagementViewTest method testRenderColumnActionsEditable.

@Test
public void testRenderColumnActionsEditable() throws Exception {
    final BRLActionColumn brlActionColumn = mock(BRLActionColumn.class);
    final ActionInsertFactCol52 actionInsertFactColumn = mock(ActionInsertFactCol52.class);
    final ActionRetractFactCol52 retractFactColumn = mock(ActionRetractFactCol52.class);
    final Map<String, List<BaseColumn>> columnGroups = new HashMap<String, List<BaseColumn>>() {

        {
            put(GuidedDecisionTableConstants.INSTANCE.BrlConditions(), Arrays.asList(brlActionColumn, actionInsertFactColumn, retractFactColumn));
        }
    };
    final ColumnLabelWidget columnLabel = mockColumnLabelWidget();
    doReturn(columnLabel).when(view).newColumnLabelWidget(anyString());
    doReturn(true).when(modellerPresenter).isActiveDecisionTableEditable();
    doReturn("one").when(brlActionColumn).getHeader();
    doReturn("two").when(actionInsertFactColumn).getHeader();
    doReturn("three").when(retractFactColumn).getHeader();
    view.renderColumns(columnGroups);
    verify(view).renderColumn(brlActionColumn);
    verify(view).renderColumn(actionInsertFactColumn);
    verify(view).renderColumn(retractFactColumn);
    // There are three action columns
    verify(horizontalPanel, times(3)).add(columnLabel);
    verify(view, times(3)).editAnchor(clickHandlerCaptor.capture());
    verify(view).deleteAnchor(eq("one"), deleteCommandCaptor.capture());
    verify(view).deleteAnchor(eq("two"), deleteCommandCaptor.capture());
    verify(view).deleteAnchor(eq("three"), deleteCommandCaptor.capture());
    clickHandlerCaptor.getAllValues().get(0).onClick(mock(ClickEvent.class));
    verify(decisionTablePresenter).editAction(eq(brlActionColumn));
    clickHandlerCaptor.getAllValues().get(1).onClick(mock(ClickEvent.class));
    verify(decisionTablePresenter).editAction(eq(actionInsertFactColumn));
    clickHandlerCaptor.getAllValues().get(2).onClick(mock(ClickEvent.class));
    verify(decisionTablePresenter).editAction(eq(retractFactColumn));
    deleteCommandCaptor.getAllValues().get(0).execute();
    verify(decisionTablePresenter).deleteColumn(brlActionColumn);
    deleteCommandCaptor.getAllValues().get(1).execute();
    verify(decisionTablePresenter).deleteColumn(actionInsertFactColumn);
    deleteCommandCaptor.getAllValues().get(2).execute();
    verify(decisionTablePresenter).deleteColumn(retractFactColumn);
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) List(java.util.List) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)94 Test (org.junit.Test)64 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)35 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)31 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)31 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)30 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)24 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)19 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)15 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)13 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)13 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)12 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)12 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)12 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)12 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)12 Path (org.uberfire.backend.vfs.Path)12 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)11 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)11 ActionRetractFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52)10