Search in sources :

Example 1 with EntryPointDescr

use of org.drools.drl.ast.descr.EntryPointDescr in project drools by kiegroup.

the class RuleParserTest method testEntryPoint2.

@Test
public void testEntryPoint2() throws Exception {
    final String text = "rule X when StockTick( symbol==\"ACME\") from entry-point \"StreamA\" then end";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", text);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    RuleDescr rule = pkg.getRules().get(0);
    PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    assertEquals(1, pattern.getDescrs().size());
    ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
    assertEquals("symbol==\"ACME\"", fcd.getExpression());
    assertNotNull(pattern.getSource());
    EntryPointDescr entry = (EntryPointDescr) pattern.getSource();
    assertEquals("StreamA", entry.getEntryId());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) EntryPointDescr(org.drools.drl.ast.descr.EntryPointDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 2 with EntryPointDescr

use of org.drools.drl.ast.descr.EntryPointDescr in project drools by kiegroup.

the class WindowReferenceGenerator method addField.

private void addField(KnowledgeBuilderImpl kbuilder, PackageModel packageModel, WindowDeclarationDescr descr) {
    final String windowName = toVar(descr.getName());
    final MethodCallExpr initializer = createDslTopLevelMethod(WINDOW_CALL);
    final PatternDescr pattern = descr.getPattern();
    ParsedBehavior behavior = pattern.getBehaviors().stream().map(this::parseTypeFromBehavior).findFirst().orElseThrow(RuntimeException::new);
    final WindowDefinition.Type windowType = behavior.windowType;
    initializer.addArgument(new NameExpr(windowType.getDeclaringClass().getCanonicalName() + "." + windowType.toString()));
    initializer.addArgument(new IntegerLiteralExpr(behavior.duration.getValue()));
    final TimeUnit timeUnit = behavior.duration.getTimeUnit();
    initializer.addArgument(new NameExpr(timeUnit.getDeclaringClass().getCanonicalName() + "." + timeUnit.name()));
    final Class<?> initClass = DrlxParseUtil.getClassFromContext(typeResolver, pattern.getObjectType());
    initializer.addArgument(new ClassExpr(toJavaParserType(initClass)));
    if (pattern.getSource() != null) {
        String epName = ((EntryPointDescr) pattern.getSource()).getEntryId();
        MethodCallExpr entryPointCall = createDslTopLevelMethod(ENTRY_POINT_CALL);
        entryPointCall.addArgument(toStringLiteral(epName));
        initializer.addArgument(entryPointCall);
    }
    parseConditions(kbuilder, packageModel, pattern, initClass).forEach(initializer::addArgument);
    packageModel.addAllWindowReferences(windowName, initializer);
}
Also used : IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) PatternDescr(org.drools.drl.ast.descr.PatternDescr) NameExpr(com.github.javaparser.ast.expr.NameExpr) EntryPointDescr(org.drools.drl.ast.descr.EntryPointDescr) TimeUnit(java.util.concurrent.TimeUnit) ClassExpr(com.github.javaparser.ast.expr.ClassExpr) WindowDefinition(org.drools.model.WindowDefinition) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 3 with EntryPointDescr

use of org.drools.drl.ast.descr.EntryPointDescr in project drools by kiegroup.

the class SourceDescrBuilderImpl method entryPoint.

public P entryPoint(String entryPoint) {
    EntryPointDescr ep = new EntryPointDescr(entryPoint);
    ep.setResource(descr.getResource());
    descr.setSource(ep);
    return parent;
}
Also used : EntryPointDescr(org.drools.drl.ast.descr.EntryPointDescr)

Example 4 with EntryPointDescr

use of org.drools.drl.ast.descr.EntryPointDescr in project drools by kiegroup.

the class RuleParserTest method testEntryPoint.

@Test
public void testEntryPoint() throws Exception {
    final String text = "rule X when StockTick( symbol==\"ACME\") from entry-point StreamA then end";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", text);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    RuleDescr rule = pkg.getRules().get(0);
    PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    assertEquals(1, pattern.getDescrs().size());
    ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
    assertEquals("symbol==\"ACME\"", fcd.getExpression());
    assertNotNull(pattern.getSource());
    EntryPointDescr entry = (EntryPointDescr) pattern.getSource();
    assertEquals("StreamA", entry.getEntryId());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) EntryPointDescr(org.drools.drl.ast.descr.EntryPointDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Aggregations

EntryPointDescr (org.drools.drl.ast.descr.EntryPointDescr)4 PatternDescr (org.drools.drl.ast.descr.PatternDescr)3 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)2 PackageDescr (org.drools.drl.ast.descr.PackageDescr)2 RuleDescr (org.drools.drl.ast.descr.RuleDescr)2 Test (org.junit.Test)2 ClassExpr (com.github.javaparser.ast.expr.ClassExpr)1 IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)1 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 TimeUnit (java.util.concurrent.TimeUnit)1 WindowDefinition (org.drools.model.WindowDefinition)1