Search in sources :

Example 1 with CollectDescr

use of org.drools.compiler.lang.descr.CollectDescr in project drools by kiegroup.

the class CollectHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final CollectDescr collectDescr = new CollectDescr();
    return collectDescr;
}
Also used : CollectDescr(org.drools.compiler.lang.descr.CollectDescr)

Example 2 with CollectDescr

use of org.drools.compiler.lang.descr.CollectDescr in project drools by kiegroup.

the class CollectHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    final CollectDescr collectDescr = (CollectDescr) parser.getCurrent();
    final Object parent = parser.getParent();
    if (parent.getClass().getName().equals(FromDescr.class.getName())) {
        final PatternDescr resultPattern = (PatternDescr) parser.getParent(1);
        resultPattern.setSource(collectDescr);
    } else if (parent instanceof ConditionalElementDescr) {
        final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent;
        parentDescr.addDescr(collectDescr);
    }
    return collectDescr;
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) CollectDescr(org.drools.compiler.lang.descr.CollectDescr) Element(org.w3c.dom.Element) FromDescr(org.drools.compiler.lang.descr.FromDescr) ConditionalElementDescr(org.drools.compiler.lang.descr.ConditionalElementDescr)

Example 3 with CollectDescr

use of org.drools.compiler.lang.descr.CollectDescr in project drools by kiegroup.

the class RuleParserTest method testAccumulateWithNestedFrom.

@Test
public void testAccumulateWithNestedFrom() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulate_with_nested_from.drl");
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(1, rule.getLhs().getDescrs().size());
    final PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final AccumulateDescr accumulate = (AccumulateDescr) out.getSource();
    PatternDescr person = (PatternDescr) accumulate.getInputPattern();
    assertEquals("Person", person.getObjectType());
    final CollectDescr collect2 = (CollectDescr) person.getSource();
    final PatternDescr people = collect2.getInputPattern();
    assertEquals("People", people.getObjectType());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) CollectDescr(org.drools.compiler.lang.descr.CollectDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) AccumulateDescr(org.drools.compiler.lang.descr.AccumulateDescr) Test(org.junit.Test)

Example 4 with CollectDescr

use of org.drools.compiler.lang.descr.CollectDescr in project drools by kiegroup.

the class RuleParserTest method testCollect.

@Test
public void testCollect() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "collect.drl");
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(1, rule.getLhs().getDescrs().size());
    final PatternDescr outPattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final CollectDescr collect = (CollectDescr) outPattern.getSource();
    final PatternDescr pattern = (PatternDescr) collect.getInputPattern();
    assertEquals("Person", pattern.getObjectType());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) CollectDescr(org.drools.compiler.lang.descr.CollectDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 5 with CollectDescr

use of org.drools.compiler.lang.descr.CollectDescr in project drools by kiegroup.

the class CollectBuilder method build.

public RuleConditionElement build(final RuleBuildContext context, final BaseDescr descr, final Pattern prefixPattern) {
    final CollectDescr collectDescr = (CollectDescr) descr;
    final PatternBuilder patternBuilder = (PatternBuilder) context.getDialect().getBuilder(PatternDescr.class);
    final Pattern sourcePattern = (Pattern) patternBuilder.build(context, collectDescr.getInputPattern());
    if (sourcePattern == null) {
        return null;
    }
    final String className = "collect" + context.getNextId();
    collectDescr.setClassMethodName(className);
    Pattern resultPattern = (Pattern) context.getDeclarationResolver().peekBuildStack();
    return new Collect(sourcePattern, resultPattern);
}
Also used : Pattern(org.drools.core.rule.Pattern) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) CollectDescr(org.drools.compiler.lang.descr.CollectDescr) Collect(org.drools.core.rule.Collect)

Aggregations

CollectDescr (org.drools.compiler.lang.descr.CollectDescr)8 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)5 AccumulateDescr (org.drools.compiler.lang.descr.AccumulateDescr)3 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)3 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)3 Test (org.junit.Test)3 FromDescr (org.drools.compiler.lang.descr.FromDescr)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConditionalElementDescr (org.drools.compiler.lang.descr.ConditionalElementDescr)1 EntryPointDescr (org.drools.compiler.lang.descr.EntryPointDescr)1 PatternSourceDescr (org.drools.compiler.lang.descr.PatternSourceDescr)1 Collect (org.drools.core.rule.Collect)1 Pattern (org.drools.core.rule.Pattern)1 StringUtils.splitArgumentsList (org.drools.core.util.StringUtils.splitArgumentsList)1 RuleModelPersistenceHelper.findMethodInfo (org.drools.workbench.models.commons.backend.rule.RuleModelPersistenceHelper.findMethodInfo)1 ActionFieldList (org.drools.workbench.models.datamodel.rule.ActionFieldList)1 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)1 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)1 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)1