Search in sources :

Example 6 with TemplateModel

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

the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectMultipleSubPatternValues.

@Test
public void testSimpleFromCollectMultipleSubPatternValues() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FactPattern fp = new FactPattern("Person");
    SingleFieldConstraint sfc = new SingleFieldConstraint("field1");
    sfc.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    sfc.setFieldType(DataType.TYPE_STRING);
    sfc.setOperator("==");
    sfc.setValue("$f1");
    fp.addConstraint(sfc);
    SingleFieldConstraint sfc1 = new SingleFieldConstraint("field2");
    sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    sfc1.setFieldType(DataType.TYPE_STRING);
    sfc1.setOperator("==");
    sfc1.setValue("$f2");
    fp.addConstraint(sfc1);
    FactPattern fp2 = new FactPattern("java.util.List");
    SingleFieldConstraint sfc2 = new SingleFieldConstraint("size");
    sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    sfc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    sfc2.setOperator(">");
    sfc2.setValue("$f3");
    fp2.addConstraint(sfc2);
    FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
    fac.setRightPattern(fp);
    fac.setFactPattern(fp2);
    m.addLhsItem(fac);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "java.util.List( size > 1 ) from collect ( Person( field1 == \"foo\", field2 == \"bar\" ) ) \n" + "then\n" + "end";
    m.addRow(new String[] { "1", "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) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) Test(org.junit.Test)

Example 7 with TemplateModel

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

the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraintsAllValues.

@Test
public void testNestedCompositeConstraintsAllValues() {
    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);
    final SingleFieldConstraint comp2sfc2 = new SingleFieldConstraint();
    comp2sfc2.setFieldType(DataType.TYPE_STRING);
    comp2sfc2.setFieldName("field3");
    comp2sfc2.setOperator("==");
    comp2sfc2.setValue("$f3");
    comp2sfc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    comp2.addConstraint(comp2sfc2);
    comp.addConstraint(comp2);
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" || ( field2 == \"bar\" && field3 == \"goo\" ) )\n" + "then\n" + "end\n";
    m.addRow(new String[] { "foo", "bar", "goo" });
    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 8 with TemplateModel

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

the class RuleTemplateModelDRLPersistenceTest method testActionInsertFactZeroValues.

@Test
public void testActionInsertFactZeroValues() {
    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" + "insert(f0);\n" + "end";
    m.addRow(new String[] { null, null });
    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 9 with TemplateModel

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

the class RuleTemplateModelDRLPersistenceTest method testInWithSimpleSingleLiteralValue.

@Test
public void testInWithSimpleSingleLiteralValue() {
    TemplateModel m = new TemplateModel();
    m.name = "t1";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFieldType(DataType.TYPE_STRING);
    con.setFieldName("field1");
    con.setOperator("in");
    con.setValue("$f1");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    p.addConstraint(con);
    m.addLhsItem(p);
    m.addRow(new String[] { "ak1,mk1" });
    m.addRow(new String[] { "(ak2,mk2)" });
    m.addRow(new String[] { "( ak3, mk3 )" });
    m.addRow(new String[] { "( \"ak4\", \"mk4\" )" });
    m.addRow(new String[] { "( \"ak5 \", \" mk5\" )" });
    String expected = "rule \"t1_4\"" + "dialect \"mvel\"\n" + "when \n" + "  Person( field1 in (\"ak5 \",\" mk5\") )" + "then \n" + "end" + "rule \"t1_3\"" + "dialect \"mvel\"\n" + "when \n" + "  Person( field1 in (\"ak4\",\"mk4\") )" + "then \n" + "end" + "rule \"t1_2\"" + "dialect \"mvel\"\n" + "when \n" + "  Person( field1 in (\"ak3\",\"mk3\") )" + "then \n" + "end" + "rule \"t1_1\"" + "dialect \"mvel\"\n" + "when \n" + "  Person( field1 in (\"ak2\",\"mk2\") )" + "then \n" + "end" + "rule \"t1_0\"" + "dialect \"mvel\"\n" + "when \n" + "  Person( field1 in (\"ak1\",\"mk1\") )" + "then \n" + "end";
    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) Test(org.junit.Test)

Example 10 with TemplateModel

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

the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints4ThirdValue.

@Test
public void testNestedCompositeConstraints4ThirdValue() {
    TemplateModel m = new TemplateModel();
    m.name = "t1";
    FactPattern p = new FactPattern("Person");
    m.addLhsItem(p);
    CompositeFieldConstraint comp1 = new CompositeFieldConstraint();
    comp1.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    final SingleFieldConstraint comp1sfc1 = new SingleFieldConstraint();
    comp1sfc1.setFieldName("field1");
    comp1sfc1.setFieldType(DataType.TYPE_STRING);
    comp1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    comp1sfc1.setValue("$f1");
    comp1sfc1.setOperator("==");
    comp1.addConstraint(comp1sfc1);
    final SingleFieldConstraint comp1sfc2 = new SingleFieldConstraint();
    comp1sfc2.setFieldName("field2");
    comp1sfc2.setFieldType(DataType.TYPE_STRING);
    comp1sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    comp1sfc2.setValue("$f2");
    comp1sfc2.setOperator("==");
    comp1.addConstraint(comp1sfc2);
    p.addConstraint(comp1);
    CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
    comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    final SingleFieldConstraint comp2sfc1 = new SingleFieldConstraint();
    comp2sfc1.setFieldType(DataType.TYPE_STRING);
    comp2sfc1.setFieldName("field3");
    comp2sfc1.setOperator("==");
    comp2sfc1.setValue("$f3");
    comp2sfc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    comp2.addConstraint(comp2sfc1);
    final SingleFieldConstraint comp2sfc2 = new SingleFieldConstraint();
    comp2sfc2.setFieldName("field4");
    comp2sfc2.setFieldType(DataType.TYPE_STRING);
    comp2sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    comp2sfc2.setValue("$f4");
    comp2sfc2.setOperator("==");
    comp2.addConstraint(comp2sfc2);
    p.addConstraint(comp2);
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field3 == \"goo\" )\n" + "then\n" + "end\n";
    m.addRow(new String[] { null, null, "goo", null });
    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)

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)4 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