Search in sources :

Example 16 with IAction

use of org.drools.workbench.models.datamodel.rule.IAction in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testRHSWithBRLColumn_ParseToRuleModel.

@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into a RuleModel
void testRHSWithBRLColumn_ParseToRuleModel() {
    GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    // All three rows are entered, some columns with optional data
    String[][] data = new String[][] { new String[] { "1", "desc", "Gargamel", "Pupa", "50" }, new String[] { "2", "desc", "Gargamel", "", "50" }, new String[] { "3", "desc", "Gargamel", "Pupa", "" } };
    // Simple (mandatory) columns
    dtable.setRowNumberCol(new RowNumberCol52());
    dtable.setDescriptionCol(new DescriptionCol52());
    // Simple Action
    ActionInsertFactCol52 a1 = new ActionInsertFactCol52();
    a1.setBoundName("$b");
    a1.setFactType("Baddie");
    a1.setFactField("name");
    a1.setType(DataType.TYPE_STRING);
    dtable.getActionCols().add(a1);
    // BRL Column
    BRLActionColumn brl1 = new BRLActionColumn();
    // BRL Column definition
    List<IAction> brl1Definition = new ArrayList<IAction>();
    ActionInsertFact brl1DefinitionAction1 = new ActionInsertFact("Smurf");
    ActionFieldValue brl1DefinitionAction1FieldValue1 = new ActionFieldValue("name", "$name", DataType.TYPE_STRING);
    brl1DefinitionAction1FieldValue1.setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brl1DefinitionAction1.addFieldValue(brl1DefinitionAction1FieldValue1);
    ActionFieldValue brl1DefinitionAction1FieldValue2 = new ActionFieldValue("age", "$age", DataType.TYPE_NUMERIC_INTEGER);
    brl1DefinitionAction1FieldValue2.setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brl1DefinitionAction1.addFieldValue(brl1DefinitionAction1FieldValue2);
    brl1Definition.add(brl1DefinitionAction1);
    brl1.setDefinition(brl1Definition);
    // Setup BRL column bindings
    BRLActionVariableColumn brl1Variable1 = new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Person", "name");
    brl1.getChildColumns().add(brl1Variable1);
    BRLActionVariableColumn brl1Variable2 = new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Person", "age");
    brl1.getChildColumns().add(brl1Variable2);
    dtable.getActionCols().add(brl1);
    // Now to test conversion
    RuleModel rm = new RuleModel();
    List<BaseColumn> allColumns = dtable.getExpandedColumns();
    List<ActionCol52> allActions = dtable.getActionCols();
    // Row 0
    List<DTCellValue52> dtRowData0 = DataUtilities.makeDataRowList(data[0]);
    TemplateDataProvider rowDataProvider0 = new GuidedDTTemplateDataProvider(allColumns, dtRowData0);
    p.doActions(allColumns, allActions, rowDataProvider0, dtRowData0, rm);
    assertEquals(2, rm.rhs.length);
    assertEquals("Baddie", ((ActionInsertFact) rm.rhs[0]).getFactType());
    assertEquals("Smurf", ((ActionInsertFact) rm.rhs[1]).getFactType());
    // examine the first action
    ActionInsertFact result0Action1 = (ActionInsertFact) rm.rhs[0];
    assertEquals(1, result0Action1.getFieldValues().length);
    ActionFieldValue result0Action1FieldValue1 = (ActionFieldValue) result0Action1.getFieldValues()[0];
    assertEquals(DataType.TYPE_STRING, result0Action1FieldValue1.getType());
    assertEquals("name", result0Action1FieldValue1.getField());
    assertEquals("Gargamel", result0Action1FieldValue1.getValue());
    // examine the second action
    ActionInsertFact result0Action2 = (ActionInsertFact) rm.rhs[1];
    assertEquals(2, result0Action2.getFieldValues().length);
    ActionFieldValue result0Action2FieldValue1 = (ActionFieldValue) result0Action2.getFieldValues()[0];
    assertEquals(DataType.TYPE_STRING, result0Action2FieldValue1.getType());
    assertEquals("name", result0Action2FieldValue1.getField());
    assertEquals("$name", result0Action2FieldValue1.getValue());
    ActionFieldValue result0Action2FieldValue2 = (ActionFieldValue) result0Action2.getFieldValues()[1];
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, result0Action2FieldValue2.getType());
    assertEquals("age", result0Action2FieldValue2.getField());
    assertEquals("$age", result0Action2FieldValue2.getValue());
    // Row 1
    List<DTCellValue52> dtRowData1 = DataUtilities.makeDataRowList(data[1]);
    TemplateDataProvider rowDataProvider1 = new GuidedDTTemplateDataProvider(allColumns, dtRowData1);
    p.doActions(allColumns, allActions, rowDataProvider1, dtRowData1, rm);
    assertEquals(2, rm.rhs.length);
    assertEquals("Baddie", ((ActionInsertFact) rm.rhs[0]).getFactType());
    assertEquals("Smurf", ((ActionInsertFact) rm.rhs[1]).getFactType());
    // examine the first action
    ActionInsertFact result1Action1 = (ActionInsertFact) rm.rhs[0];
    assertEquals(1, result1Action1.getFieldValues().length);
    ActionFieldValue result1Action1FieldValue1 = (ActionFieldValue) result1Action1.getFieldValues()[0];
    assertEquals(DataType.TYPE_STRING, result1Action1FieldValue1.getType());
    assertEquals("name", result1Action1FieldValue1.getField());
    assertEquals("Gargamel", result1Action1FieldValue1.getValue());
    // examine the second action
    ActionInsertFact result1Action2 = (ActionInsertFact) rm.rhs[1];
    assertEquals(2, result1Action2.getFieldValues().length);
    ActionFieldValue result1Action2FieldValue1 = (ActionFieldValue) result1Action2.getFieldValues()[0];
    assertEquals(DataType.TYPE_STRING, result1Action2FieldValue1.getType());
    assertEquals("name", result1Action2FieldValue1.getField());
    assertEquals("$name", result1Action2FieldValue1.getValue());
    ActionFieldValue result1Action2FieldValue2 = (ActionFieldValue) result1Action2.getFieldValues()[1];
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, result1Action2FieldValue2.getType());
    assertEquals("age", result1Action2FieldValue2.getField());
    assertEquals("$age", result1Action2FieldValue2.getValue());
    // Row 2
    List<DTCellValue52> dtRowData2 = DataUtilities.makeDataRowList(data[2]);
    TemplateDataProvider rowDataProvider2 = new GuidedDTTemplateDataProvider(allColumns, dtRowData2);
    p.doActions(allColumns, allActions, rowDataProvider2, dtRowData2, rm);
    assertEquals(2, rm.rhs.length);
    assertEquals("Baddie", ((ActionInsertFact) rm.rhs[0]).getFactType());
    assertEquals("Smurf", ((ActionInsertFact) rm.rhs[1]).getFactType());
    // examine the first action
    ActionInsertFact result2Action1 = (ActionInsertFact) rm.rhs[0];
    assertEquals(1, result2Action1.getFieldValues().length);
    ActionFieldValue result2Action1FieldValue1 = (ActionFieldValue) result2Action1.getFieldValues()[0];
    assertEquals(DataType.TYPE_STRING, result2Action1FieldValue1.getType());
    assertEquals("name", result2Action1FieldValue1.getField());
    assertEquals("Gargamel", result2Action1FieldValue1.getValue());
    // examine the second action
    ActionInsertFact result2Action2 = (ActionInsertFact) rm.rhs[1];
    assertEquals(2, result2Action2.getFieldValues().length);
    ActionFieldValue result2Action2FieldValue1 = (ActionFieldValue) result2Action2.getFieldValues()[0];
    assertEquals(DataType.TYPE_STRING, result2Action2FieldValue1.getType());
    assertEquals("name", result2Action2FieldValue1.getField());
    assertEquals("$name", result2Action2FieldValue1.getValue());
    ActionFieldValue result3Action2FieldValue2 = (ActionFieldValue) result2Action2.getFieldValues()[1];
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, result3Action2FieldValue2.getType());
    assertEquals("age", result3Action2FieldValue2.getField());
    assertEquals("$age", result3Action2FieldValue2.getValue());
}
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) IAction(org.drools.workbench.models.datamodel.rule.IAction) 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) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) 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 17 with IAction

