Search in sources :

Example 51 with TemplateModel

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

the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints3SecondValue.

@Test
public void testNestedCompositeConstraints3SecondValue() {
    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);
    final SingleFieldConstraint sfc2 = new SingleFieldConstraint();
    sfc2.setFieldName("field2");
    sfc2.setFieldType(DataType.TYPE_STRING);
    sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    sfc2.setValue("$f2");
    sfc2.setOperator("==");
    comp.addConstraint(sfc2);
    CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
    comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
    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);
    comp.addConstraint(comp2);
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field2== \"bar\" )\n" + "then\n" + "end\n";
    m.addRow(new String[] { null, "bar", 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)

Example 52 with TemplateModel

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

the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints6NoValues.

@Test
public void testNestedCompositeConstraints6NoValues() {
    TemplateModel m = new TemplateModel();
    m.name = "t1";
    FactPattern p = new FactPattern("Person");
    m.addLhsItem(p);
    final CompositeFieldConstraint cfc1 = new CompositeFieldConstraint();
    cfc1.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p.addConstraint(cfc1);
    final SingleFieldConstraint cfc1sfc1 = new SingleFieldConstraint();
    cfc1sfc1.setFieldName("field1");
    cfc1sfc1.setFieldType(DataType.TYPE_STRING);
    cfc1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    cfc1sfc1.setValue("$f1");
    cfc1sfc1.setOperator("==");
    cfc1.addConstraint(cfc1sfc1);
    final SingleFieldConstraint cfc1sfc2 = new SingleFieldConstraint();
    cfc1sfc2.setFieldName("field2");
    cfc1sfc2.setFieldType(DataType.TYPE_STRING);
    cfc1sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    cfc1sfc2.setValue("$f2");
    cfc1sfc2.setOperator("==");
    cfc1.addConstraint(cfc1sfc2);
    final CompositeFieldConstraint cfc2 = new CompositeFieldConstraint();
    cfc2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p.addConstraint(cfc2);
    final SingleFieldConstraint cfc2sfc1 = new SingleFieldConstraint();
    cfc2sfc1.setFieldName("field3");
    cfc2sfc1.setFieldType(DataType.TYPE_STRING);
    cfc2sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    cfc2sfc1.setValue("$f3");
    cfc2sfc1.setOperator("==");
    cfc2.addConstraint(cfc2sfc1);
    final SingleFieldConstraint cfc2sfc2 = new SingleFieldConstraint();
    cfc2sfc2.setFieldName("field4");
    cfc2sfc2.setFieldType(DataType.TYPE_STRING);
    cfc2sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    cfc2sfc2.setValue("$f4");
    cfc2sfc2.setOperator("==");
    cfc2.addConstraint(cfc2sfc2);
    final CompositeFieldConstraint cfc3 = new CompositeFieldConstraint();
    cfc3.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p.addConstraint(cfc3);
    final SingleFieldConstraint cfc3sfc1 = new SingleFieldConstraint();
    cfc3sfc1.setFieldName("field5");
    cfc3sfc1.setFieldType(DataType.TYPE_STRING);
    cfc3sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    cfc3sfc1.setValue("$f5");
    cfc3sfc1.setOperator("==");
    cfc3.addConstraint(cfc3sfc1);
    final SingleFieldConstraint cfc3sfc2 = new SingleFieldConstraint();
    cfc3sfc2.setFieldName("field6");
    cfc3sfc2.setFieldType(DataType.TYPE_STRING);
    cfc3sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    cfc3sfc2.setValue("$f6");
    cfc3sfc2.setOperator("==");
    cfc3.addConstraint(cfc3sfc2);
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "end\n";
    m.addRow(new String[] { null, null, null, null, null, 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)

Example 53 with TemplateModel

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

the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectFirstValue.

@Test
public void testSimpleFromCollectFirstValue() {
    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);
    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("$f2");
    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( ) )\n" + "then\n" + "end";
    m.addRow(new String[] { "1", 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) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) Test(org.junit.Test)

Example 54 with TemplateModel

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

the class RuleTemplateModelDRLPersistenceTest method testCompositeConstraintsBothValues.

@Test
public void testCompositeConstraintsBothValues() {
    TemplateModel m = new TemplateModel();
    m.name = "t1";
    FactPattern p1 = new FactPattern("Person");
    m.addLhsItem(p1);
    CompositeFieldConstraint comp = new CompositeFieldConstraint();
    comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p1.addConstraint(comp);
    final SingleFieldConstraint X = new SingleFieldConstraint();
    X.setFieldName("field1");
    X.setFieldType(DataType.TYPE_STRING);
    X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    X.setValue("$f1");
    X.setOperator("==");
    comp.addConstraint(X);
    final SingleFieldConstraint Y = new SingleFieldConstraint();
    Y.setFieldName("field2");
    Y.setFieldType(DataType.TYPE_STRING);
    Y.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    Y.setValue("$f2");
    Y.setOperator("==");
    comp.addConstraint(Y);
    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 55 with TemplateModel

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

the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectSecondValue.

@Test
public void testSimpleFromCollectSecondValue() {
    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);
    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("$f2");
    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() from collect ( Person( field1 == \"foo\" ) )" + "then\n" + "end";
    m.addRow(new String[] { null, "foo" });
    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)

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