|
@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
|
import com.yomahub.liteflow.enums.ConditionTypeEnum;
|
|
import com.yomahub.liteflow.enums.ConditionTypeEnum;
|
|
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
|
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
|
import com.yomahub.liteflow.exception.*;
|
|
import com.yomahub.liteflow.exception.*;
|
|
|
|
+import com.yomahub.liteflow.flow.element.Condition;
|
|
import com.yomahub.liteflow.flow.element.Executable;
|
|
import com.yomahub.liteflow.flow.element.Executable;
|
|
import com.yomahub.liteflow.flow.element.Node;
|
|
import com.yomahub.liteflow.flow.element.Node;
|
|
import com.yomahub.liteflow.slot.DataBus;
|
|
import com.yomahub.liteflow.slot.DataBus;
|
|
@@ -22,67 +23,63 @@ public class IfCondition extends Condition {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void executeCondition(Integer slotIndex) throws Exception {
|
|
public void executeCondition(Integer slotIndex) throws Exception {
|
|
- if (ListUtil.toList(NodeTypeEnum.IF, NodeTypeEnum.IF_SCRIPT).contains(getIfNode().getType())) {
|
|
|
|
- // 先去判断isAccess方法,如果isAccess方法都返回false,整个IF表达式不执行
|
|
|
|
- if (!this.getIfNode().isAccess(slotIndex)) {
|
|
|
|
- return;
|
|
|
|
|
|
+ Executable ifItem = this.getIfItem();
|
|
|
|
+
|
|
|
|
+ // 先去判断isAccess方法,如果isAccess方法都返回false,整个IF表达式不执行
|
|
|
|
+ if (!ifItem.isAccess(slotIndex)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 先执行IF节点
|
|
|
|
+ ifItem.setCurrChainId(this.getCurrChainId());
|
|
|
|
+ ifItem.execute(slotIndex);
|
|
|
|
+
|
|
|
|
+ // 拿到If执行过的结果
|
|
|
|
+ boolean ifResult = ifItem.getItemResultMetaValue(slotIndex);
|
|
|
|
+
|
|
|
|
+ Executable trueCaseExecutableItem = this.getTrueCaseExecutableItem();
|
|
|
|
+ Executable falseCaseExecutableItem = this.getFalseCaseExecutableItem();
|
|
|
|
+
|
|
|
|
+ Slot slot = DataBus.getSlot(slotIndex);
|
|
|
|
+
|
|
|
|
+ if (ifResult) {
|
|
|
|
+ // trueCaseExecutableItem这个不能为空,否则执行什么呢
|
|
|
|
+ if (ObjectUtil.isNull(trueCaseExecutableItem)) {
|
|
|
|
+ String errorInfo = StrUtil.format("[{}]:no if-true node found for the component[{}]",
|
|
|
|
+ slot.getRequestId(), ifItem.getExecuteId());
|
|
|
|
+ throw new NoIfTrueNodeException(errorInfo);
|
|
}
|
|
}
|
|
|
|
|
|
- // 先执行IF节点
|
|
|
|
- this.getIfNode().setCurrChainId(this.getCurrChainId());
|
|
|
|
- this.getIfNode().execute(slotIndex);
|
|
|
|
-
|
|
|
|
- Slot slot = DataBus.getSlot(slotIndex);
|
|
|
|
- // 这里可能会有spring代理过的bean,所以拿到user原始的class
|
|
|
|
- Class<?> originalClass = LiteFlowProxyUtil.getUserClass(this.getIfNode().getInstance().getClass());
|
|
|
|
- // 拿到If执行过的结果
|
|
|
|
- boolean ifResult = slot.getIfResult(originalClass.getName());
|
|
|
|
-
|
|
|
|
- Executable trueCaseExecutableItem = this.getTrueCaseExecutableItem();
|
|
|
|
- Executable falseCaseExecutableItem = this.getFalseCaseExecutableItem();
|
|
|
|
-
|
|
|
|
- if (ifResult) {
|
|
|
|
- // trueCaseExecutableItem这个不能为空,否则执行什么呢
|
|
|
|
- if (ObjectUtil.isNull(trueCaseExecutableItem)) {
|
|
|
|
- String errorInfo = StrUtil.format("[{}]:no if-true node found for the component[{}]",
|
|
|
|
- slot.getRequestId(), this.getIfNode().getInstance().getDisplayName());
|
|
|
|
- throw new NoIfTrueNodeException(errorInfo);
|
|
|
|
- }
|
|
|
|
|
|
+ // trueCaseExecutableItem 不能为前置或者后置组件
|
|
|
|
+ if (trueCaseExecutableItem instanceof PreCondition
|
|
|
|
+ || trueCaseExecutableItem instanceof FinallyCondition) {
|
|
|
|
+ String errorInfo = StrUtil.format(
|
|
|
|
+ "[{}]:if component[{}] error, if true node cannot be pre or finally", slot.getRequestId(),
|
|
|
|
+ ifItem.getExecuteId());
|
|
|
|
+ throw new IfTargetCannotBePreOrFinallyException(errorInfo);
|
|
|
|
+ }
|
|
|
|
|
|
- // trueCaseExecutableItem 不能为前置或者后置组件
|
|
|
|
- if (trueCaseExecutableItem instanceof PreCondition
|
|
|
|
- || trueCaseExecutableItem instanceof FinallyCondition) {
|
|
|
|
|
|
+ // 执行trueCaseExecutableItem
|
|
|
|
+ trueCaseExecutableItem.setCurrChainId(this.getCurrChainId());
|
|
|
|
+ trueCaseExecutableItem.execute(slotIndex);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ // falseCaseExecutableItem可以为null,但是不为null时就执行否的情况
|
|
|
|
+ if (ObjectUtil.isNotNull(falseCaseExecutableItem)) {
|
|
|
|
+ // falseCaseExecutableItem 不能为前置或者后置组件
|
|
|
|
+ if (falseCaseExecutableItem instanceof PreCondition
|
|
|
|
+ || falseCaseExecutableItem instanceof FinallyCondition) {
|
|
String errorInfo = StrUtil.format(
|
|
String errorInfo = StrUtil.format(
|
|
- "[{}]:if component[{}] error, if true node cannot be pre or finally", slot.getRequestId(),
|
|
|
|
- this.getIfNode().getInstance().getDisplayName());
|
|
|
|
|
|
+ "[{}]:if component[{}] error, if true node cannot be pre or finally",
|
|
|
|
+ slot.getRequestId(), ifItem.getExecuteId());
|
|
throw new IfTargetCannotBePreOrFinallyException(errorInfo);
|
|
throw new IfTargetCannotBePreOrFinallyException(errorInfo);
|
|
}
|
|
}
|
|
|
|
|
|
- // 执行trueCaseExecutableItem
|
|
|
|
- trueCaseExecutableItem.setCurrChainId(this.getCurrChainId());
|
|
|
|
- trueCaseExecutableItem.execute(slotIndex);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- // falseCaseExecutableItem可以为null,但是不为null时就执行否的情况
|
|
|
|
- if (ObjectUtil.isNotNull(falseCaseExecutableItem)) {
|
|
|
|
- // falseCaseExecutableItem 不能为前置或者后置组件
|
|
|
|
- if (falseCaseExecutableItem instanceof PreCondition
|
|
|
|
- || falseCaseExecutableItem instanceof FinallyCondition) {
|
|
|
|
- String errorInfo = StrUtil.format(
|
|
|
|
- "[{}]:if component[{}] error, if true node cannot be pre or finally",
|
|
|
|
- slot.getRequestId(), this.getIfNode().getInstance().getDisplayName());
|
|
|
|
- throw new IfTargetCannotBePreOrFinallyException(errorInfo);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 执行falseCaseExecutableItem
|
|
|
|
- falseCaseExecutableItem.setCurrChainId(this.getCurrChainId());
|
|
|
|
- falseCaseExecutableItem.execute(slotIndex);
|
|
|
|
- }
|
|
|
|
|
|
+ // 执行falseCaseExecutableItem
|
|
|
|
+ falseCaseExecutableItem.setCurrChainId(this.getCurrChainId());
|
|
|
|
+ falseCaseExecutableItem.execute(slotIndex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- throw new IfTypeErrorException("if instance must be NodeIfComponent");
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -106,12 +103,11 @@ public class IfCondition extends Condition {
|
|
this.addExecutable(ConditionKey.IF_FALSE_CASE_KEY, falseCaseExecutableItem);
|
|
this.addExecutable(ConditionKey.IF_FALSE_CASE_KEY, falseCaseExecutableItem);
|
|
}
|
|
}
|
|
|
|
|
|
- public void setIfNode(Node ifNode) {
|
|
|
|
|
|
+ public void setIfItem(Executable ifNode) {
|
|
this.addExecutable(ConditionKey.IF_KEY, ifNode);
|
|
this.addExecutable(ConditionKey.IF_KEY, ifNode);
|
|
}
|
|
}
|
|
|
|
|
|
- public Node getIfNode() {
|
|
|
|
- return (Node) this.getExecutableOne(ConditionKey.IF_KEY);
|
|
|
|
|
|
+ public Executable getIfItem() {
|
|
|
|
+ return this.getExecutableOne(ConditionKey.IF_KEY);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|