use of org.drools.workbench.models.datamodel.rule.IAction in project drools by kiegroup.

the class BRLActionColumnTest method setup.

@Before
public void setup() {
    column1 = new BRLActionColumn();
    List<IAction> definition1 = Arrays.asList(new ActionRetractFact("var"));
    column1.setDefinition(definition1);
    List<BRLActionVariableColumn> childColumns1 = Arrays.asList(new BRLActionVariableColumn("var", "FieldType"));
    column1.setChildColumns(childColumns1);
    column1.setHeader("header");
    column1.setHideColumn(false);
    column2 = new BRLActionColumn();
    List<IAction> definition2 = Arrays.asList(new ActionRetractFact("var"));
    column2.setDefinition(definition2);
    List<BRLActionVariableColumn> childColumns2 = Arrays.asList(new BRLActionVariableColumn("var", "FieldType"));
    column2.setChildColumns(childColumns2);
    column2.setHeader("header");
    column2.setHideColumn(false);
}
Also used : ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) IAction(org.drools.workbench.models.datamodel.rule.IAction) Before(org.junit.Before)

Example 18 with IAction

use of org.drools.workbench.models.datamodel.rule.IAction in project drools by kiegroup.

the class BRLActionColumnTest method testDiffDefinitions.

@Test
public void testDiffDefinitions() {
    List<IAction> definition1 = Arrays.asList(new ActionRetractFact("var1"));
    column1.setDefinition(definition1);
    List<IAction> definition2 = Arrays.asList(new ActionRetractFact("var2"));
    column2.setDefinition(definition2);
    checkSingleDiff(FIELD_DEFINITION, definition1, definition2, column1, column2);
}
Also used : ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) IAction(org.drools.workbench.models.datamodel.rule.IAction) Test(org.junit.Test)

