Search in sources :

Example 1 with FromCollectCompositeFactPattern

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

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

the class RuleTemplateModelDRLPersistenceTest method testFromCollectFreeFormLineBothValues.

@Test
public void testFromCollectFreeFormLineBothValues() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FreeFormLine ffl = new FreeFormLine();
    ffl.setText("Person( field1 == \"@{f1}\", field2 == \"@{f2}\" )");
    FactPattern fp = new FactPattern("java.util.List");
    FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
    fac.setRightPattern(ffl);
    fac.setFactPattern(fp);
    m.addLhsItem(fac);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "java.util.List() from collect ( Person( field1 == \"foo\", field2 == \"bar\" ) ) \n" + "then\n" + "end";
    m.addRow(new String[] { "foo", "bar" });
    checkMarshall(expected, m);
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) 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 3 with FromCollectCompositeFactPattern

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

the class RuleTemplateModelDRLPersistenceTest method testSimpleFromCollectBothValues.

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

Example 4 with FromCollectCompositeFactPattern

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

the class RuleModelDRLPersistenceUnmarshallingTest method testCollectWithFreeFormDRL_MethodsUndefined.

@Test
public void testCollectWithFreeFormDRL_MethodsUndefined() throws Exception {
    // https://bugzilla.redhat.com/show_bug.cgi?id=1060816
    String drl = "package org.sample.resourceassignment;\n" + "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + "$trans : Transactions()\n" + "$transactions : java.util.List( eval( size > 0 ) ) from collect ( Transaction() from $trans.getRecCategorization().get(\"APES-01\") )\n" + "then\n" + "end";
    addModelField("Transactions", "recCategorization", "java.util.Map", DataType.TYPE_COLLECTION);
    addMethodInformation("java.util.Map", "get", new ArrayList<String>() {

        {
            add("p0");
        }
    }, "java.lang.String", null, DataType.TYPE_STRING);
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(2, m.lhs.length);
    IPattern p0 = m.lhs[0];
    assertTrue(p0 instanceof FactPattern);
    FactPattern fp0 = (FactPattern) p0;
    assertEquals("Transactions", fp0.getFactType());
    assertEquals("$trans", fp0.getBoundName());
    assertEquals(0, fp0.getNumberOfConstraints());
    IPattern p1 = m.lhs[1];
    assertTrue(p1 instanceof FromCollectCompositeFactPattern);
    FromCollectCompositeFactPattern fp1 = (FromCollectCompositeFactPattern) p1;
    assertEquals("java.util.List", fp1.getFactPattern().getFactType());
    assertEquals("$transactions", fp1.getFactPattern().getBoundName());
    assertEquals(1, fp1.getFactPattern().getNumberOfConstraints());
    assertTrue(fp1.getFactPattern().getConstraint(0) instanceof SingleFieldConstraint);
    SingleFieldConstraint fp1sfc = (SingleFieldConstraint) fp1.getFactPattern().getConstraint(0);
    assertEquals("size > 0", fp1sfc.getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_PREDICATE, fp1sfc.getConstraintValueType());
    assertTrue(fp1.getRightPattern() instanceof FromCompositeFactPattern);
    FromCompositeFactPattern fp2 = (FromCompositeFactPattern) fp1.getRightPattern();
    assertNotNull(fp2.getFactPattern());
    FactPattern fp3 = fp2.getFactPattern();
    assertEquals("Transaction", fp3.getFactType());
    assertEquals(0, fp3.getNumberOfConstraints());
    assertNotNull(fp2.getExpression());
    ExpressionFormLine efl = fp2.getExpression();
    assertEquals(3, efl.getParts().size());
    assertTrue(efl.getParts().get(0) instanceof ExpressionVariable);
    ExpressionVariable ev = (ExpressionVariable) efl.getParts().get(0);
    assertEquals("$trans", ev.getName());
    assertEquals("Transactions", ev.getClassType());
    assertTrue(efl.getParts().get(1) instanceof ExpressionText);
    ExpressionText et1 = (ExpressionText) efl.getParts().get(1);
    assertEquals("getRecCategorization()", et1.getName());
    assertEquals("java.lang.String", et1.getClassType());
    assertEquals(DataType.TYPE_STRING, et1.getGenericType());
    assertTrue(efl.getParts().get(2) instanceof ExpressionText);
    ExpressionText et2 = (ExpressionText) efl.getParts().get(2);
    assertEquals("get(\"APES-01\")", et2.getName());
    assertEquals("java.lang.String", et2.getClassType());
    assertEquals(DataType.TYPE_STRING, et2.getGenericType());
    assertEquals(0, m.rhs.length);
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) 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) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 5 with FromCollectCompositeFactPattern

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

the class RuleModelDRLPersistenceUnmarshallingTest method testLHSFromCollectWithListDeclared.

@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1158813
void testLHSFromCollectWithListDeclared() throws Exception {
    String drl = "package org.test;\n" + "rule \"rule1\"\n" + "dialect \"mvel\"\n" + "when\n" + "  c : Customer( )\n" + "  items : List( eval( size == c.items.size )) \n" + "  from collect ( var : Item( price > 10 )) \n" + "then \n" + "end";
    addModelField("org.test.Customer", "this", "org.test.Customer", DataType.TYPE_THIS);
    addModelField("org.test.Item", "this", "org.test.Item", DataType.TYPE_THIS);
    addModelField("org.test.Item", "price", "java.lang.Double", DataType.TYPE_NUMERIC_DOUBLE);
    addModelField("java.util.List", "this", "java.util.List", DataType.TYPE_THIS);
    addMethodInformation("org.test.Customer", "items", new ArrayList<String>() {

        {
        }
    }, DataType.TYPE_NUMERIC_INTEGER, null, DataType.TYPE_NUMERIC_INTEGER);
    when(dmo.getPackageName()).thenReturn("org.test");
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(2, m.lhs.length);
    assertEquals(0, m.rhs.length);
    assertTrue(m.lhs[0] instanceof FactPattern);
    final FactPattern fp = (FactPattern) m.lhs[0];
    assertEquals("Customer", fp.getFactType());
    assertEquals("c", fp.getBoundName());
    assertEquals(0, fp.getNumberOfConstraints());
    assertTrue(m.lhs[1] instanceof FromCollectCompositeFactPattern);
    final FromCollectCompositeFactPattern fcfp = (FromCollectCompositeFactPattern) m.lhs[1];
    assertNotNull(fcfp.getFactPattern());
    assertEquals("List", fcfp.getFactPattern().getFactType());
    assertEquals("items", fcfp.getFactPattern().getBoundName());
    assertEquals(1, fcfp.getFactPattern().getNumberOfConstraints());
    assertTrue(fcfp.getFactPattern().getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint sfc0 = (SingleFieldConstraint) fcfp.getFactPattern().getConstraint(0);
    assertNull(sfc0.getFactType());
    assertNull(sfc0.getFieldName());
    assertEquals("size == c.items.size", sfc0.getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_PREDICATE, sfc0.getConstraintValueType());
    assertNotNull(fcfp.getRightPattern());
    assertTrue(fcfp.getRightPattern() instanceof FactPattern);
    final FactPattern rfp = (FactPattern) fcfp.getRightPattern();
    assertEquals("Item", rfp.getFactType());
    assertEquals("var", rfp.getBoundName());
    assertEquals(1, rfp.getNumberOfConstraints());
    assertTrue(rfp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint sfc1 = (SingleFieldConstraint) rfp.getConstraint(0);
    assertEquals("Item", sfc1.getFactType());
    assertEquals("price", sfc1.getFieldName());
    assertEquals("10", sfc1.getValue());
    assertEquals(">", sfc1.getOperator());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, sfc1.getConstraintValueType());
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) 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) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)27 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)24 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)20 Test (org.junit.Test)18 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)15 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)15 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)12 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)12 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)10 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)10 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)6 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)5 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)5 Widget (com.google.gwt.user.client.ui.Widget)5 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)5 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)4 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)4 ExpressionVariable (org.drools.workbench.models.datamodel.rule.ExpressionVariable)4 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)4