Search in sources :

Example 61 with TemplateModel

use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints2AllValues.

@Test
public void testNestedCompositeConstraints2AllValues() {
    TemplateModel m = new TemplateModel();
    m.name = "t1";
    FactPattern p = new FactPattern("Person");
    CompositeFieldConstraint comp = new CompositeFieldConstraint();
    comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p.addConstraint(comp);
    m.addLhsItem(p);
    final SingleFieldConstraint sfc1 = new SingleFieldConstraint();
    sfc1.setFieldName("field1");
    sfc1.setFieldType(DataType.TYPE_STRING);
    sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    sfc1.setValue("$f1");
    sfc1.setOperator("==");
    comp.addConstraint(sfc1);
    CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
    comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
    final SingleFieldConstraint comp2sfc1 = new SingleFieldConstraint();
    comp2sfc1.setFieldType(DataType.TYPE_STRING);
    comp2sfc1.setFieldName("field2");
    comp2sfc1.setOperator("==");
    comp2sfc1.setValue("$f2");
    comp2sfc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    comp2.addConstraint(comp2sfc1);
    comp.addConstraint(comp2);
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" || ( field2 == \"bar\" ) )\n" + "then\n" + "end\n";
    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) 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) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 62 with TemplateModel

use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceTest method testRHSDelimitedNonEmptyStringValues.

@Test
public void testRHSDelimitedNonEmptyStringValues() {
    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" + "      setName( \"   \" ),\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" + "    modify( p1 ) {\n" + "      setName( \"\" )\n" + "    }\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" + "      setName( \"\" ),\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 63 with TemplateModel

use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceTest method testFromCollectFreeFormLineSecondValue.

@Test
public void testFromCollectFreeFormLineSecondValue() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FreeFormLine ffl = new FreeFormLine();
    ffl.setText("Person( field1 == \"@{f1}\", field2 == \"@{f2}\" )");
    FactPattern fp = new FactPattern("java.util.List");
    FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
    fac.setRightPattern(ffl);
    fac.setFactPattern(fp);
    m.addLhsItem(fac);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "end";
    m.addRow(new String[] { null, "foo" });
    checkMarshall(expected, m);
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) 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) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) Test(org.junit.Test)

Example 64 with TemplateModel

use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceTest method testLHSNonEmptyStringValues.

@Test
public void testLHSNonEmptyStringValues() {
    FactPattern fp = new FactPattern("Smurf");
    fp.setBoundName("p1");
    SingleFieldConstraint sfc1 = new SingleFieldConstraint();
    sfc1.setOperator("==");
    sfc1.setFactType("Smurf");
    sfc1.setFieldName("name");
    sfc1.setFieldType(DataType.TYPE_STRING);
    sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    sfc1.setValue("$f1");
    SingleFieldConstraint sfc2 = new SingleFieldConstraint();
    sfc2.setOperator("==");
    sfc2.setFactType("Smurf");
    sfc2.setFieldName("age");
    sfc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    sfc2.setValue("$f2");
    fp.addConstraint(sfc1);
    fp.addConstraint(sfc2);
    // Test 1
    TemplateModel m1 = new TemplateModel();
    m1.addLhsItem(fp);
    m1.name = "r1";
    m1.addRow(new String[] { null, null });
    final String expected1 = "rule \"r1_0\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "  then\n" + "end";
    checkMarshall(expected1, m1);
    // Test 2
    TemplateModel m2 = new TemplateModel();
    m2.addLhsItem(fp);
    m2.name = "r2";
    m2.addRow(new String[] { "   ", "35" });
    final String expected2 = "rule \"r2_0\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    p1 : Smurf( age == 35 )\n" + "  then\n" + "end";
    checkMarshall(expected2, m2);
    // Test 3
    TemplateModel m3 = new TemplateModel();
    m3.addLhsItem(fp);
    m3.name = "r3";
    m3.addRow(new String[] { "", null });
    final String expected3 = "rule \"r3_0\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "  then\n" + "end";
    checkMarshall(expected3, m3);
    // Test 4
    TemplateModel m4 = new TemplateModel();
    m4.addLhsItem(fp);
    m4.name = "r4";
    m4.addRow(new String[] { "", "35" });
    final String expected4 = "rule \"r4_0\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    p1 : Smurf( age == 35 )\n" + "  then\n" + "end";
    checkMarshall(expected4, m4);
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) 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 65 with TemplateModel

use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceTest method testActionModifyTwoFieldsFirstTemplateSecondLiteral1.

@Test
public void testActionModifyTwoFieldsFirstTemplateSecondLiteral1() {
    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" + "    setField1(\"foo\"),\n" + "    setField2(\"bar\")\n" + "  }\n" + "end";
    m.addRow(new String[] { "foo" });
    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)

Aggregations

TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)118 Test (org.junit.Test)103 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)89 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)88 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)85 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)64 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)63 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)34 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)26 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)16 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)11 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)8 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)7 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)6 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)5 Query (org.apache.lucene.search.Query)3 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)3 Path (org.uberfire.backend.vfs.Path)3 ArrayList (java.util.ArrayList)2 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)2