mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
enhancement #ID1GUK 使WHILE表达式支持WHILE(true)这种表达方式
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
package com.yomahub.liteflow.builder.el.operator;
|
package com.yomahub.liteflow.builder.el.operator;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
|
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
|
||||||
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
|
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
|
||||||
|
import com.yomahub.liteflow.core.NodeBooleanComponent;
|
||||||
|
import com.yomahub.liteflow.core.NodeForComponent;
|
||||||
|
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||||
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.condition.WhileCondition;
|
import com.yomahub.liteflow.flow.element.condition.WhileCondition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,11 +22,30 @@ public class WhileOperator extends BaseOperator<WhileCondition> {
|
|||||||
public WhileCondition build(Object[] objects) throws Exception {
|
public WhileCondition build(Object[] objects) throws Exception {
|
||||||
OperatorHelper.checkObjectSizeEqOne(objects);
|
OperatorHelper.checkObjectSizeEqOne(objects);
|
||||||
|
|
||||||
OperatorHelper.checkObjMustBeBooleanTypeItem(objects[0]);
|
Object param = objects[0];
|
||||||
Executable whileItem = OperatorHelper.convert(objects[0], Executable.class);
|
|
||||||
|
|
||||||
WhileCondition whileCondition = new WhileCondition();
|
WhileCondition whileCondition = new WhileCondition();
|
||||||
whileCondition.setWhileItem(whileItem);
|
if (param instanceof Boolean) {
|
||||||
|
boolean booleanParam = OperatorHelper.convert(objects[0], Boolean.class);
|
||||||
|
Node node = new Node();
|
||||||
|
node.setType(NodeTypeEnum.BOOLEAN);
|
||||||
|
NodeBooleanComponent nodeBooleanComponent = new NodeBooleanComponent() {
|
||||||
|
@Override
|
||||||
|
public boolean processBoolean() {
|
||||||
|
return booleanParam;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
nodeBooleanComponent.setSelf(nodeBooleanComponent);
|
||||||
|
nodeBooleanComponent.setNodeId(StrUtil.format("LOOP_{}", booleanParam));
|
||||||
|
nodeBooleanComponent.setType(NodeTypeEnum.BOOLEAN);
|
||||||
|
node.setInstance(nodeBooleanComponent);
|
||||||
|
node.setId(nodeBooleanComponent.getNodeId());
|
||||||
|
whileCondition.setWhileItem(node);
|
||||||
|
}else{
|
||||||
|
OperatorHelper.checkObjMustBeBooleanTypeItem(param);
|
||||||
|
Executable whileItem = OperatorHelper.convert(param, Executable.class);
|
||||||
|
whileCondition.setWhileItem(whileItem);
|
||||||
|
}
|
||||||
return whileCondition;
|
return whileCondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,4 +118,11 @@ public class LoopELSpringbootTest extends BaseTest {
|
|||||||
Assertions.assertTrue(response.isSuccess());
|
Assertions.assertTrue(response.isSuccess());
|
||||||
Assertions.assertEquals("[000][001][010][011][020][021][100][101][110][111][120][121][200][201][210][211][220][221][300][301][310][311][320][321]", assertStr);
|
Assertions.assertEquals("[000][001][010][011][020][021][100][101][110][111][120][121][200][201][210][211][220][221][300][301][310][311][320][321]", assertStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WHILE(true)表达式的可行性验证
|
||||||
|
@Test
|
||||||
|
public void testLoop11() throws Exception {
|
||||||
|
LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg");
|
||||||
|
Assertions.assertTrue(response.isSuccess());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,4 +56,8 @@
|
|||||||
<chain name="chain10">
|
<chain name="chain10">
|
||||||
FOR(4).DO(FOR(3).DO(FOR(2).DO(c)));
|
FOR(4).DO(FOR(3).DO(FOR(2).DO(c)));
|
||||||
</chain>
|
</chain>
|
||||||
|
|
||||||
|
<chain name="chain11">
|
||||||
|
WHILE(true).DO(a).BREAK(y);
|
||||||
|
</chain>
|
||||||
</flow>
|
</flow>
|
||||||
Reference in New Issue
Block a user