use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class KnowledgeBuilderTest method testOr.
@Test
public void testOr() throws Exception {
final KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
final RuleImpl rule = createRule(new OrDescr(), builder, "update(stilton);");
assertLength(0, builder.getErrors().getErrors());
final GroupElement lhs = rule.getLhs();
assertLength(1, lhs.getChildren());
final GroupElement or = (GroupElement) lhs.getChildren().get(0);
assertLength(1, or.getChildren());
final Pattern pattern = (Pattern) or.getChildren().get(0);
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class KnowledgeBuilderTest method testExists.
@Test
public void testExists() throws Exception {
KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
// Make sure we can't accessa variable bound inside the not node
RuleImpl rule = createRule(new ExistsDescr(), builder, "update(stilton);");
assertTrue(builder.hasErrors());
builder = new KnowledgeBuilderImpl();
rule = createRule(new ExistsDescr(), builder, "");
assertEquals(0, builder.getErrors().getErrors().length);
final GroupElement lhs = rule.getLhs();
assertLength(1, lhs.getChildren());
final GroupElement exists = (GroupElement) lhs.getChildren().get(0);
assertLength(1, exists.getChildren());
final Pattern pattern = (Pattern) exists.getChildren().get(0);
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class KnowledgeBuilderTest method testAnd.
@Test
public void testAnd() throws Exception {
final KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
final RuleImpl rule = createRule(new AndDescr(), builder, "update(stilton);");
assertLength(0, builder.getErrors().getErrors());
final GroupElement lhs = rule.getLhs();
assertLength(1, lhs.getChildren());
final GroupElement and = (GroupElement) lhs.getChildren().get(0);
assertLength(1, and.getChildren());
final Pattern pattern = (Pattern) and.getChildren().get(0);
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class KnowledgeBuilderTest method testNot.
@Test
public void testNot() throws Exception {
KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
// Make sure we can't accessa variable bound inside the not node
RuleImpl rule = createRule(new NotDescr(), builder, "update(stilton);");
assertTrue(builder.hasErrors());
builder = new KnowledgeBuilderImpl();
rule = createRule(new NotDescr(), builder, "");
assertEquals(0, builder.getErrors().getErrors().length);
final GroupElement lhs = rule.getLhs();
assertLength(1, lhs.getChildren());
final GroupElement not = (GroupElement) lhs.getChildren().get(0);
assertLength(1, not.getChildren());
final Pattern pattern = (Pattern) not.getChildren().get(0);
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class RuleBuilder method buildAttributes.
public static void buildAttributes(final RuleBuildContext context) {
final RuleImpl rule = context.getRule();
final RuleDescr ruleDescr = context.getRuleDescr();
boolean enforceEager = false;
for (final AttributeDescr attributeDescr : ruleDescr.getAttributes().values()) {
final String name = attributeDescr.getName();
switch(name) {
case "no-loop":
rule.setNoLoop(getBooleanValue(attributeDescr, true));
enforceEager = true;
break;
case "auto-focus":
rule.setAutoFocus(getBooleanValue(attributeDescr, true));
break;
case "agenda-group":
if (StringUtils.isEmpty(rule.getRuleFlowGroup())) {
// don't override if RFG has already set this
rule.setAgendaGroup(attributeDescr.getValue());
} else {
if (rule.getRuleFlowGroup().equals(attributeDescr.getValue())) {
DroolsWarning warn = new RuleBuildWarning(rule, context.getParentDescr(), null, "Both an agenda-group ( " + attributeDescr.getValue() + " ) and a ruleflow-group ( " + rule.getRuleFlowGroup() + " ) are defined for rule " + rule.getName() + ". Since version 6.x the " + "two concepts have been unified, the ruleflow-group name will override the agenda-group. ");
context.addWarning(warn);
}
}
break;
case "activation-group":
rule.setActivationGroup(attributeDescr.getValue());
break;
case "ruleflow-group":
rule.setRuleFlowGroup(attributeDescr.getValue());
if (!rule.getAgendaGroup().equals(AgendaGroup.MAIN) && !rule.getAgendaGroup().equals(attributeDescr.getValue())) {
DroolsWarning warn = new RuleBuildWarning(rule, context.getParentDescr(), null, "Both an agenda-group ( " + attributeDescr.getValue() + " ) and a ruleflow-group ( " + rule.getRuleFlowGroup() + " ) are defined for rule " + rule.getName() + ". Since version 6.x the " + "two concepts have been unified, the ruleflow-group name will override the agenda-group. ");
context.addWarning(warn);
}
// assign AG to the same name as RFG, as they are aliased to AGs anyway
rule.setAgendaGroup(attributeDescr.getValue());
break;
case "lock-on-active":
boolean lockOnActive = getBooleanValue(attributeDescr, true);
rule.setLockOnActive(lockOnActive);
enforceEager |= lockOnActive;
break;
case DroolsSoftKeywords.DURATION:
case DroolsSoftKeywords.TIMER:
String duration = attributeDescr.getValue();
buildTimer(rule, duration, context);
break;
case "calendars":
buildCalendars(rule, attributeDescr.getValue(), context);
break;
case "date-effective":
try {
Date date = DateUtils.parseDate(attributeDescr.getValue());
final Calendar cal = Calendar.getInstance();
cal.setTime(date);
rule.setDateEffective(cal);
} catch (Exception e) {
DroolsError err = new RuleBuildError(rule, context.getParentDescr(), null, "Wrong date-effective value: " + e.getMessage());
context.addError(err);
}
break;
case "date-expires":
try {
Date date = DateUtils.parseDate(attributeDescr.getValue());
final Calendar cal = Calendar.getInstance();
cal.setTime(date);
rule.setDateExpires(cal);
} catch (Exception e) {
DroolsError err = new RuleBuildError(rule, context.getParentDescr(), null, "Wrong date-expires value: " + e.getMessage());
context.addError(err);
}
break;
}
}
buildSalience(context);
buildEnabled(context);
parseAnnotation(context, rule, ruleDescr, enforceEager);
}
Aggregations