Search in sources :

Example 26 with SingleFieldConstraint

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

the class RuleTemplateModelDRLPersistenceTest method checkLHSMultipleFactPatternsWhenPattern1LiteralPattern2Template.

@Test
public void checkLHSMultipleFactPatternsWhenPattern1LiteralPattern2Template() {
    FactPattern fp1 = new FactPattern("Smurf");
    fp1.setBoundName("p1");
    SingleFieldConstraint p1sfc1 = new SingleFieldConstraint();
    p1sfc1.setOperator("==");
    p1sfc1.setFactType("Smurf");
    p1sfc1.setFieldName("field1");
    p1sfc1.setFieldType(DataType.TYPE_STRING);
    p1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p1sfc1.setValue("value1");
    SingleFieldConstraint p1sfc2 = new SingleFieldConstraint();
    p1sfc2.setOperator("==");
    p1sfc2.setFactType("Smurf");
    p1sfc2.setFieldName("field2");
    p1sfc2.setFieldType(DataType.TYPE_STRING);
    p1sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p1sfc2.setValue("value2");
    fp1.addConstraint(p1sfc1);
    fp1.addConstraint(p1sfc2);
    FactPattern fp2 = new FactPattern("Smurf");
    fp2.setBoundName("p2");
    SingleFieldConstraint p2sfc1 = new SingleFieldConstraint();
    p2sfc1.setOperator("==");
    p2sfc1.setFactType("Smurf");
    p2sfc1.setFieldName("field3");
    p2sfc1.setFieldType(DataType.TYPE_STRING);
    p2sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    p2sfc1.setValue("$key");
    fp2.addConstraint(p2sfc1);
    // Test 1
    TemplateModel m1 = new TemplateModel();
    m1.addLhsItem(fp1);
    m1.addLhsItem(fp2);
    m1.name = "r1";
    m1.addRow(new String[] { null });
    final String expected1 = "rule \"r1_0\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    p1 : Smurf( field1 == \"value1\", field2 == \"value2\" )\n" + "  then\n" + "end";
    checkMarshall(expected1, m1);
    // Test 2
    TemplateModel m2 = new TemplateModel();
    m2.addLhsItem(fp1);
    m2.addLhsItem(fp2);
    m2.name = "r2";
    m2.addRow(new String[] { "value3" });
    final String expected2 = "rule \"r2_0\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    p1 : Smurf( field1 == \"value1\", field2 == \"value2\" )\n" + "    p2 : Smurf( field3 == \"value3\" )\n" + "  then\n" + "end";
    checkMarshall(expected2, m2);
}
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 27 with SingleFieldConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints6LiteralsAndVariablesWithValues.

@Test
public void testNestedCompositeConstraints6LiteralsAndVariablesWithValues() {
    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_LITERAL);
    cfc1sfc1.setValue("v1");
    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_LITERAL);
    cfc2sfc1.setValue("v3");
    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_LITERAL);
    cfc3sfc1.setValue("v5");
    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" + "Person( field1 == \"v1\" || field2 == \"v2\", field3 == \"v3\" || field4 == \"v4\", field5 == \"v5\" || field6 == \"v6\" )\n" + "then\n" + "end\n";
    m.addRow(new String[] { "v2", "v4", "v6" });
    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 28 with SingleFieldConstraint

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

the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints5SecondValue.

@Test
public void testNestedCompositeConstraints5SecondValue() {
    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( 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 29 with SingleFieldConstraint

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

the class RuleTemplateModelXMLPersistenceTest method getComplexModel.

private TemplateModel getComplexModel() {
    final TemplateModel m = new TemplateModel();
    m.addAttribute(new RuleAttribute("no-loop", "true"));
    final FactPattern pat = new FactPattern("Person");
    pat.setBoundName("p1");
    final SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFactType("Person");
    con.setFieldBinding("f1");
    con.setFieldName("age");
    con.setOperator("<");
    con.setValue("42");
    pat.addConstraint(con);
    m.addLhsItem(pat);
    final CompositeFactPattern comp = new CompositeFactPattern("not");
    comp.addFactPattern(new FactPattern("Cancel"));
    m.addLhsItem(comp);
    final ActionUpdateField set = new ActionUpdateField();
    set.setVariable("p1");
    set.addFieldValue(new ActionFieldValue("status", "rejected", DataType.TYPE_STRING));
    m.addRhsItem(set);
    final ActionRetractFact ret = new ActionRetractFact("p1");
    m.addRhsItem(ret);
    final DSLSentence sen = new DSLSentence();
    sen.setDefinition("Send an email to {administrator}");
    m.addRhsItem(sen);
    return m;
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence)

Example 30 with SingleFieldConstraint

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

the class TemplateModelTest method testAddRowInvalidColumnCount.

@Test
public void testAddRowInvalidColumnCount() throws Exception {
    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("==");
    con.setValue("$f1");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    p.addConstraint(con);
    m.addLhsItem(p);
    try {
        m.addRow(new String[] {});
        Assert.fail("Expected IlegalArgumentException");
    } catch (IllegalArgumentException iae) {
        assertEquals("Invalid numbers of columns: 0 expected: 1", iae.getMessage());
    }
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) 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