Search in sources :

Example 46 with ActionFieldValue

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

the class RuleTemplateModelDRLPersistenceTest method testRHSNonEmptyStringValues.

@Test
public void testRHSNonEmptyStringValues() {
    FactPattern fp = new FactPattern("Smurf");
    fp.setBoundName("p1");
    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);
    // Test 1
    TemplateModel m1 = new TemplateModel();
    m1.addLhsItem(fp);
    m1.addRhsItem(auf1);
    m1.addRhsItem(auf2);
    m1.name = "r1";
    m1.addRow(new String[] { null, null });
    final String expected1 = "rule \"r1_0\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    p1 : Smurf()\n" + "  then\n" + "end";
    checkMarshall(expected1, m1);
    // Test 2
    TemplateModel m2 = new TemplateModel();
    m2.addLhsItem(fp);
    m2.addRhsItem(auf1);
    m2.addRhsItem(auf2);
    m2.name = "r2";
    m2.addRow(new String[] { "   ", "35" });
    final String expected2 = "rule \"r2_0\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    p1 : Smurf()\n" + "  then\n" + "    modify( p1 ) {\n" + "      setAge( 35 )\n" + "    }\n" + "end";
    checkMarshall(expected2, m2);
    // Test 3
    TemplateModel m3 = new TemplateModel();
    m3.addLhsItem(fp);
    m3.addRhsItem(auf1);
    m3.addRhsItem(auf2);
    m3.name = "r3";
    m3.addRow(new String[] { "", null });
    final String expected3 = "rule \"r3_0\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    p1 : Smurf()\n" + "  then\n" + "end";
    checkMarshall(expected3, m3);
    // Test 4
    TemplateModel m4 = new TemplateModel();
    m4.addLhsItem(fp);
    m4.addRhsItem(auf1);
    m4.addRhsItem(auf2);
    m4.name = "r4";
    m4.addRow(new String[] { "", "35" });
    final String expected4 = "rule \"r4_0\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    p1 : Smurf()\n" + "  then\n" + "    modify( p1 ) {\n" + "      setAge( 35 )\n" + "    }\n" + "end";
    checkMarshall(expected4, m4);
}
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 47 with ActionFieldValue

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

the class RuleTemplateModelDRLPersistenceTest method testActionModifyTwoFieldsFirstTemplateSecondLiteral2.

@Test
public void testActionModifyTwoFieldsFirstTemplateSecondLiteral2() {
    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_LITERAL);
    afv1.setField("field2");
    afv1.setValue("bar");
    auf1.addFieldValue(afv1);
    m.addRhsItem(auf1);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "  $p : Person()\n" + "then\n" + "  modify( $p ) {\n" + "    setField2(\"bar\")\n" + "  }\n" + "end";
    m.addRow(new String[] { null });
    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 48 with ActionFieldValue

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

the class RuleTemplateModelDRLPersistenceTest method testUpdateModifyMultipleFieldsWithMultipleSkipped3.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped3() {
    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" + "    setField3(\"v3\")\n" + "  }\n" + "end";
    m.addRow(new String[] { null, 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 49 with ActionFieldValue

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

the class RuleTemplateModelXMLPersistenceTest method getComplexModel.

private TemplateModel getComplexModel() {
    final TemplateModel m = new TemplateModel();
    m.addAttribute(new RuleAttribute("no-loop", "true"));
    final FactPattern pat = new FactPattern("Person");
    pat.setBoundName("p1");
    final SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFactType("Person");
    con.setFieldBinding("f1");
    con.setFieldName("age");
    con.setOperator("<");
    con.setValue("42");
    pat.addConstraint(con);
    m.addLhsItem(pat);
    final CompositeFactPattern comp = new CompositeFactPattern("not");
    comp.addFactPattern(new FactPattern("Cancel"));
    m.addLhsItem(comp);
    final ActionUpdateField set = new ActionUpdateField();
    set.setVariable("p1");
    set.addFieldValue(new ActionFieldValue("status", "rejected", DataType.TYPE_STRING));
    m.addRhsItem(set);
    final ActionRetractFact ret = new ActionRetractFact("p1");
    m.addRhsItem(ret);
    final DSLSentence sen = new DSLSentence();
    sen.setDefinition("Send an email to {administrator}");
    m.addRhsItem(sen);
    return m;
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence)

Example 50 with ActionFieldValue

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

the class GuidedRuleTemplateFactory method makeModelWithActions.

public static TemplateModel makeModelWithActions(final String packageName, final Collection<Import> imports, final String name) {
    final TemplateModel model = new TemplateModel();
    model.getImports().getImports().addAll(imports);
    model.setPackageName(packageName);
    model.name = name;
    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);
    model.addRhsItem(ifc1);
    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);
    model.addRhsItem(ifc2);
    final ActionSetField asf = new ActionSetField();
    asf.setVariable("$a");
    asf.addFieldValue(new ActionFieldValue("age", "33", DataType.TYPE_NUMERIC_INTEGER));
    model.addRhsItem(asf);
    final ActionUpdateField auf = new ActionUpdateField();
    asf.setVariable("$m");
    asf.addFieldValue(new ActionFieldValue("amount", "10000", DataType.TYPE_NUMERIC_INTEGER));
    model.addRhsItem(auf);
    model.addRow(new String[] { "33", null });
    return model;
}
Also used : ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel)

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