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());
}
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);
}
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;
}
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());
}
Aggregations