use of org.drools.compiler.lang.descr.QueryDescr in project drools by kiegroup.
the class RuleBuilder method preProcess.
public static void preProcess(final RuleBuildContext context) {
RuleDescr ruleDescr = context.getRuleDescr();
// Query and get object instead of using String
if (null != ruleDescr.getParentName() && null != context.getPkg().getRule(ruleDescr.getParentName())) {
context.getRule().setParent(context.getPkg().getRule(ruleDescr.getParentName()));
}
parseUnitAnnotations(context, context.getRule(), ruleDescr);
// add all the rule's meta attributes
buildMetaAttributes(context);
if (context.getRuleDescr() instanceof QueryDescr) {
context.getDialect().getQueryBuilder().build(context, (QueryDescr) context.getRuleDescr());
}
context.initRule();
}
use of org.drools.compiler.lang.descr.QueryDescr in project drools by kiegroup.
the class RuleParserTest method testSimpleQuery.
@Test
public void testSimpleQuery() throws Exception {
final QueryDescr query = (QueryDescr) parseResource("query", "simple_query.drl");
assertNotNull(query);
assertEquals("simple_query", query.getName());
final AndDescr lhs = query.getLhs();
assertNotNull(lhs);
assertEquals(3, lhs.getDescrs().size());
// Check first pattern
final PatternDescr first = (PatternDescr) lhs.getDescrs().get(0);
assertEquals("foo3", first.getIdentifier());
assertEquals("Bar", first.getObjectType());
assertEquals(1, first.getConstraint().getDescrs().size());
AndDescr and = (AndDescr) first.getConstraint();
ExprConstraintDescr fld = (ExprConstraintDescr) and.getDescrs().get(0);
assertNotNull(fld);
assertEquals("a==3", fld.getExpression());
// Check second pattern
final PatternDescr second = (PatternDescr) lhs.getDescrs().get(1);
assertEquals("foo4", second.getIdentifier());
assertEquals("Bar", second.getObjectType());
assertEquals(1, second.getDescrs().size());
// check it has field bindings.
final ExprConstraintDescr bindingDescr = (ExprConstraintDescr) second.getDescrs().get(0);
assertEquals("a4:a==4", bindingDescr.getExpression());
}
Aggregations