!291 enhancement #IABK5C 校验 EL 表达式,获取校验失败原因

Merge pull request !291 from 与或非/issues/IABK5C
This commit is contained in:
铂赛东
2024-07-24 07:19:55 +00:00
committed by Gitee
2 changed files with 68 additions and 16 deletions

View File

@@ -10,6 +10,7 @@ import com.ql.util.express.InstructionSet;
import com.ql.util.express.exception.QLException;
import com.yomahub.liteflow.builder.el.operator.*;
import com.yomahub.liteflow.common.ChainConstant;
import com.yomahub.liteflow.common.entity.ValidationResp;
import com.yomahub.liteflow.enums.ParseModeEnum;
import com.yomahub.liteflow.exception.*;
import com.yomahub.liteflow.flow.FlowBus;
@@ -242,22 +243,37 @@ public class LiteFlowChainELBuilder {
return this;
}
/**
* EL表达式校验
* @param elStr EL表达式
* @return true 校验成功 false 校验失败
*/
public static boolean validate(String elStr) {
try {
// 移除注释
elStr = ElRegexUtil.removeComments(elStr);
LiteFlowChainELBuilder.createChain().setEL(elStr);
return Boolean.TRUE;
} catch (Exception e) {
LOG.error("validate error",e);
}
return Boolean.FALSE;
}
/**
* EL表达式校验,此方法已经过时,请使用 {@link LiteFlowChainELBuilder#validateWithEx(String)}
*
* @param elStr EL表达式
* @return true 校验成功 false 校验失败
*/
@Deprecated
public static boolean validate(String elStr) {
return validateWithEx(elStr).isSuccess();
}
/**
* 校验
*
* @param elStr
* @return
*/
public static ValidationResp validateWithEx(String elStr) {
ValidationResp resp = new ValidationResp();
try {
// 移除注释
elStr = ElRegexUtil.removeComments(elStr);
LiteFlowChainELBuilder.createChain().setEL(elStr);
resp.setSuccess(true);
} catch (Exception e) {
LOG.error("validate error", e);
resp.setSuccess(false);
resp.setCause(e);
}
return resp;
}
public void build() {
this.chain.setRouteItem(this.route);

View File

@@ -0,0 +1,36 @@
package com.yomahub.liteflow.common.entity;
/**
* 校验结果封装类
*
* @author gaibu
* @since 2.12.2
*/
public class ValidationResp {
/**
* 是否成功true 校验成功false 校验失败
*/
private boolean success;
/**
* 失败抛出的异常,成功时候为 null
*/
private Exception cause;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public Exception getCause() {
return cause;
}
public void setCause(Exception cause) {
this.cause = cause;
}
}