Search in sources :

Example 41 with ActionCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionCol52 in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testRHSActionWorkItemSetFields2.

@Test
public // Test only Actions set to "true" are correctly converted to RuleModel
void testRHSActionWorkItemSetFields2() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "true", "true", "false" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    List<ActionCol52> cols = new ArrayList<ActionCol52>();
    ActionWorkItemCol52 awi = new ActionWorkItemCol52();
    PortableWorkDefinition pwd = new PortableWorkDefinition();
    pwd.setName("WorkItem");
    awi.setWorkItemDefinition(pwd);
    PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
    p1.setName("BooleanResult");
    pwd.addResult(p1);
    PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
    p2.setName("FloatResult");
    pwd.addResult(p2);
    cols.add(awi);
    ActionWorkItemSetFieldCol52 asf1 = new ActionWorkItemSetFieldCol52();
    asf1.setBoundName("$r");
    asf1.setFactField("ResultBooleanField");
    asf1.setType(DataType.TYPE_BOOLEAN);
    asf1.setWorkItemName("WorkItem");
    asf1.setWorkItemResultParameterName("BooleanResult");
    asf1.setParameterClassName(Boolean.class.getName());
    cols.add(asf1);
    ActionWorkItemSetFieldCol52 asf2 = new ActionWorkItemSetFieldCol52();
    asf2.setBoundName("$r");
    asf2.setFactField("ResultFloatField");
    asf2.setType(DataType.TYPE_NUMERIC_FLOAT);
    asf2.setWorkItemName("WorkItem");
    asf2.setWorkItemResultParameterName("FloatResult");
    asf2.setParameterClassName(Float.class.getName());
    cols.add(asf2);
    RuleModel rm = new RuleModel();
    allColumns.addAll(cols);
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
    assertEquals(2, rm.rhs.length);
    // Examine RuleModel actions
    ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0];
    assertNotNull(aw);
    ActionSetField asf = (ActionSetField) rm.rhs[1];
    assertNotNull(asf);
    // Check ActionExecuteWorkItem
    PortableWorkDefinition mpwd = aw.getWorkDefinition();
    assertNotNull(mpwd);
    assertEquals(2, mpwd.getResults().size());
    PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getResult("BooleanResult");
    assertNotNull(mp1);
    PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getResult("FloatResult");
    assertNotNull(mp2);
    // Check ActionSetField
    assertEquals(asf.getVariable(), "$r");
    assertEquals(1, asf.getFieldValues().length);
    ActionFieldValue fv1 = asf.getFieldValues()[0];
    assertNotNull(fv1);
    assertTrue(fv1 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv1 = (ActionWorkItemFieldValue) fv1;
    assertEquals("ResultBooleanField", wifv1.getField());
    assertEquals(DataType.TYPE_BOOLEAN, wifv1.getType());
    assertEquals("WorkItem", wifv1.getWorkItemName());
    assertEquals("BooleanResult", wifv1.getWorkItemParameterName());
    assertEquals(Boolean.class.getName(), wifv1.getWorkItemParameterClassName());
}
Also used : ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) ArrayList(java.util.ArrayList) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) ActionExecuteWorkItem(org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) ActionWorkItemSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemSetFieldCol52) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 42 with ActionCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionCol52 in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testRHS.

