Search in sources :

Example 1 with CompositeFieldConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints5ThirdValue.

@Test
public void testNestedCompositeConstraints5ThirdValue() {
    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 comp1sfc1 = new SingleFieldConstraint();
    comp1sfc1.setFieldName("field1");
    comp1sfc1.setFieldType(DataType.TYPE_STRING);
    comp1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    comp1sfc1.setValue("$f1");
    comp1sfc1.setOperator("==");
    comp.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("==");
    comp.addConstraint(comp1sfc2);
    final SingleFieldConstraint comp1sfc3 = new SingleFieldConstraint();
    comp1sfc3.setFieldName("field3");
    comp1sfc3.setFieldType(DataType.TYPE_STRING);
    comp1sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    comp1sfc3.setValue("$f3");
    comp1sfc3.setOperator("==");
    comp.addConstraint(comp1sfc3);
    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" });
    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 2 with CompositeFieldConstraint

use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint 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 3 with CompositeFieldConstraint

use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint 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)

Example 4 with CompositeFieldConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints3FirstValue.

@Test
public void testNestedCompositeConstraints3FirstValue() {
    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( field1 == \"foo\" )\n" + "then\n" + "end\n";
    m.addRow(new String[] { "foo", 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 5 with CompositeFieldConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints5FirstValue.

@Test
public void testNestedCompositeConstraints5FirstValue() {
    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 comp1sfc1 = new SingleFieldConstraint();
    comp1sfc1.setFieldName("field1");
    comp1sfc1.setFieldType(DataType.TYPE_STRING);
    comp1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    comp1sfc1.setValue("$f1");
    comp1sfc1.setOperator("==");
    comp.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("==");
    comp.addConstraint(comp1sfc2);
    final SingleFieldConstraint comp1sfc3 = new SingleFieldConstraint();
    comp1sfc3.setFieldName("field3");
    comp1sfc3.setFieldType(DataType.TYPE_STRING);
    comp1sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    comp1sfc3.setValue("$f3");
    comp1sfc3.setOperator("==");
    comp.addConstraint(comp1sfc3);
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" )\n" + "then\n" + "end\n";
    m.addRow(new String[] { "foo", 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)

Aggregations

CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)60 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)59 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)52 Test (org.junit.Test)51 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)50 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)49 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)47 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)34 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)17 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)15 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)14 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)9 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)7 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)7 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)6 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)5 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)3 SmallLabel (org.uberfire.ext.widgets.common.client.common.SmallLabel)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2