use of org.drools.compiler.lang.descr.NotDescr in project drools by kiegroup.
the class RuleModelDRLPersistenceImpl method parseExistentialElementDescr.
private CompositeFactPattern parseExistentialElementDescr(final RuleModel m, final ConditionalElementDescr conditionalDescr, final boolean isJavaDialect, final Map<String, String> boundParams, final PackageDataModelOracle dmo) {
CompositeFactPattern comp;
if (conditionalDescr instanceof NotDescr) {
comp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_NOT);
} else if (conditionalDescr instanceof OrDescr) {
comp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_OR);
} else if (conditionalDescr instanceof ExistsDescr) {
comp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_EXISTS);
} else {
throw new IllegalArgumentException("Unknown conditional descr type: " + conditionalDescr);
}
addPatternToComposite(m, conditionalDescr, comp, isJavaDialect, boundParams, dmo);
IFactPattern[] patterns = comp.getPatterns();
return patterns != null && patterns.length > 0 ? comp : null;
}
use of org.drools.compiler.lang.descr.NotDescr in project drools by kiegroup.
the class NotHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final NotDescr notDescr = (NotDescr) parser.getCurrent();
if ((notDescr.getDescrs().size() != 1) && (notDescr.getDescrs().get(0).getClass() != PatternDescr.class)) {
throw new SAXParseException("<not> can only have a single <pattern...> as a child element", parser.getLocator());
}
final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parser.getParent();
parentDescr.addDescr(notDescr);
return null;
}
use of org.drools.compiler.lang.descr.NotDescr in project drools by kiegroup.
the class RuleParserTest method testFromComplexAcessor.
@Test
public void testFromComplexAcessor() throws Exception {
String source = "rule \"Invalid customer id\" ruleflow-group \"validate\" lock-on-active true \n" + " when \n" + " o: Order( ) \n" + " not( Customer( ) from customerService.getCustomer(o.getCustomerId()) ) \n" + " then \n" + " System.err.println(\"Invalid customer id found!\"); \n" + " o.addError(\"Invalid customer id\"); \n" + "end \n";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
assertFalse(parser.getErrorMessages().toString(), parser.hasErrors());
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals("Invalid customer id", rule.getName());
assertEquals(2, rule.getLhs().getDescrs().size());
NotDescr not = (NotDescr) rule.getLhs().getDescrs().get(1);
PatternDescr customer = (PatternDescr) not.getDescrs().get(0);
assertEquals("Customer", customer.getObjectType());
assertEquals("customerService.getCustomer(o.getCustomerId())", ((FromDescr) customer.getSource()).getDataSource().getText());
}
use of org.drools.compiler.lang.descr.NotDescr in project drools by kiegroup.
the class AndDescrTest method testAddUnboundPatternsEtc.
@Test
public void testAddUnboundPatternsEtc() {
final AndDescr and = new AndDescr();
and.addDescr(new NotDescr());
and.addDescr(new PatternDescr("Foo"));
and.addDescr(new NotDescr());
assertEquals(3, and.getDescrs().size());
}
use of org.drools.compiler.lang.descr.NotDescr in project drools by kiegroup.
the class RuleParserTest method testBracketsPrecedence.
/**
*/
@Test
public void testBracketsPrecedence() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "brackets_precedence.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
final AndDescr rootAnd = (AndDescr) rule.getLhs();
assertEquals(2, rootAnd.getDescrs().size());
final OrDescr leftOr = (OrDescr) rootAnd.getDescrs().get(0);
assertEquals(2, leftOr.getDescrs().size());
final NotDescr not = (NotDescr) leftOr.getDescrs().get(0);
final PatternDescr foo1 = (PatternDescr) not.getDescrs().get(0);
assertEquals("Foo", foo1.getObjectType());
final PatternDescr foo2 = (PatternDescr) leftOr.getDescrs().get(1);
assertEquals("Foo", foo2.getObjectType());
final OrDescr rightOr = (OrDescr) rootAnd.getDescrs().get(1);
assertEquals(2, rightOr.getDescrs().size());
final PatternDescr shoes = (PatternDescr) rightOr.getDescrs().get(0);
assertEquals("Shoes", shoes.getObjectType());
final PatternDescr butt = (PatternDescr) rightOr.getDescrs().get(1);
assertEquals("Butt", butt.getObjectType());
}
Aggregations