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;
}
Aggregations