Search in sources :

Example 11 with NotDescr

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;
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr) ExistsDescr(org.drools.compiler.lang.descr.ExistsDescr) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) OrDescr(org.drools.compiler.lang.descr.OrDescr) IFactPattern(org.drools.workbench.models.datamodel.rule.IFactPattern)

Example 12 with NotDescr

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;
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr) SAXParseException(org.xml.sax.SAXParseException) Element(org.w3c.dom.Element) ConditionalElementDescr(org.drools.compiler.lang.descr.ConditionalElementDescr)

Example 13 with NotDescr

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());
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) FromDescr(org.drools.compiler.lang.descr.FromDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 14 with NotDescr

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());
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) Test(org.junit.Test)

Example 15 with NotDescr

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());
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) OrDescr(org.drools.compiler.lang.descr.OrDescr) Test(org.junit.Test)

Aggregations

NotDescr (org.drools.compiler.lang.descr.NotDescr)16 Test (org.junit.Test)12 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)11 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)10 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)7 AndDescr (org.drools.compiler.lang.descr.AndDescr)6 OrDescr (org.drools.compiler.lang.descr.OrDescr)4 ExistsDescr (org.drools.compiler.lang.descr.ExistsDescr)3 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)3 ConditionalElementDescr (org.drools.compiler.lang.descr.ConditionalElementDescr)2 FromDescr (org.drools.compiler.lang.descr.FromDescr)2 InputStreamReader (java.io.InputStreamReader)1 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)1 CEDescrBuilder (org.drools.compiler.lang.api.CEDescrBuilder)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)1 GroupElement (org.drools.core.rule.GroupElement)1 Pattern (org.drools.core.rule.Pattern)1 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)1 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)1