@Test
public void testRHS() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "a", "a condition", "actionsetfield1", "actionupdatefield2", "retract", "actioninsertfact1", "actioninsertfact2" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    allColumns.add(new MetadataCol52());
    allColumns.add(new ConditionCol52());
    List<ActionCol52> cols = new ArrayList<ActionCol52>();
    ActionSetFieldCol52 asf1 = new ActionSetFieldCol52();
    asf1.setBoundName("a");
    asf1.setFactField("field1");
    asf1.setType(DataType.TYPE_STRING);
    cols.add(asf1);
    ActionSetFieldCol52 asf2 = new ActionSetFieldCol52();
    asf2.setBoundName("a");
    asf2.setFactField("field2");
    asf2.setUpdate(true);
    asf2.setType(DataType.TYPE_NUMERIC_INTEGER);
    cols.add(asf2);
    ActionRetractFactCol52 ret = new ActionRetractFactCol52();
    cols.add(ret);
    ActionInsertFactCol52 ins1 = new ActionInsertFactCol52();
    ins1.setBoundName("ins");
    ins1.setFactType("Cheese");
    ins1.setFactField("price");
    ins1.setType(DataType.TYPE_NUMERIC_INTEGER);
    cols.add(ins1);
    ActionInsertFactCol52 ins2 = new ActionInsertFactCol52();
    ins2.setBoundName("ins");
    ins2.setFactType("Cheese");
    ins2.setFactField("type");
    ins2.setType(DataType.TYPE_NUMERIC_INTEGER);
    cols.add(ins2);
    RuleModel rm = new RuleModel();
    allColumns.addAll(cols);
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
    assertEquals(4, rm.rhs.length);
    // examine the set field action that is produced
    ActionSetField a1 = (ActionSetField) rm.rhs[0];
    assertEquals("a", a1.getVariable());
    assertEquals(1, a1.getFieldValues().length);
    assertEquals("field1", a1.getFieldValues()[0].getField());
    assertEquals("actionsetfield1", a1.getFieldValues()[0].getValue());
    assertEquals(DataType.TYPE_STRING, a1.getFieldValues()[0].getType());
    ActionSetField a2 = (ActionSetField) rm.rhs[1];
    assertEquals("a", a2.getVariable());
    assertEquals(1, a2.getFieldValues().length);
    assertEquals("field2", a2.getFieldValues()[0].getField());
    assertEquals("actionupdatefield2", a2.getFieldValues()[0].getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, a2.getFieldValues()[0].getType());
    // examine the retract
    ActionRetractFact a3 = (ActionRetractFact) rm.rhs[2];
    assertEquals("retract", a3.getVariableName());
    // examine the insert
    ActionInsertFact a4 = (ActionInsertFact) rm.rhs[3];
    assertEquals("Cheese", a4.getFactType());
    assertEquals(2, a4.getFieldValues().length);
    assertEquals("price", a4.getFieldValues()[0].getField());
    assertEquals("actioninsertfact1", a4.getFieldValues()[0].getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, a4.getFieldValues()[0].getType());
    assertEquals("type", a4.getFieldValues()[1].getField());
    assertEquals("actioninsertfact2", a4.getFieldValues()[1].getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, a4.getFieldValues()[1].getType());
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) LimitedEntryActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52) ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ArrayList(java.util.ArrayList) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) LimitedEntryActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) Test(org.junit.Test)

Example 43 with ActionCol52

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

the class ColumnsPagePresenterTest method testOnRefreshActionsPanelEvent.

@Test
public void testOnRefreshActionsPanelEvent() {
    final RefreshActionsPanelEvent event = mock(RefreshActionsPanelEvent.class);
    final GuidedDecisionTableView.Presenter eventPresenter = mock(GuidedDecisionTableView.Presenter.class);
    final List<ActionCol52> columns = new ArrayList<>();
    doReturn(eventPresenter).when(event).getPresenter();
    doReturn(columns).when(event).getColumns();
    doNothing().when(presenter).refreshActionsWidget(any());
    doNothing().when(presenter).refreshColumnsNoteInfo(any());
    presenter.onRefreshActionsPanelEvent(event);
    verify(presenter).refreshActionsWidget(columns);
    verify(presenter).refreshColumnsNoteInfo(eventPresenter);
}
Also used : ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ArrayList(java.util.ArrayList) RefreshActionsPanelEvent(org.drools.workbench.screens.guided.dtable.client.widget.table.events.cdi.RefreshActionsPanelEvent) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) Test(org.junit.Test)

Example 44 with ActionCol52

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

the class DefaultGuidedDecisionTableLinkManager method link.

