mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
enhancement #I679UX 组件参数设入json,支持在脚本组件中点操作符取到
This commit is contained in:
@@ -3,6 +3,8 @@ package com.yomahub.liteflow.core;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 脚本BREAK节点
|
||||
* @author Bryan.Zhang
|
||||
@@ -16,7 +18,7 @@ public class ScriptBreakComponent extends NodeBreakComponent implements ScriptCo
|
||||
wrap.setNodeId(this.getNodeId());
|
||||
wrap.setSlotIndex(this.getSlotIndex());
|
||||
wrap.setTag(this.getTag());
|
||||
wrap.setCmpData(this.getCmpData(Object.class));
|
||||
wrap.setCmpData(this.getCmpData(Map.class));
|
||||
return (boolean) ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(wrap);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 脚本组件类
|
||||
* @author Bryan.Zhang
|
||||
@@ -21,7 +23,7 @@ public class ScriptCommonComponent extends NodeComponent implements ScriptCompon
|
||||
wrap.setNodeId(this.getNodeId());
|
||||
wrap.setSlotIndex(this.getSlotIndex());
|
||||
wrap.setTag(this.getTag());
|
||||
wrap.setCmpData(this.getCmpData(Object.class));
|
||||
wrap.setCmpData(this.getCmpData(Map.class));
|
||||
ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(wrap);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.yomahub.liteflow.core;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 脚本FOR节点
|
||||
* @author Bryan.Zhang
|
||||
@@ -16,7 +18,7 @@ public class ScriptForComponent extends NodeForComponent implements ScriptCompon
|
||||
wrap.setNodeId(this.getNodeId());
|
||||
wrap.setSlotIndex(this.getSlotIndex());
|
||||
wrap.setTag(this.getTag());
|
||||
wrap.setCmpData(this.getCmpData(Object.class));
|
||||
wrap.setCmpData(this.getCmpData(Map.class));
|
||||
return (int) ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(wrap);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.yomahub.liteflow.core;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 脚本IF节点
|
||||
* @author Bryan.Zhang
|
||||
@@ -16,7 +18,7 @@ public class ScriptIfComponent extends NodeIfComponent implements ScriptComponen
|
||||
wrap.setNodeId(this.getNodeId());
|
||||
wrap.setSlotIndex(this.getSlotIndex());
|
||||
wrap.setTag(this.getTag());
|
||||
wrap.setCmpData(this.getCmpData(Object.class));
|
||||
wrap.setCmpData(this.getCmpData(Map.class));
|
||||
return (boolean)ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(wrap);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.yomahub.liteflow.core;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 脚本条件节点
|
||||
* @author Bryan.Zhang
|
||||
@@ -17,7 +19,7 @@ public class ScriptSwitchComponent extends NodeSwitchComponent implements Script
|
||||
wrap.setNodeId(this.getNodeId());
|
||||
wrap.setSlotIndex(this.getSlotIndex());
|
||||
wrap.setTag(this.getTag());
|
||||
wrap.setCmpData(this.getCmpData(Object.class));
|
||||
wrap.setCmpData(this.getCmpData(Map.class));
|
||||
return (String)ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(wrap);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.yomahub.liteflow.core;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.ScriptExecutorFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 脚本WHILE节点
|
||||
* @author Bryan.Zhang
|
||||
@@ -17,7 +19,7 @@ public class ScriptWhileComponent extends NodeWhileComponent implements ScriptCo
|
||||
wrap.setNodeId(this.getNodeId());
|
||||
wrap.setSlotIndex(this.getSlotIndex());
|
||||
wrap.setTag(this.getTag());
|
||||
wrap.setCmpData(this.getCmpData(Object.class));
|
||||
wrap.setCmpData(this.getCmpData(Map.class));
|
||||
return (boolean) ScriptExecutorFactory.loadInstance().getScriptExecutor().execute(wrap);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.yomahub.liteflow.test.script.groovy.cmpdata;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* springboot环境EL常规的例子测试
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/cmpdata/application.properties")
|
||||
@SpringBootTest(classes = CmpDataGroovyELTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.script.groovy.cmpdata.cmp"})
|
||||
public class CmpDataGroovyELTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
//最简单的情况
|
||||
@Test
|
||||
public void testCmpData1() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("1995-10-01", context.getData("s1"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.script.groovy.cmpdata.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("a")
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println(this.getCmpData(String.class));
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=cmpdata/flow.xml
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE flow PUBLIC "liteflow" "liteflow.dtd">
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="s1" type="script" language="groovy">
|
||||
defaultContext.setData("s1", _meta.cmpData.birth);
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
cmpData = '{"name":"jack","age":27,"birth":"1995-10-01"}';
|
||||
|
||||
THEN(
|
||||
s1.data(cmpData),
|
||||
a
|
||||
);
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user