From 3bbef46a5d688b714d68c61861b9677c880b0fc6 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Tue, 9 Jul 2024 10:39:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?enhancement=20#IABK5C=20=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=20EL=20=E8=A1=A8=E8=BE=BE=E5=BC=8F=EF=BC=8C=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=A4=B1=E8=B4=A5=E5=8E=9F=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/builder/el/LiteFlowChainELBuilder.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index 802be9890..88bbe5ebf 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -257,6 +257,17 @@ public class LiteFlowChainELBuilder { return Boolean.FALSE; } + /** + * EL表达式校验,此方法校验失败会抛出异常 + * + * @param elStr EL表达式 + */ + public static void validateThrowEx(String elStr) { + // 移除注释 + elStr = ElRegexUtil.removeComments(elStr); + LiteFlowChainELBuilder.createChain().setEL(elStr); + } + public void build() { this.chain.setRouteItem(this.route); this.chain.setConditionList(this.conditionList); From 43fa9d47d3072d16f593fd27e29d39f077275f92 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Tue, 9 Jul 2024 10:41:25 +0800 Subject: [PATCH 2/3] =?UTF-8?q?enhancement=20#IABK5C=20=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=20EL=20=E8=A1=A8=E8=BE=BE=E5=BC=8F=EF=BC=8C=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=A4=B1=E8=B4=A5=E5=8E=9F=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index 88bbe5ebf..064c488b7 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -247,9 +247,7 @@ public class LiteFlowChainELBuilder { */ public static boolean validate(String elStr) { try { - // 移除注释 - elStr = ElRegexUtil.removeComments(elStr); - LiteFlowChainELBuilder.createChain().setEL(elStr); + validateThrowEx(elStr); return Boolean.TRUE; } catch (Exception e) { LOG.error("validate error",e); From ad158e626522aeb5849c8b5d4dca4c64f19224d1 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Wed, 24 Jul 2024 15:16:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?enhancement=20#IABK5C=20=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=20EL=20=E8=A1=A8=E8=BE=BE=E5=BC=8F=EF=BC=8C=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=A4=B1=E8=B4=A5=E5=8E=9F=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/LiteFlowChainELBuilder.java | 47 +++++++++++-------- .../common/entity/ValidationResp.java | 36 ++++++++++++++ 2 files changed, 63 insertions(+), 20 deletions(-) create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/common/entity/ValidationResp.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index 064c488b7..d74001be2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -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; @@ -240,30 +241,36 @@ public class LiteFlowChainELBuilder { return this; } - /** - * EL表达式校验 - * @param elStr EL表达式 - * @return true 校验成功 false 校验失败 - */ - public static boolean validate(String elStr) { - try { - validateThrowEx(elStr); - return Boolean.TRUE; - } catch (Exception e) { - LOG.error("validate error",e); - } - return Boolean.FALSE; - } - /** - * EL表达式校验,此方法校验失败会抛出异常 + * EL表达式校验,此方法已经过时,请使用 {@link LiteFlowChainELBuilder#validateWithEx(String)} * * @param elStr EL表达式 + * @return true 校验成功 false 校验失败 */ - public static void validateThrowEx(String elStr) { - // 移除注释 - elStr = ElRegexUtil.removeComments(elStr); - LiteFlowChainELBuilder.createChain().setEL(elStr); + @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() { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/common/entity/ValidationResp.java b/liteflow-core/src/main/java/com/yomahub/liteflow/common/entity/ValidationResp.java new file mode 100644 index 000000000..073dfe79f --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/common/entity/ValidationResp.java @@ -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; + } +}