Search in sources :

Example 56 with ActionUpdateField

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

the class RuleModelDRLPersistenceUnmarshallingTest method testFunctionInRHS.

@Test
public void testFunctionInRHS() throws Exception {
    String drl = "" + "rule \"Borked\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    application : Application( )\n" + "  then\n" + "    application.setApr( application.getApr() + 5 );\n" + "    update( application )" + "end";
    RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertTrue(m.rhs[0] instanceof ActionUpdateField);
    ActionUpdateField field = (ActionUpdateField) m.rhs[0];
    assertNotNull(field.getFieldValues()[0]);
    ActionFieldValue value = field.getFieldValues()[0];
    assertEquals("apr", value.getField());
    assertEquals("application.getApr() + 5", value.getValue());
    assertEquals(FieldNatureType.TYPE_FORMULA, value.getNature());
    assertEquals(DataType.TYPE_NUMERIC, value.getType());
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 57 with ActionUpdateField

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

the class BRLRuleModelTest method testRHSNonEmptyStringValues.

@Test
public void testRHSNonEmptyStringValues() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    dt.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
    dt.setTableName("extended-entry");
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Smurf");
    BRLActionColumn brlAction = new BRLActionColumn();
    ActionUpdateField auf1 = new ActionUpdateField("p1");
    auf1.addFieldValue(new ActionFieldValue("name", "$name", DataType.TYPE_STRING));
    auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    ActionUpdateField auf2 = new ActionUpdateField("p1");
    auf2.addFieldValue(new ActionFieldValue("age", "$age", DataType.TYPE_NUMERIC_INTEGER));
    auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction.getDefinition().add(auf1);
    brlAction.getDefinition().add(auf2);
    brlAction.getChildColumns().add(new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Smurf", "name"));
    brlAction.getChildColumns().add(new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Smurf", "age"));
    dt.getActionCols().add(brlAction);
    // Test 1
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc-row1", null, null } }));
    String drl1 = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected1 = "//from row number: 1\n" + "//desc-row1\n" + "rule \"Row 1 extended-entry\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "  then\n" + "end";
    assertEqualsIgnoreWhitespace(expected1, drl1);
    // Test 2
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 2l, "desc-row2", "   ", 35l } }));
    String drl2 = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected2 = "//from row number: 1\n" + "//desc-row2\n" + "rule \"Row 2 extended-entry\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "  then\n" + "    modify( p1 ) {\n" + "      setAge( 35 )\n" + "    }\n" + "end";
    assertEqualsIgnoreWhitespace(expected2, drl2);
    // Test 3
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 3l, "desc-row3", "", null } }));
    String drl3 = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected3 = "//from row number: 1\n" + "//desc-row3\n" + "rule \"Row 3 extended-entry\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "  then\n" + "end";
    assertEqualsIgnoreWhitespace(expected3, drl3);
    // Test 4
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 4l, "desc-row4", "", 35l } }));
    String drl4 = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected4 = "//from row number: 1\n" + "//desc-row4\n" + "rule \"Row 4 extended-entry\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "  then\n" + "    modify( p1 ) {\n" + "      setAge( 35 )\n" + "    }\n" + "end";
    assertEqualsIgnoreWhitespace(expected4, drl4);
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) Test(org.junit.Test)

Example 58 with ActionUpdateField

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

the class GuidedDecisionTableFactory method makeTableWithBRLFragmentActionCol.

public static GuidedDecisionTable52 makeTableWithBRLFragmentActionCol(final String packageName, final Collection<Import> imports, final String tableName) {
    final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    dt.setPackageName(packageName);
    dt.getImports().getImports().addAll(imports);
    dt.setTableName(tableName);
    final BRLActionColumn brl = new BRLActionColumn();
    final ActionInsertFact ifc1 = new ActionInsertFact();
    ifc1.setFactType("Applicant");
    ifc1.setBoundName("$a");
    final ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("age");
    afv1.setValue("f1");
    ifc1.addFieldValue(afv1);
    final ActionInsertFact ifc2 = new ActionInsertFact();
    ifc2.setFactType("Mortgage");
    ifc2.setBoundName("$m");
    final ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv2.setField("amount");
    afv2.setValue("f2");
    ifc2.addFieldValue(afv2);
    final ActionSetField asf = new ActionSetField();
    asf.setVariable("$a");
    asf.addFieldValue(new ActionFieldValue("age", "33", DataType.TYPE_NUMERIC_INTEGER));
    final ActionUpdateField auf = new ActionUpdateField();
    asf.setVariable("$m");
    asf.addFieldValue(new ActionFieldValue("amount", "10000", DataType.TYPE_NUMERIC_INTEGER));
    brl.getDefinition().add(ifc1);
    brl.getDefinition().add(ifc2);
    brl.getChildColumns().add(new BRLActionVariableColumn("f1", DataType.TYPE_NUMERIC_INTEGER));
    brl.getChildColumns().add(new BRLActionVariableColumn("f2", DataType.TYPE_NUMERIC_INTEGER));
    brl.getDefinition().add(asf);
    brl.getDefinition().add(auf);
    dt.getConditions().add(brl);
    dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "33", "" } }));
    return dt;
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) 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)

Aggregations

ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)58 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)53 Test (org.junit.Test)47 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)37 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)37 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)36 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)27 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)22 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)22 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)16 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)16 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)11 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)11 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)10 IAction (org.drools.workbench.models.datamodel.rule.IAction)8 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)8 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)8 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)8 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)7 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)6