@Override
public void link(final GuidedDecisionTable52 model, final GuidedDecisionTable52 otherModel, final LinkFoundCallback callback) {
    if (model == null) {
        return;
    }
    if (otherModel == null) {
        return;
    }
    if (callback == null) {
        return;
    }
    final BRLRuleModel helper = new BRLRuleModel(model);
    // Re-create links to other Decision Tables
    for (CompositeColumn<? extends BaseColumn> otherDecisionTableConditions : otherModel.getConditions()) {
        if (otherDecisionTableConditions instanceof Pattern52) {
            final Pattern52 otherDecisionTablePattern = (Pattern52) otherDecisionTableConditions;
            for (ConditionCol52 otherDecisionTableCondition : otherDecisionTablePattern.getChildColumns()) {
                final String factType = otherDecisionTablePattern.getFactType();
                final String fieldName = otherDecisionTableCondition.getFactField();
                final ActionCol52 linkedActionColumn = getLinkedActionColumn(factType, fieldName, model, helper);
                if (linkedActionColumn != null) {
                    final int sourceColumnIndex = model.getExpandedColumns().indexOf(linkedActionColumn);
                    final int targetColumnIndex = otherModel.getExpandedColumns().indexOf(otherDecisionTableCondition);
                    callback.link(sourceColumnIndex, targetColumnIndex);
                }
            }
        } else if (otherDecisionTableConditions instanceof BRLConditionColumn) {
            final BRLConditionColumn fragment = (BRLConditionColumn) otherDecisionTableConditions;
            for (BRLConditionVariableColumn var : fragment.getChildColumns()) {
                final String factType = var.getFactType();
                final String fieldName = var.getFactField();
                final ActionCol52 linkedActionColumn = getLinkedActionColumn(factType, fieldName, model, helper);
                if (linkedActionColumn != null) {
                    final int sourceColumnIndex = model.getExpandedColumns().indexOf(linkedActionColumn);
                    final int targetColumnIndex = otherModel.getExpandedColumns().indexOf(var);
                    callback.link(sourceColumnIndex, targetColumnIndex);
                }
            }
        }
    }
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)

Example 45 with ActionCol52

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

the class ColumnsPagePresenterTest method testRefreshActionsWidgetWhenActionColumnsIsNotEmpty.

@Test
public void testRefreshActionsWidgetWhenActionColumnsIsNotEmpty() {
    final ColumnManagementView columnManagementView = mock(ColumnManagementView.class);
    final GuidedDecisionTableAccordionItem item = mock(GuidedDecisionTableAccordionItem.class);
    final Label blankSlate = mock(Label.class);
    final ActionCol52 actionCol52 = mock(ActionCol52.class);
    final List<ActionCol52> actionColumns1 = new ArrayList<ActionCol52>() {

        {
            add(actionCol52);
        }
    };
    final Map<String, List<BaseColumn>> actionColumns2 = new HashMap<String, List<BaseColumn>>() {

        {
            put("title", new ArrayList<>());
        }
    };
    doReturn(verticalPanel).when(presenter).getActionsWidget();
    doReturn(columnManagementView).when(presenter).getActionsPanel();
    doReturn(blankSlate).when(presenter).blankSlate();
    doReturn(item).when(accordion).getItem(ACTION);
    doReturn(actionColumns2).when(presenter).groupByTitle(actionColumns1);
    presenter.refreshActionsWidget(actionColumns1);
    verify(item, never()).setOpen(false);
    verify(verticalPanel, never()).add(blankSlate);
    verify(verticalPanel).add(columnManagementView);
    verify(columnManagementView).renderColumns(actionColumns2);
}
Also used : ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) HashMap(com.google.gwt.dev.util.collect.HashMap) ColumnManagementView(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.control.ColumnManagementView) Label(com.google.gwt.user.client.ui.Label) ArrayList(java.util.ArrayList) GuidedDecisionTableAccordionItem(org.drools.workbench.screens.guided.dtable.client.editor.page.accordion.GuidedDecisionTableAccordionItem) List(java.util.List) ArrayList(java.util.ArrayList) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)60 Test (org.junit.Test)31 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)27 ArrayList (java.util.ArrayList)17 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)16 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)13 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)13 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)12 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)12 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)12 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)11 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)11 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)10 ActionWorkItemCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52)9 GuidedDTTemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider)8 TemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider)8 List (java.util.List)6 ActionExecuteWorkItem (org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem)6 PortableBooleanParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition)6 PortableFloatParameterDefinition (org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition)6