Search in sources :

Example 86 with SingleFieldConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testCompositeFactPatternSecondValue.

@Test
public void testCompositeFactPatternSecondValue() {
    TemplateModel m = new TemplateModel();
    m.name = "t1";
    CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_OR);
    FactPattern p1 = new FactPattern("Person");
    SingleFieldConstraint sfc1 = new SingleFieldConstraint();
    sfc1.setFieldName("field1");
    sfc1.setFieldType(DataType.TYPE_STRING);
    sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    sfc1.setValue("$f1");
    sfc1.setOperator("==");
    p1.addConstraint(sfc1);
    FactPattern p2 = new FactPattern("Person");
    SingleFieldConstraint sfc2 = new SingleFieldConstraint();
    sfc2.setFieldName("field2");
    sfc2.setFieldType(DataType.TYPE_STRING);
    sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    sfc2.setValue("$f2");
    sfc2.setOperator("==");
    p2.addConstraint(sfc2);
    cp.addFactPattern(p1);
    cp.addFactPattern(p2);
    m.addLhsItem(cp);
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "(\n" + "Person( )\n" + "or\n" + "Person( field2 == \"bar\" )\n" + ")\n" + "then\n" + "end\n";
    m.addRow(new String[] { null, "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) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) 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 87 with SingleFieldConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testConnectiveConstraintSecondValue.

@Test
public void testConnectiveConstraintSecondValue() {
    TemplateModel m = new TemplateModel();
    m.name = "t1";
    FactPattern p1 = new FactPattern("Person");
    m.addLhsItem(p1);
    final SingleFieldConstraint X = new SingleFieldConstraint();
    X.setFieldName("field1");
    X.setFieldType(DataType.TYPE_STRING);
    X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    X.setValue("$f1");
    X.setOperator("==");
    p1.addConstraint(X);
    ConnectiveConstraint connective = new ConnectiveConstraint();
    connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    connective.setFieldType(DataType.TYPE_STRING);
    connective.setOperator("|| ==");
    connective.setValue("$f2");
    X.setConnectives(new ConnectiveConstraint[1]);
    X.getConnectives()[0] = connective;
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"bar\" )\n" + "then\n" + "end\n";
    m.addRow(new String[] { null, "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) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 88 with SingleFieldConstraint

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

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

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

Aggregations

SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)278 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)250 Test (org.junit.Test)242 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)236 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)218 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)199 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)148 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)142 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)138 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)73 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)65 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)64 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)62 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)28 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)27 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)25 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)23 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)21 ArrayList (java.util.ArrayList)20