Search in sources :

Example 1 with SalienceInteger

use of org.drools.core.base.SalienceInteger in project drools by kiegroup.

the class KiePackagesBuilder method setRuleAttributes.

private void setRuleAttributes(Rule rule, RuleImpl ruleImpl) {
    Boolean noLoop = setAttribute(rule, Rule.Attribute.NO_LOOP, ruleImpl::setNoLoop);
    Boolean lockOnActive = setAttribute(rule, Rule.Attribute.LOCK_ON_ACTIVE, ruleImpl::setLockOnActive);
    setAttribute(rule, Rule.Attribute.AUTO_FOCUS, ruleImpl::setAutoFocus);
    setAttribute(rule, Rule.Attribute.ENABLED, e -> ruleImpl.setEnabled(new EnabledBoolean(e)));
    setAttribute(rule, Rule.Attribute.SALIENCE, s -> ruleImpl.setSalience(new SalienceInteger(s)));
    String agendaGroup = setAttribute(rule, Rule.Attribute.AGENDA_GROUP, ruleImpl::setAgendaGroup);
    setAttribute(rule, Rule.Attribute.RULEFLOW_GROUP, rfg -> {
        ruleImpl.setRuleFlowGroup(rfg);
        if (agendaGroup == null) {
            ruleImpl.setAgendaGroup(rfg);
        }
    });
    setAttribute(rule, Rule.Attribute.ACTIVATION_GROUP, ruleImpl::setActivationGroup);
    setAttribute(rule, Rule.Attribute.DURATION, t -> ruleImpl.setTimer(parseTimer(t)));
    setAttribute(rule, Rule.Attribute.TIMER, t -> ruleImpl.setTimer(parseTimer(t)));
    setAttribute(rule, Rule.Attribute.CALENDARS, ruleImpl::setCalendars);
    setAttribute(rule, Rule.Attribute.DATE_EFFECTIVE, ruleImpl::setDateEffective);
    setAttribute(rule, Rule.Attribute.DATE_EXPIRES, ruleImpl::setDateExpires);
    ruleImpl.setEager(ruleImpl.isEager() || noLoop != null || lockOnActive != null);
}
Also used : EnabledBoolean(org.drools.core.base.EnabledBoolean) EnabledBoolean(org.drools.core.base.EnabledBoolean) SalienceInteger(org.drools.core.base.SalienceInteger)

Example 2 with SalienceInteger

use of org.drools.core.base.SalienceInteger in project drools by kiegroup.

the class RuleTest method testGetSalienceValue.

@Test
public void testGetSalienceValue() {
    final RuleImpl rule = new RuleImpl("myrule");
    final int salienceValue = 100;
    Salience salience = new SalienceInteger(salienceValue);
    rule.setSalience(salience);
    assertEquals(salienceValue, rule.getSalienceValue());
    assertFalse(rule.isSalienceDynamic());
}
Also used : Salience(org.drools.core.spi.Salience) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) SalienceInteger(org.drools.core.base.SalienceInteger) Test(org.junit.Test)

Example 3 with SalienceInteger

use of org.drools.core.base.SalienceInteger in project drools by kiegroup.

the class RuleBuilder method buildSalience.

private static void buildSalience(final RuleBuildContext context) {
    String salienceText = context.getRuleDescr().getSalience();
    if (salienceText != null && !salienceText.equals("")) {
        try {
            // First check if it is an Integer
            Salience salience = new SalienceInteger(Integer.parseInt(salienceText));
            context.getRule().setSalience(salience);
        } catch (Exception e) {
            // It wasn't an integer, so build as an expression
            context.getDialect().getSalienceBuilder().build(context);
        }
    }
}
Also used : Salience(org.drools.core.spi.Salience) SalienceInteger(org.drools.core.base.SalienceInteger) ParseException(java.text.ParseException)

Aggregations

SalienceInteger (org.drools.core.base.SalienceInteger)3 Salience (org.drools.core.spi.Salience)2 ParseException (java.text.ParseException)1 EnabledBoolean (org.drools.core.base.EnabledBoolean)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 Test (org.junit.Test)1