Example 19 with IAction

use of org.drools.workbench.models.datamodel.rule.IAction in project drools-wb by kiegroup.

the class ExtendedGuidedDecisionTableBuilder method createBRLActionColumn.

public static BRLActionColumn createBRLActionColumn() {
    final BRLActionColumn brlActionColumn = new BRLActionColumn();
    final ArrayList<IAction> definition = new ArrayList<IAction>();
    definition.add(mock(IAction.class));
    brlActionColumn.setDefinition(definition);
    return brlActionColumn;
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) IAction(org.drools.workbench.models.datamodel.rule.IAction) ArrayList(java.util.ArrayList)

Example 20 with IAction

use of org.drools.workbench.models.datamodel.rule.IAction in project drools-wb by kiegroup.

the class RuleModelCloneVisitor method visitRuleModel.

public RuleModel visitRuleModel(RuleModel model) {
    RuleModel clone = new RuleModel();
    clone.modelVersion = model.modelVersion;
    clone.name = model.name;
    clone.parentName = model.parentName;
    clone.setNegated(model.isNegated());
    if (model.attributes != null) {
        clone.attributes = new RuleAttribute[model.attributes.length];
        for (int i = 0; i < model.attributes.length; i++) {
            RuleAttribute attr = model.attributes[i];
            clone.attributes[i] = (RuleAttribute) visit(attr);
        }
    }
    if (model.metadataList != null) {
        clone.metadataList = new RuleMetadata[model.metadataList.length];
        for (int i = 0; i < model.metadataList.length; i++) {
            RuleMetadata md = model.metadataList[i];
            clone.metadataList[i] = (RuleMetadata) visit(md);
        }
    }
    if (model.lhs != null) {
        clone.lhs = new IPattern[model.lhs.length];
        for (int i = 0; i < model.lhs.length; i++) {
            IPattern pattern = model.lhs[i];
            clone.lhs[i] = (IPattern) visit(pattern);
        }
    }
    if (model.rhs != null) {
        clone.rhs = new IAction[model.rhs.length];
        for (int i = 0; i < model.rhs.length; i++) {
            IAction action = model.rhs[i];
            clone.rhs[i] = (IAction) visit(action);
        }
    }
    return clone;
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) IAction(org.drools.workbench.models.datamodel.rule.IAction) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint)

Aggregations

IAction (org.drools.workbench.models.datamodel.rule.IAction)63 Test (org.junit.Test)44 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)35 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)32 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)31 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)30 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)29 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)25 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)21 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)20 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)20 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)20 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)20 ArrayList (java.util.ArrayList)19 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)19 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)17 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)17 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)17 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)15 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)15