初步完成 liteflow-solon-plugin 适配

This commit is contained in:
noear
2022-12-21 19:06:01 +08:00
parent 73982435b3
commit 77d2c12485
4 changed files with 84 additions and 2 deletions

View File

@@ -0,0 +1,70 @@
package com.yomahub.liteflow.solon;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.slot.Slot;
import org.noear.solon.core.BeanWrap;
import java.lang.reflect.Method;
/**
* @author noear
* @since 1.11
*/
public class NodeComponentOfMethod extends NodeComponent {
final BeanWrap beanWrap;
final Method method;
final LiteFlowMethodEnum methodEnum;
public NodeComponentOfMethod(BeanWrap beanWrap, Method method, LiteFlowMethodEnum methodEnum) {
this.beanWrap = beanWrap;
this.method = method;
this.methodEnum = methodEnum;
}
@Override
public void process() throws Exception {
if(methodEnum != LiteFlowMethodEnum.PROCESS){
return;
}
if (method.getParameterCount() == 0) {
method.invoke(beanWrap.get());
} else if (method.getParameterCount() == 1) {
method.invoke(beanWrap.get(), this);
} else {
String methodFullName = beanWrap.clz().getName() + "::" + method.getName();
throw new RuntimeException("NodeComponent method parameter cannot be more than one: " + methodFullName);
}
}
@Override
public <T> void beforeProcess(String nodeId, Slot slot) {
if(methodEnum != LiteFlowMethodEnum.BEFORE_PROCESS){
return;
}
}
@Override
public <T> void afterProcess(String nodeId, Slot slot) {
if(methodEnum != LiteFlowMethodEnum.AFTER_PROCESS){
return;
}
}
@Override
public void onError() throws Exception {
if(methodEnum != LiteFlowMethodEnum.ON_ERROR){
return;
}
}
@Override
public void onSuccess() throws Exception {
if(methodEnum != LiteFlowMethodEnum.ON_SUCCESS){
return;
}
}
}

View File

@@ -1,9 +1,11 @@
package com.yomahub.liteflow.solon.integration;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.solon.LiteflowProperty;
import com.yomahub.liteflow.solon.NodeComponentOfMethod;
import org.noear.solon.Utils;
import org.noear.solon.core.AopContext;
import org.noear.solon.core.Plugin;
@@ -40,6 +42,15 @@ public class XPluginImpl implements Plugin {
FlowBus.addSpringScanNode(bw.name(), bw.raw());
});
context.beanExtractorAdd(LiteflowMethod.class, (bw, method, anno) -> {
NodeComponent node1 = new NodeComponentOfMethod(bw, method, anno.value());
String nodeId = Utils.annoAlias(anno.nodeId(), bw.name());
node1.setNodeId(nodeId);
node1.setType(anno.nodeType());
FlowBus.addSpringScanNode(bw.name(), node1);
});
context.beanBuilderAdd(LiteflowComponent.class, (clz, bw, anno) -> {
if(NodeComponent.class.isAssignableFrom(clz)) {
NodeComponent node1 = bw.raw();
@@ -50,6 +61,8 @@ public class XPluginImpl implements Plugin {
node1.setName(name1);
FlowBus.addSpringScanNode(node1.getNodeId(), node1);
}else{
context.beanExtract(bw); //尝试提取 LiteflowMethod 函数
}
});

View File

@@ -16,7 +16,6 @@ import org.noear.solon.test.annotation.TestPropertySource;
*/
@RunWith(SolonJUnit4ClassRunner.class)
@TestPropertySource(value = "classpath:/requestId/application.properties")
@Import(scanPackages = {"com.yomahub.liteflow.test.requestId.cmp"})
public class LiteflowRequestIdELSpringbootTest extends BaseTest {
@Inject

View File

@@ -65,7 +65,7 @@
<aspectjweaver.version>1.8.13</aspectjweaver.version>
<logback-classic.version>1.2.3</logback-classic.version>
<solon.version>1.11.7</solon.version>
<solon.version>1.11.7-M1</solon.version>
<netty.version>4.1.84.Final</netty.version>
<guava.version>31.1-jre</guava.version>