Search in sources :

Example 1 with RuleResult

use of com.duangframework.rule.entity.RuleResult in project duangframework by tcrct.

the class RuleFactory method execute.

/**
 * 执行规则验证
 * @param ruleParams
 * @return
 */
public static RuleResult execute(List<RuleParam> ruleParams) {
    if (ToolsKit.isEmpty(ruleParams)) {
        throw new EmptyNullException("ruleParams is null");
    }
    if (ToolsKit.isEmpty(kieSessionHolder)) {
        throw new EmptyNullException("RuleFactory.kieSessionHolder is null");
    }
    KieSession kieSession = kieSessionHolder.kieSession();
    RuleResult ruleResult = new RuleResult(200, "success");
    try {
        for (RuleParam ruleParam : ruleParams) {
            Map<String, Object> ruleParamsMap = ruleParam.toMap();
            kieSession.insert(ruleParamsMap);
            int ruleFiredCount = kieSession.fireAllRules(new RuleNameEndsWithAgendaFilter(ruleParam.getRuleName()));
            if (ruleFiredCount <= 0) {
                throw new ServiceException().setMessage("verification [" + ruleParam.getRuleName() + "] is not pass!");
            }
        }
    } catch (ServiceException e) {
        ruleResult.setCode(500);
        ruleResult.setMessage(e.getMessage());
        logger.warn(e.getMessage(), e);
    }
    kieSession.destroy();
    return ruleResult;
}
Also used : ServiceException(com.duangframework.core.exceptions.ServiceException) RuleParam(com.duangframework.rule.entity.RuleParam) EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) KieSession(org.kie.api.runtime.KieSession) RuleResult(com.duangframework.rule.entity.RuleResult) RuleNameEndsWithAgendaFilter(org.drools.core.base.RuleNameEndsWithAgendaFilter)

Aggregations

EmptyNullException (com.duangframework.core.exceptions.EmptyNullException)1 ServiceException (com.duangframework.core.exceptions.ServiceException)1 RuleParam (com.duangframework.rule.entity.RuleParam)1 RuleResult (com.duangframework.rule.entity.RuleResult)1 RuleNameEndsWithAgendaFilter (org.drools.core.base.RuleNameEndsWithAgendaFilter)1 KieSession (org.kie.api.runtime.KieSession)1