Search in sources :

Example 21 with ActionFieldValue

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

the class RuleModelDRLPersistenceTest method testRHSChangeMultipleFieldsBlockModify.

@Test
public void testRHSChangeMultipleFieldsBlockModify() {
    String expected = "" + "rule \"my rule\" \n" + "  dialect \"mvel\"\n" + "  when\n" + "    $p : Person()\n" + "  then\n" + "    modify( $p ) {\n" + "      setName( \"Fred\" ),\n" + "      setAge( 55 )\n" + "    }\n" + "    $p.setGender( \"X\" );" + "end\n";
    final RuleModel m = new RuleModel();
    FactPattern factPattern = new FactPattern();
    factPattern.setFactType("Person");
    factPattern.setBoundName("$p");
    m.lhs = new IPattern[] { factPattern };
    ActionUpdateField auf1 = new ActionUpdateField();
    auf1.setVariable("$p");
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setField("name");
    afv1.setType(DataType.TYPE_STRING);
    afv1.setNature(FieldNatureType.TYPE_LITERAL);
    afv1.setValue("Fred");
    auf1.setFieldValues(new ActionFieldValue[] { afv1 });
    ActionSetField asf = new ActionSetField();
    asf.setVariable("$p");
    ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setField("gender");
    afv2.setType(DataType.TYPE_STRING);
    afv2.setNature(FieldNatureType.TYPE_LITERAL);
    afv2.setValue("X");
    asf.setFieldValues(new ActionFieldValue[] { afv2 });
    ActionUpdateField auf2 = new ActionUpdateField();
    auf2.setVariable("$p");
    ActionFieldValue afv3 = new ActionFieldValue();
    afv3.setField("age");
    afv3.setType(DataType.TYPE_NUMERIC_INTEGER);
    afv3.setNature(FieldNatureType.TYPE_LITERAL);
    afv3.setValue("55");
    auf2.setFieldValues(new ActionFieldValue[] { afv3 });
    m.rhs = new IAction[] { auf1, asf, auf2 };
    m.name = "my rule";
    checkMarshalling(expected, m);
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 22 with ActionFieldValue

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

the class RuleModelDRLPersistenceTest method testLiteralBigDecimalMvel.

@Test
public void testLiteralBigDecimalMvel() {
    RuleModel m = new RuleModel();
    m.name = "test literal bigdecimal";
    m.addAttribute(new RuleAttribute("dialect", "mvel"));
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFieldType(DataType.TYPE_NUMERIC_BIGDECIMAL);
    con.setFieldName("field1");
    con.setOperator("==");
    con.setValue("44");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    ActionInsertFact ai = new ActionInsertFact("Person");
    ai.addFieldValue(new ActionFieldValue("field1", "55", DataType.TYPE_NUMERIC_BIGDECIMAL));
    m.addRhsItem(ai);
    String expected = "rule \"test literal bigdecimal\" \n" + "\tdialect \"mvel\"\n when \n" + "     Person(field1 == 44B) \n" + " then \n" + "Person fact0 = new Person(); \n" + "fact0.setField1( 55B ); \n" + "insert( fact0 ); \n" + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 23 with ActionFieldValue

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

the class RuleModelDRLPersistenceTest method testRHSChangeMultipleFieldsModifyOneUpdateOther.

@Test
public void testRHSChangeMultipleFieldsModifyOneUpdateOther() {
    String expected = "" + "rule \"my rule\" \n" + "  dialect \"mvel\"\n" + "  when\n" + "    $p : Person()\n" + "  then\n" + "    modify( $p ) {\n" + "      setName( \"Fred\" )\n" + "    }\n" + "  $p.setAge( 55 );\n" + "end\n";
    final RuleModel m = new RuleModel();
    FactPattern factPattern = new FactPattern();
    factPattern.setFactType("Person");
    factPattern.setBoundName("$p");
    m.lhs = new IPattern[] { factPattern };
    ActionUpdateField auf = new ActionUpdateField();
    auf.setVariable("$p");
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setField("name");
    afv1.setType(DataType.TYPE_STRING);
    afv1.setNature(FieldNatureType.TYPE_LITERAL);
    afv1.setValue("Fred");
    auf.setFieldValues(new ActionFieldValue[] { afv1 });
    ActionSetField asf = new ActionSetField();
    asf.setVariable("$p");
    ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setField("age");
    afv2.setType(DataType.TYPE_NUMERIC_INTEGER);
    afv2.setNature(FieldNatureType.TYPE_LITERAL);
    afv2.setValue("55");
    asf.setFieldValues(new ActionFieldValue[] { afv2 });
    m.rhs = new IAction[] { auf, asf };
    m.name = "my rule";
    checkMarshalling(expected, m);
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 24 with ActionFieldValue

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

the class RuleModelDRLPersistenceTest method testLiteralBigIntegerJava.

@Test
public void testLiteralBigIntegerJava() {
    RuleModel m = new RuleModel();
    m.name = "test literal biginteger";
    m.addAttribute(new RuleAttribute("dialect", "java"));
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFieldType(DataType.TYPE_NUMERIC_BIGINTEGER);
    con.setFieldName("field1");
    con.setOperator("==");
    con.setValue("44");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    ActionInsertFact ai = new ActionInsertFact("Person");
    ai.addFieldValue(new ActionFieldValue("field1", "55", DataType.TYPE_NUMERIC_BIGINTEGER));
    m.addRhsItem(ai);
    String expected = "rule \"test literal biginteger\" \n" + "\tdialect \"java\"\n when \n" + "     Person(field1 == 44I ) \n" + " then \n" + "Person fact0 = new Person(); \n" + "fact0.setField1( new java.math.BigInteger( \"55\" ) ); \n" + "insert( fact0 ); \n" + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 25 with ActionFieldValue

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

the class RuleModelDRLPersistenceTest method testRHSChangeMultipleFieldsModifyBoth.

@Test
public void testRHSChangeMultipleFieldsModifyBoth() {
    String expected = "" + "rule \"my rule\" \n" + "  dialect \"mvel\"\n" + "  when\n" + "    $p : Person()\n" + "  then\n" + "    modify( $p ) {\n" + "      setName( \"Fred\" ),\n" + "      setAge( 55 )\n" + "    }\n" + "end\n";
    final RuleModel m = new RuleModel();
    FactPattern factPattern = new FactPattern();
    factPattern.setFactType("Person");
    factPattern.setBoundName("$p");
    m.lhs = new IPattern[] { factPattern };
    ActionUpdateField auf = new ActionUpdateField();
    auf.setVariable("$p");
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setField("name");
    afv1.setType(DataType.TYPE_STRING);
    afv1.setNature(FieldNatureType.TYPE_LITERAL);
    afv1.setValue("Fred");
    ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setField("age");
    afv2.setType(DataType.TYPE_NUMERIC_INTEGER);
    afv2.setNature(FieldNatureType.TYPE_LITERAL);
    afv2.setValue("55");
    auf.setFieldValues(new ActionFieldValue[] { afv1, afv2 });
    m.rhs = new IAction[] { auf };
    m.name = "my rule";
    checkMarshalling(expected, m);
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)136 Test (org.junit.Test)113 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)71 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)71 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)65 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)63 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)53 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)48 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)41 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)41 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)33 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)30 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)28 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)26 IAction (org.drools.workbench.models.datamodel.rule.IAction)25 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)24 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)23 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)21 ArrayList (java.util.ArrayList)19