Search in sources :

Example 6 with CompositeFactPattern

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

the class RuleModelDRLPersistenceTest method testInvalidComposite.

@Test
public void testInvalidComposite() throws Exception {
    RuleModel m = new RuleModel();
    CompositeFactPattern com = new CompositeFactPattern("not");
    m.addLhsItem(com);
    String s = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertNotNull(s);
    m.addLhsItem(new CompositeFactPattern("or"));
    m.addLhsItem(new CompositeFactPattern("exists"));
    s = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertNotNull(s);
}
Also used : CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 7 with CompositeFactPattern

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

the class RuleModelDRLPersistenceTest method testCompositeFactPatternWithFromWithDSL.

@Test
public void testCompositeFactPatternWithFromWithDSL() {
    final RuleModel m = new RuleModel();
    m.name = "model";
    final DSLSentence sen = new DSLSentence();
    sen.setDefinition("A DSL phrase");
    m.addLhsItem(sen);
    final FactPattern fp1 = new FactPattern("Data");
    fp1.setBoundName("$d");
    m.addLhsItem(fp1);
    final CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_NOT);
    final FactPattern fp2 = new FactPattern("Person");
    final FromCompositeFactPattern ffp1 = new FromCompositeFactPattern();
    ffp1.setExpression(new ExpressionFormLine(new ExpressionVariable(fp1.getBoundName(), fp1.getFactType())));
    ffp1.setFactPattern(fp2);
    cp.addFactPattern(ffp1);
    m.addLhsItem(cp);
    final String actual = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    final String expected = "rule \"model\"\n" + "dialect \"mvel\"\n" + "when\n" + "A DSL phrase\n" + ">$d : Data( )\n" + ">not ( Person( ) from $d\n" + ")\n" + "then\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected, actual);
}
Also used : ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) Test(org.junit.Test)

Example 8 with CompositeFactPattern

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

the class RuleModelDRLPersistenceTest method getComplexModel.

private RuleModel getComplexModel(boolean useDsl) {
    final RuleModel m = new RuleModel();
    m.name = "Complex Rule";
    m.setPackageName("org.test");
    m.addAttribute(new RuleAttribute("no-loop", "true"));
    m.addAttribute(new RuleAttribute("salience", "-10"));
    m.addAttribute(new RuleAttribute("agenda-group", "aGroup"));
    final FactPattern pat = new FactPattern("Person");
    pat.setBoundName("p1");
    final SingleFieldConstraint con = new SingleFieldConstraint();
    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 upd1 = new ActionUpdateField();
    upd1.setVariable("p1");
    upd1.addFieldValue(new ActionFieldValue("status", "rejected", DataType.TYPE_STRING));
    upd1.addFieldValue(new ActionFieldValue("name", "Fred", DataType.TYPE_STRING));
    m.addRhsItem(upd1);
    final ActionRetractFact ret = new ActionRetractFact("p1");
    m.addRhsItem(ret);
    if (useDsl) {
        final DSLSentence sen = new DSLSentence();
        sen.setDefinition("Send an email to {administrator}");
        m.addRhsItem(sen);
    }
    addModelField("org.test.Person", "this", "org.test.Person", DataType.TYPE_THIS);
    addModelField("org.test.Person", "age", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    addModelField("org.test.Person", "status", String.class.getName(), DataType.TYPE_STRING);
    return m;
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) 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) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence)

Example 9 with CompositeFactPattern

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

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

the class RuleTemplateModelDRLPersistenceTest method testCompositeFactPatternFirstValue.

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

Aggregations

CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)27 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)23 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)22 Test (org.junit.Test)22 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)21 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)21 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)18 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)16 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)15 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)9 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)4 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)4 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)4 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)3 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)3 DSLSentence (org.drools.workbench.models.datamodel.rule.DSLSentence)3 IFactPattern (org.drools.workbench.models.datamodel.rule.IFactPattern)3 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)3 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)2 IAction (org.drools.workbench.models.datamodel.rule.IAction)2