Search in sources :

Example 71 with ActionFieldValue

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

the class RuleTemplateModelDRLPersistenceTest method testActionInsertFactBothValues.

@Test
public void testActionInsertFactBothValues() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FactPattern fp = new FactPattern("Person");
    fp.setBoundName("$p");
    m.addLhsItem(fp);
    ActionInsertFact aif = new ActionInsertFact("Present");
    aif.setBoundName("f0");
    ActionFieldValue afv0 = new ActionFieldValue();
    afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv0.setField("field1");
    afv0.setValue("$f1");
    aif.addFieldValue(afv0);
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("field2");
    afv1.setValue("$f2");
    aif.addFieldValue(afv1);
    m.addRhsItem(aif);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person()\n" + "then\n" + "Present f0 = new Present();\n" + "f0.setField1(\"foo\");\n" + "f0.setField2(\"bar\");\n" + "insert(f0);\n" + "end";
    m.addRow(new String[] { "foo", "bar" });
    checkMarshall(expected, m);
}
Also used : ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 72 with ActionFieldValue

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

the class RuleTemplateModelDRLPersistenceTest method testUpdateModifyMultipleFieldsWithMultipleSkipped4.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped4() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FactPattern fp = new FactPattern("Person");
    fp.setBoundName("$p");
    m.addLhsItem(fp);
    ActionUpdateField auf1 = new ActionUpdateField("$p");
    ActionFieldValue afv0 = new ActionFieldValue();
    afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv0.setField("field1");
    afv0.setValue("$f1");
    auf1.addFieldValue(afv0);
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("field2");
    afv1.setValue("$f2");
    auf1.addFieldValue(afv1);
    ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv2.setField("field3");
    afv2.setValue("$f3");
    auf1.addFieldValue(afv2);
    m.addRhsItem(auf1);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "  $p : Person()\n" + "then\n" + "  modify( $p ) {\n" + "    setField1(\"v1\"),\n" + "    setField3(\"v3\")\n" + "  }\n" + "end";
    m.addRow(new String[] { "v1", null, "v3" });
    checkMarshall(expected, m);
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 73 with ActionFieldValue

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

the class RuleTemplateModelDRLPersistenceTest method checkPattern1StrictlyLiteralPattern2StrictlyTemplate.

@Test
public void checkPattern1StrictlyLiteralPattern2StrictlyTemplate() {
    FactPattern fp1 = new FactPattern("Smurf");
    fp1.setBoundName("p1");
    SingleFieldConstraint p1sfc1 = new SingleFieldConstraint();
    p1sfc1.setOperator("==");
    p1sfc1.setFactType("Smurf");
    p1sfc1.setFieldName("field1");
    p1sfc1.setFieldType(DataType.TYPE_STRING);
    p1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p1sfc1.setValue("value1");
    SingleFieldConstraint p1sfc2 = new SingleFieldConstraint();
    p1sfc2.setOperator("==");
    p1sfc2.setFactType("Smurf");
    p1sfc2.setFieldName("field2");
    p1sfc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    p1sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p1sfc2.setValue("123");
    ActionUpdateField p1auf1 = new ActionUpdateField("p1");
    p1auf1.addFieldValue(new ActionFieldValue("field1", "newValue", DataType.TYPE_STRING));
    p1auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_LITERAL);
    ActionUpdateField p1auf2 = new ActionUpdateField("p1");
    p1auf2.addFieldValue(new ActionFieldValue("field2", "12345", DataType.TYPE_NUMERIC_INTEGER));
    p1auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_LITERAL);
    fp1.addConstraint(p1sfc1);
    fp1.addConstraint(p1sfc2);
    FactPattern fp2 = new FactPattern("Smurf");
    fp2.setBoundName("p2");
    SingleFieldConstraint p2sfc1 = new SingleFieldConstraint();
    p2sfc1.setOperator("==");
    p2sfc1.setFactType("Smurf");
    p2sfc1.setFieldName("field1");
    p2sfc1.setFieldType(DataType.TYPE_STRING);
    p2sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    p2sfc1.setValue("$oldField1");
    SingleFieldConstraint p2sfc2 = new SingleFieldConstraint();
    p2sfc2.setOperator("==");
    p2sfc2.setFactType("Smurf");
    p2sfc2.setFieldName("field2");
    p2sfc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    p2sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    p2sfc2.setValue("$oldField2");
    ActionUpdateField p2auf1 = new ActionUpdateField("p2");
    p2auf1.addFieldValue(new ActionFieldValue("field1", "$newField1", DataType.TYPE_STRING));
    p2auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    ActionUpdateField p2auf2 = new ActionUpdateField("p2");
    p2auf2.addFieldValue(new ActionFieldValue("field2", "$newField2", DataType.TYPE_NUMERIC_INTEGER));
    p2auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    fp2.addConstraint(p2sfc1);
    fp2.addConstraint(p2sfc2);
    // Test 1
    TemplateModel m1 = new TemplateModel();
    m1.addLhsItem(fp1);
    m1.addLhsItem(fp2);
    m1.addRhsItem(p1auf1);
    m1.addRhsItem(p1auf2);
    m1.addRhsItem(p2auf1);
    m1.addRhsItem(p2auf2);
    m1.name = "r1";
    m1.addRow(new String[] { null, null, null, null });
    final String expected1 = "rule \"r1_0\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    p1 : Smurf( field1 == \"value1\", field2 == 123 )\n" + "  then\n" + "    modify( p1 ) {" + "       setField1( \"newValue\" )," + "       setField2( 12345 )" + "    }" + "end";
    checkMarshall(expected1, m1);
    m1.addRow(new String[] { "abc", "0", "def", "1" });
    final String expected2 = "rule \"r1_1\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    p1 : Smurf( field1 == \"value1\", field2 == 123 )\n" + "    p2 : Smurf( field1 == \"abc\", field2 == 0 )\n" + "  then\n" + "    modify( p1 ) {" + "       setField1( \"newValue\" )," + "       setField2( 12345 )" + "    }" + "    modify( p2 ) {" + "       setField1( \"def\" )," + "       setField2( 1 )" + "    }" + "end";
    checkMarshall(expected2 + expected1, m1);
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 74 with ActionFieldValue

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

