everywhere.z 5 mesi fa
parent
commit
23cbf924be

+ 45 - 48
liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/DeclComponentProxy.java

@@ -111,7 +111,7 @@ public class DeclComponentProxy {
 
     public class AopInvocationHandler implements InvocationHandler {
 
-        private DeclWarpBean declWarpBean;
+        private final DeclWarpBean declWarpBean;
 
         public AopInvocationHandler(DeclWarpBean declWarpBean) {
             this.declWarpBean = declWarpBean;
@@ -162,60 +162,57 @@ public class DeclComponentProxy {
     private Object[] loadMethodParameter(Object proxy, MethodWrapBean methodWrapBean, Object[] args){
         NodeComponent thisNodeComponent = (NodeComponent) proxy;
 
-        return IntStream.range(0, methodWrapBean.getParameterWrapBeanList().size()).boxed().map(new Function<Integer, Object>() {
-            @Override
-            public Object apply(Integer index) {
-                ParameterWrapBean parameterWrapBean = methodWrapBean.getParameterWrapBeanList().get(index);
+        return IntStream.range(0, methodWrapBean.getParameterWrapBeanList().size()).boxed().map(index -> {
+            ParameterWrapBean parameterWrapBean = methodWrapBean.getParameterWrapBeanList().get(index);
 
-                // 如果参数是NodeComponent,那就返回proxy本身
-                if (parameterWrapBean.getParameterType().isAssignableFrom(NodeComponent.class)) {
-                    return proxy;
-                }
-
-                if (parameterWrapBean.getFact() == null && ArrayUtil.isNotEmpty(args)){
-                    if (parameterWrapBean.getParameterType().isAssignableFrom(args[index - 1].getClass())){
-                        return args[index -1];
-                    }
-                }
+            // 如果参数是NodeComponent,那就返回proxy本身
+            if (parameterWrapBean.getParameterType().isAssignableFrom(NodeComponent.class)) {
+                return proxy;
+            }
 
-                // 如果没有@LiteflowFact标注,那么不处理,直接赋值null
-                if (parameterWrapBean.getFact() == null) {
-                    return null;
+            if (parameterWrapBean.getFact() == null && ArrayUtil.isNotEmpty(args)){
+                if (parameterWrapBean.getParameterType().isAssignableFrom(args[index - 1].getClass())){
+                    return args[index -1];
                 }
+            }
 
-                // 把上下文数据转换成map形式的,key为别名,value为上下文
-                Map<String, Object> contextMap = DataBus.getSlot(thisNodeComponent.getSlotIndex()).getContextBeanList().stream().collect(
-                        Collectors.toMap(tuple -> tuple.get(0), tuple -> tuple.get(1))
-                );
-
-                List<String> errorList = new ArrayList<>();
-
-                Object result = null;
-                // 根据表达式去上下文里搜索相匹配的数据
-                for(Map.Entry<String, Object> entry : contextMap.entrySet()){
-                    try{
-                        InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache(entry.getKey() + "." + parameterWrapBean.getFact().value());
-                        DefaultContext<String, Object> context = new DefaultContext<>();
-                        context.put(entry.getKey(), entry.getValue());
-                        result = expressRunner.execute(instructionSet, context, errorList, false, false);
-                        if (result != null){
-                            break;
-                        }
-                    }catch (Exception ignore){}
-                }
+            // 如果没有@LiteflowFact标注,那么不处理,直接赋值null
+            if (parameterWrapBean.getFact() == null) {
+                return null;
+            }
 
-                if (result == null){
-                    try{
-                        // 如果没有搜到,那么尝试推断表达式是指定的上下文,按照指定上下文的方式去再获取
-                        InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache("contextMap." + parameterWrapBean.getFact().value());
-                        DefaultContext<String, Object> context = new DefaultContext<>();
-                        context.put("contextMap", contextMap);
-                        result = expressRunner.execute(instructionSet, context, errorList, false, false);
-                    }catch (Exception ignore){}
-                }
+            // 把上下文数据转换成map形式的,key为别名,value为上下文
+            Map<String, Object> contextMap = DataBus.getSlot(thisNodeComponent.getSlotIndex()).getContextBeanList().stream().collect(
+                    Collectors.toMap(tuple -> tuple.get(0), tuple -> tuple.get(1))
+            );
+
+            List<String> errorList = new ArrayList<>();
+
+            Object result = null;
+            // 根据表达式去上下文里搜索相匹配的数据
+            for(Map.Entry<String, Object> entry : contextMap.entrySet()){
+                try{
+                    InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache(entry.getKey() + "." + parameterWrapBean.getFact().value());
+                    DefaultContext<String, Object> context = new DefaultContext<>();
+                    context.put(entry.getKey(), entry.getValue());
+                    result = expressRunner.execute(instructionSet, context, errorList, false, false);
+                    if (result != null){
+                        break;
+                    }
+                }catch (Exception ignore){}
+            }
 
-                return result;
+            if (result == null){
+                try{
+                    // 如果没有搜到,那么尝试推断表达式是指定的上下文,按照指定上下文的方式去再获取
+                    InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache("contextMap." + parameterWrapBean.getFact().value());
+                    DefaultContext<String, Object> context = new DefaultContext<>();
+                    context.put("contextMap", contextMap);
+                    result = expressRunner.execute(instructionSet, context, errorList, false, false);
+                }catch (Exception ignore){}
             }
+
+            return result;
         }).toArray();
     }
 }