mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
!167 #I69M1M 对上下文在脚本中的引用,支持自定义名称
Merge pull request !167 from wangtl/feature/I69M1M
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.yomahub.liteflow.context;
|
||||
|
||||
import com.yomahub.liteflow.annotation.AliasFor;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @description 用于标注上下文bean的别名,以便在脚本或者组件中通过别名来获取上下文对象
|
||||
* @since 2.9.7
|
||||
* @author Tingliang Wang
|
||||
* @createTime 2023/2/6 15:06
|
||||
* @update: [序号][日期YYYY-MM-DD] [更改人姓名][变更描述]
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
public @interface ContextBean {
|
||||
@AliasFor("name")
|
||||
String value() default "";
|
||||
|
||||
@AliasFor("value")
|
||||
String name() default "";
|
||||
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.yomahub.liteflow.script.jsr223;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.annotation.util.AnnoUtil;
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
import com.yomahub.liteflow.exception.LiteFlowException;
|
||||
import com.yomahub.liteflow.script.ScriptBeanManager;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
@@ -16,6 +18,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.script.*;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* JSR223 script engine的统一实现抽象类
|
||||
@@ -71,7 +74,13 @@ public abstract class JSR223ScriptExecutor implements ScriptExecutor {
|
||||
//比如你的自定义上下文为AbcContext,那么key就为:abcContext
|
||||
//这里不统一放一个map的原因是考虑到有些用户会调用上下文里的方法,而不是参数,所以脚本语言的绑定表里也是放多个上下文
|
||||
DataBus.getContextBeanList(wrap.getSlotIndex()).forEach(o -> {
|
||||
String key = StrUtil.lowerFirst(o.getClass().getSimpleName());
|
||||
ContextBean contextBean = AnnoUtil.getAnnotation(o.getClass(),ContextBean.class);
|
||||
String key;
|
||||
if(contextBean !=null && contextBean.value().trim().length()>0){
|
||||
key = contextBean.value();
|
||||
}else{
|
||||
key = StrUtil.lowerFirst(o.getClass().getSimpleName());
|
||||
}
|
||||
bindings.put(key, o);
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.yomahub.liteflow.script.graaljs;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.annotation.util.AnnoUtil;
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
import com.yomahub.liteflow.script.ScriptBeanManager;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.script.ScriptExecutor;
|
||||
@@ -57,7 +59,13 @@ public class GraalJavaScriptExecutor implements ScriptExecutor {
|
||||
//比如你的自定义上下文为AbcContext,那么key就为:abcContext
|
||||
//这里不统一放一个map的原因是考虑到有些用户会调用上下文里的方法,而不是参数,所以脚本语言的绑定表里也是放多个上下文
|
||||
DataBus.getContextBeanList(wrap.getSlotIndex()).forEach(o -> {
|
||||
String key = StrUtil.lowerFirst(o.getClass().getSimpleName());
|
||||
ContextBean contextBean = AnnoUtil.getAnnotation(o.getClass(),ContextBean.class);
|
||||
String key;
|
||||
if(contextBean !=null && contextBean.value().trim().length()>0){
|
||||
key = contextBean.value();
|
||||
}else{
|
||||
key = StrUtil.lowerFirst(o.getClass().getSimpleName());
|
||||
}
|
||||
bindings.putMember(key, o);
|
||||
});
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.ql.util.express.DefaultContext;
|
||||
import com.ql.util.express.ExpressLoader;
|
||||
import com.ql.util.express.ExpressRunner;
|
||||
import com.ql.util.express.InstructionSet;
|
||||
import com.yomahub.liteflow.annotation.util.AnnoUtil;
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
import com.yomahub.liteflow.script.ScriptBeanManager;
|
||||
import com.yomahub.liteflow.script.ScriptExecuteWrap;
|
||||
import com.yomahub.liteflow.slot.DataBus;
|
||||
@@ -69,7 +71,13 @@ public class QLExpressScriptExecutor implements ScriptExecutor {
|
||||
//比如你的自定义上下文为AbcContext,那么key就为:abcContext
|
||||
//这里不统一放一个map的原因是考虑到有些用户会调用上下文里的方法,而不是参数,所以脚本语言的绑定表里也是放多个上下文
|
||||
DataBus.getContextBeanList(wrap.getSlotIndex()).forEach(o -> {
|
||||
String key = StrUtil.lowerFirst(o.getClass().getSimpleName());
|
||||
ContextBean contextBean = AnnoUtil.getAnnotation(o.getClass(),ContextBean.class);
|
||||
String key;
|
||||
if(contextBean !=null && contextBean.value().trim().length()>0){
|
||||
key = contextBean.value();
|
||||
}else{
|
||||
key = StrUtil.lowerFirst(o.getClass().getSimpleName());
|
||||
}
|
||||
context.put(key, o);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.yomahub.liteflow.test.script.graaljs.contextbean;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.script.graaljs.contextbean.bean.CheckContext;
|
||||
import com.yomahub.liteflow.test.script.graaljs.contextbean.bean.Order2Context;
|
||||
import com.yomahub.liteflow.test.script.graaljs.contextbean.bean.OrderContext;
|
||||
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;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/contextbean/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowScriptContextbeanGraaljsTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.script.graaljs.contextbean.cmp","com.yomahub.liteflow.test.script.graaljs.contextbean.bean"})
|
||||
public class LiteFlowScriptContextbeanGraaljsTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void testContextBean1() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
OrderContext orderContext = response.getContextBean(OrderContext.class);
|
||||
CheckContext checkContext = response.getContextBean(CheckContext.class);
|
||||
Order2Context order2Context = response.getContextBean(Order2Context.class);
|
||||
Assert.assertEquals("order1", orderContext.getOrderNo());
|
||||
Assert.assertEquals("d", checkContext.getSign());
|
||||
Assert.assertEquals("order2", order2Context.getOrderNo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextBean2() throws Exception{
|
||||
OrderContext orderContext = new OrderContext();
|
||||
orderContext.setOrderNo("order1");
|
||||
CheckContext checkContext = new CheckContext();
|
||||
checkContext.setSign("sign1");
|
||||
Order2Context orderContext2 = new Order2Context();
|
||||
orderContext2.setOrderNo("order2");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yomahub.liteflow.test.script.graaljs.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
@ContextBean
|
||||
public class CheckContext {
|
||||
|
||||
private String sign;
|
||||
|
||||
private int randomId;
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public int getRandomId() {
|
||||
return randomId;
|
||||
}
|
||||
|
||||
public void setRandomId(int randomId) {
|
||||
this.randomId = randomId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yomahub.liteflow.test.script.graaljs.contextbean.bean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Order2Context {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.yomahub.liteflow.test.script.graaljs.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ContextBean("order")
|
||||
public class OrderContext {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.script.graaljs.contextbean.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("ACmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -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.graaljs.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.graaljs.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=contextbean/flow.xml
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
|
||||
<nodes>
|
||||
<node id="d" type="script" language="js">
|
||||
<![CDATA[
|
||||
order.setOrderNo("order1")
|
||||
checkContext.setSign(_meta.get("nodeId"))
|
||||
order2Context.setOrderNo("order2")
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="e" type="script" language="js">
|
||||
<![CDATA[
|
||||
var orderNo = order.getOrderNo()
|
||||
var sign = checkContext.getSign()
|
||||
var orderNo2 = order2Context.getOrderNo()
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(a,b,c,d);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(a,b,c,e);
|
||||
</chain>
|
||||
|
||||
</flow>
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.yomahub.liteflow.test.script.groovy.contextbean;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.script.groovy.contextbean.bean.CheckContext;
|
||||
import com.yomahub.liteflow.test.script.groovy.contextbean.bean.Order2Context;
|
||||
import com.yomahub.liteflow.test.script.groovy.contextbean.bean.OrderContext;
|
||||
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;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/contextbean/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowScriptContextbeanGroovyELTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.script.groovy.contextbean.cmp","com.yomahub.liteflow.test.script.groovy.contextbean.bean"})
|
||||
public class LiteFlowScriptContextbeanGroovyELTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void testContextBean1() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
OrderContext orderContext = response.getContextBean(OrderContext.class);
|
||||
CheckContext checkContext = response.getContextBean(CheckContext.class);
|
||||
Order2Context order2Context = response.getContextBean(Order2Context.class);
|
||||
Assert.assertEquals("order1", orderContext.getOrderNo());
|
||||
Assert.assertEquals("sign1", checkContext.getSign());
|
||||
Assert.assertEquals("order2", order2Context.getOrderNo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextBean2() throws Exception{
|
||||
OrderContext orderContext = new OrderContext();
|
||||
orderContext.setOrderNo("order1");
|
||||
CheckContext checkContext = new CheckContext();
|
||||
checkContext.setSign("sign1");
|
||||
Order2Context orderContext2 = new Order2Context();
|
||||
orderContext2.setOrderNo("order2");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yomahub.liteflow.test.script.groovy.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
@ContextBean
|
||||
public class CheckContext {
|
||||
|
||||
private String sign;
|
||||
|
||||
private int randomId;
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public int getRandomId() {
|
||||
return randomId;
|
||||
}
|
||||
|
||||
public void setRandomId(int randomId) {
|
||||
this.randomId = randomId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yomahub.liteflow.test.script.groovy.contextbean.bean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Order2Context {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.yomahub.liteflow.test.script.groovy.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ContextBean("order")
|
||||
public class OrderContext {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* <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.contextbean.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("ACmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -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.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=contextbean/flow.xml
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
|
||||
<nodes>
|
||||
<node id="d" type="script" language="groovy">
|
||||
<![CDATA[
|
||||
order.setOrderNo("order1")
|
||||
checkContext.setSign("sign1")
|
||||
order2Context.setOrderNo("order2")
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="e" type="script" language="groovy">
|
||||
<![CDATA[
|
||||
def orderNo = order.getOrderNo()
|
||||
println orderNo
|
||||
def sign = checkContext.getSign()
|
||||
println sign
|
||||
def orderNo2 = order2Context.getOrderNo()
|
||||
println orderNo2
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(a,b,c,d);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(a,b,c,e);
|
||||
</chain>
|
||||
|
||||
</flow>
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.yomahub.liteflow.test.script.javascript.contextbean;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.script.javascript.contextbean.bean.CheckContext;
|
||||
import com.yomahub.liteflow.test.script.javascript.contextbean.bean.Order2Context;
|
||||
import com.yomahub.liteflow.test.script.javascript.contextbean.bean.OrderContext;
|
||||
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;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/contextbean/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowScriptContextbeanJavaScriptTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.script.javascript.contextbean.cmp","com.yomahub.liteflow.test.script.javascript.contextbean.bean"})
|
||||
public class LiteFlowScriptContextbeanJavaScriptTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void testContextBean1() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
OrderContext orderContext = response.getContextBean(OrderContext.class);
|
||||
CheckContext checkContext = response.getContextBean(CheckContext.class);
|
||||
Order2Context order2Context = response.getContextBean(Order2Context.class);
|
||||
Assert.assertEquals("order1", orderContext.getOrderNo());
|
||||
Assert.assertEquals("sign1", checkContext.getSign());
|
||||
Assert.assertEquals("order2", order2Context.getOrderNo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextBean2() throws Exception{
|
||||
OrderContext orderContext = new OrderContext();
|
||||
orderContext.setOrderNo("order1");
|
||||
CheckContext checkContext = new CheckContext();
|
||||
checkContext.setSign("sign1");
|
||||
Order2Context orderContext2 = new Order2Context();
|
||||
orderContext2.setOrderNo("order2");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yomahub.liteflow.test.script.javascript.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
@ContextBean
|
||||
public class CheckContext {
|
||||
|
||||
private String sign;
|
||||
|
||||
private int randomId;
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public int getRandomId() {
|
||||
return randomId;
|
||||
}
|
||||
|
||||
public void setRandomId(int randomId) {
|
||||
this.randomId = randomId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yomahub.liteflow.test.script.javascript.contextbean.bean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Order2Context {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.yomahub.liteflow.test.script.javascript.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ContextBean("order")
|
||||
public class OrderContext {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.script.javascript.contextbean.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("ACmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -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.javascript.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.javascript.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=contextbean/flow.xml
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
|
||||
<nodes>
|
||||
<node id="d" type="script" language="js">
|
||||
<![CDATA[
|
||||
order.setOrderNo("order1")
|
||||
checkContext.setSign("sign1")
|
||||
order2Context.setOrderNo("order2")
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="e" type="script" language="js">
|
||||
<![CDATA[
|
||||
var orderNo = order.getOrderNo()
|
||||
var sign = checkContext.getSign()
|
||||
var orderNo2 = order2Context.getOrderNo()
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(a,b,c,d);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(a,b,c,e);
|
||||
</chain>
|
||||
|
||||
</flow>
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.yomahub.liteflow.test.script.lua.contextbean;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.script.lua.contextbean.bean.CheckContext;
|
||||
import com.yomahub.liteflow.test.script.lua.contextbean.bean.Order2Context;
|
||||
import com.yomahub.liteflow.test.script.lua.contextbean.bean.OrderContext;
|
||||
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;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/contextbean/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowScriptContextbeanLuaTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.script.lua.contextbean.cmp","com.yomahub.liteflow.test.script.lua.contextbean.bean"})
|
||||
public class LiteFlowScriptContextbeanLuaTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void testContextBean1() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
OrderContext orderContext = response.getContextBean(OrderContext.class);
|
||||
CheckContext checkContext = response.getContextBean(CheckContext.class);
|
||||
Order2Context order2Context = response.getContextBean(Order2Context.class);
|
||||
Assert.assertEquals(30, orderContext.getOrderType());
|
||||
Assert.assertEquals("d", checkContext.getSign());
|
||||
Assert.assertEquals("order2", order2Context.getOrderNo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextBean2() throws Exception{
|
||||
OrderContext orderContext = new OrderContext();
|
||||
orderContext.setOrderNo("order1");
|
||||
CheckContext checkContext = new CheckContext();
|
||||
checkContext.setSign("sign1");
|
||||
Order2Context orderContext2 = new Order2Context();
|
||||
orderContext2.setOrderNo("order2");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yomahub.liteflow.test.script.lua.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
@ContextBean
|
||||
public class CheckContext {
|
||||
|
||||
private String sign;
|
||||
|
||||
private int randomId;
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public int getRandomId() {
|
||||
return randomId;
|
||||
}
|
||||
|
||||
public void setRandomId(int randomId) {
|
||||
this.randomId = randomId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yomahub.liteflow.test.script.lua.contextbean.bean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Order2Context {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.yomahub.liteflow.test.script.lua.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ContextBean("order")
|
||||
public class OrderContext {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.script.lua.contextbean.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("ACmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -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.lua.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.lua.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=contextbean/flow.xml
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
|
||||
<nodes>
|
||||
<node id="d" type="script">
|
||||
<![CDATA[
|
||||
local a=6
|
||||
local b=10
|
||||
if(a>5) then
|
||||
b=5
|
||||
else
|
||||
b=2
|
||||
end
|
||||
order:setOrderType(a*b)
|
||||
checkContext:setSign(_meta:get("nodeId"))
|
||||
order2Context:setOrderNo("order2")
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="e" type="script">
|
||||
<![CDATA[
|
||||
local orderNo = order:getOrderNo()
|
||||
print(orderNo)
|
||||
local sign = checkContext:getSign()
|
||||
print(sign)
|
||||
local orderNo2 = order2Context:getOrderNo()
|
||||
print(orderNo2)
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(a,b,c,d);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(a,b,c,e);
|
||||
</chain>
|
||||
|
||||
</flow>
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.yomahub.liteflow.test.script.python.contextbean;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.script.python.contextbean.bean.CheckContext;
|
||||
import com.yomahub.liteflow.test.script.python.contextbean.bean.Order2Context;
|
||||
import com.yomahub.liteflow.test.script.python.contextbean.bean.OrderContext;
|
||||
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;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/contextbean/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowScriptContextbeanPythonTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.script.python.contextbean.cmp","com.yomahub.liteflow.test.script.python.contextbean.bean"})
|
||||
public class LiteFlowScriptContextbeanPythonTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void testContextBean1() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
OrderContext orderContext = response.getContextBean(OrderContext.class);
|
||||
CheckContext checkContext = response.getContextBean(CheckContext.class);
|
||||
Order2Context order2Context = response.getContextBean(Order2Context.class);
|
||||
Assert.assertEquals(30, orderContext.getOrderType());
|
||||
Assert.assertEquals("d", checkContext.getSign());
|
||||
Assert.assertEquals("order2", order2Context.getOrderNo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextBean2() throws Exception{
|
||||
OrderContext orderContext = new OrderContext();
|
||||
orderContext.setOrderNo("order1");
|
||||
CheckContext checkContext = new CheckContext();
|
||||
checkContext.setSign("sign1");
|
||||
Order2Context orderContext2 = new Order2Context();
|
||||
orderContext2.setOrderNo("order2");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yomahub.liteflow.test.script.python.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
@ContextBean
|
||||
public class CheckContext {
|
||||
|
||||
private String sign;
|
||||
|
||||
private int randomId;
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public int getRandomId() {
|
||||
return randomId;
|
||||
}
|
||||
|
||||
public void setRandomId(int randomId) {
|
||||
this.randomId = randomId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yomahub.liteflow.test.script.python.contextbean.bean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Order2Context {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.yomahub.liteflow.test.script.python.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ContextBean("order")
|
||||
public class OrderContext {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.script.python.contextbean.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("ACmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -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.python.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.python.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=contextbean/flow.xml
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
|
||||
<nodes>
|
||||
<node id="d" type="script">
|
||||
<![CDATA[
|
||||
a=6
|
||||
b=10
|
||||
if a>5:
|
||||
b=5
|
||||
print 'hello'
|
||||
else:
|
||||
print 'hi'
|
||||
order.setOrderType(a*b)
|
||||
checkContext.setSign(_meta.get("nodeId"))
|
||||
order2Context.setOrderNo("order2")
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="e" type="script">
|
||||
<![CDATA[
|
||||
orderNo = order.getOrderNo()
|
||||
print orderNo
|
||||
sign = checkContext.getSign()
|
||||
print sign
|
||||
orderNo2 = order2Context.getOrderNo()
|
||||
print orderNo2
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(a,b,c,d);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(a,b,c,e);
|
||||
</chain>
|
||||
|
||||
</flow>
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.yomahub.liteflow.test.script.qlexpress.contextbean;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.script.qlexpress.contextbean.bean.CheckContext;
|
||||
import com.yomahub.liteflow.test.script.qlexpress.contextbean.bean.Order2Context;
|
||||
import com.yomahub.liteflow.test.script.qlexpress.contextbean.bean.OrderContext;
|
||||
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;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/contextbean/application.properties")
|
||||
@SpringBootTest(classes = LiteFlowScriptContextbeanQLExpressTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.script.qlexpress.contextbean.cmp","com.yomahub.liteflow.test.script.qlexpress.contextbean.bean"})
|
||||
public class LiteFlowScriptContextbeanQLExpressTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void testContextBean1() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg", OrderContext.class, CheckContext.class, Order2Context.class);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
OrderContext orderContext = response.getContextBean(OrderContext.class);
|
||||
CheckContext checkContext = response.getContextBean(CheckContext.class);
|
||||
Order2Context order2Context = response.getContextBean(Order2Context.class);
|
||||
Assert.assertEquals(6, orderContext.getOrderType());
|
||||
Assert.assertEquals("d", checkContext.getSign());
|
||||
Assert.assertEquals("order2", order2Context.getOrderNo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextBean2() throws Exception{
|
||||
OrderContext orderContext = new OrderContext();
|
||||
orderContext.setOrderNo("order1");
|
||||
CheckContext checkContext = new CheckContext();
|
||||
checkContext.setSign("sign1");
|
||||
Order2Context orderContext2 = new Order2Context();
|
||||
orderContext2.setOrderNo("order2");
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", null, orderContext, checkContext, orderContext2);
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yomahub.liteflow.test.script.qlexpress.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
@ContextBean
|
||||
public class CheckContext {
|
||||
|
||||
private String sign;
|
||||
|
||||
private int randomId;
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public int getRandomId() {
|
||||
return randomId;
|
||||
}
|
||||
|
||||
public void setRandomId(int randomId) {
|
||||
this.randomId = randomId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yomahub.liteflow.test.script.qlexpress.contextbean.bean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Order2Context {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.yomahub.liteflow.test.script.qlexpress.contextbean.bean;
|
||||
|
||||
import com.yomahub.liteflow.context.ContextBean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ContextBean("order")
|
||||
public class OrderContext {
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private int orderType;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public int getOrderType() {
|
||||
return orderType;
|
||||
}
|
||||
|
||||
public void setOrderType(int orderType) {
|
||||
this.orderType = orderType;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.script.qlexpress.contextbean.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("ACmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -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.qlexpress.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.qlexpress.contextbean.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=contextbean/flow.xml
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
|
||||
<nodes>
|
||||
<node id="d" type="script">
|
||||
<![CDATA[
|
||||
a=3;
|
||||
b=2;
|
||||
order.setOrderType(a*b);
|
||||
id = _meta.get("nodeId");
|
||||
checkContext.setSign(id);
|
||||
order2Context.setOrderNo("order2");
|
||||
]]>
|
||||
</node>
|
||||
|
||||
<node id="e" type="script">
|
||||
<![CDATA[
|
||||
order = order.getOrderNo();
|
||||
System.out.println(order);
|
||||
sign = checkContext.getSign();
|
||||
System.out.println(sign);
|
||||
orderNo2 = order2Context.getOrderNo();
|
||||
System.out.println(orderNo2);
|
||||
]]>
|
||||
</node>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1">
|
||||
THEN(a,b,c,d);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(a,b,c,e);
|
||||
</chain>
|
||||
|
||||
</flow>
|
||||
Reference in New Issue
Block a user