the class RuleTemplateModelDRLPersistenceTest method testActionUpdateFactSecondValue.

@Test
public void testActionUpdateFactSecondValue() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FactPattern fp = new FactPattern("Person");
    fp.setBoundName("$p");
    m.addLhsItem(fp);
    ActionSetField asf = new ActionSetField("$p");
    ActionFieldValue afv0 = new ActionFieldValue();
    afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv0.setField("field1");
    afv0.setValue("$f1");
    asf.addFieldValue(afv0);
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("field2");
    afv1.setValue("$f2");
    asf.addFieldValue(afv1);
    m.addRhsItem(asf);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person()\n" + "then\n" + "$p.setField2(\"bar\");\n" + "end";
    m.addRow(new String[] { null, "bar" });
    checkMarshall(expected, m);
}
Also used : ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 75 with ActionFieldValue

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

the class RuleTemplateModelDRLPersistenceTest method testEmptyFreeForm.

@Test
public void testEmptyFreeForm() {
    // https://bugzilla.redhat.com/show_bug.cgi?id=1058247
    TemplateModel m = new TemplateModel();
    m.name = "Empty FreeFormLine";
    FreeFormLine fl = new FreeFormLine();
    m.addLhsItem(fl);
    FactPattern fp = new FactPattern("Person");
    fp.setBoundName("$p");
    SingleFieldConstraint sfc1 = new SingleFieldConstraint();
    sfc1.setFieldName("field1");
    sfc1.setFieldType(DataType.TYPE_STRING);
    sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    sfc1.setValue("$f1");
    sfc1.setOperator("==");
    fp.addConstraint(sfc1);
    m.addLhsItem(fp);
    FreeFormLine fr = new FreeFormLine();
    m.addRhsItem(fr);
    ActionSetField asf = new ActionSetField("$p");
    ActionFieldValue afv0 = new ActionFieldValue();
    afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv0.setType(DataType.TYPE_STRING);
    afv0.setField("field1");
    afv0.setValue("$asf1");
    asf.addFieldValue(afv0);
    m.addRhsItem(asf);
    String expected = "rule \"Empty FreeFormLine_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person( field1 == \"foo\" )\n" + "then\n" + "$p.setField1(\"bar\");\n" + "end";
    m.addRow(new String[] { "foo", "bar" });
    checkMarshall(expected, m);
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) 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