Skip to content

Commit

Permalink
v1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuliang5 committed Feb 2, 2024
1 parent 427f171 commit b47bd03
Show file tree
Hide file tree
Showing 60 changed files with 612 additions and 247 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ There are test cases in the test package of source code. You can run or debug di
<version>{latestVersion}</version>
</dependency>
```

2. Write flow definition. For example, the sequence is node001->node002->node003:
```
{"id": "quickstart_001", "name": "Quick Start 001",
Expand All @@ -35,18 +36,21 @@ There are test cases in the test package of source code. You can run or debug di
}
```
QuickStart001Node01Action and so on is java node action class.

3. Write the code of loading flow engine when application start.
```
FlowEngineImpl flowEngine = new FlowEngineImpl();
flowEngine.setFlowPath("classpath:flow/quickstart/quickstart_001.json");
flowEngine.init();
```
You can define FlowEngineImpl bean in Spring.
4. Write invoke flow engine code.
You can define FlowEngineImpl bean in Spring.

4. Write the code of invoking flow engine.
```
FlowParam param = new FlowParam("quickstart_001");
FlowResult result = flowEngine.execute(param);
```

The executing log are as follows:
```
[main ] INFO FlowEngineImpl - Start parsing definition files:easyflow-flow/target/test-classes/flow/quickstart/quickstart_001.json
Expand All @@ -69,7 +73,7 @@ You only need set flowPaser of FlowEngineImpl to BpmnFlowParser when use.
### More
Above is simple usecase, JDEasyFlow support many configurations and use cases. More can be seen in wiki doc.

JDEasyFlow has very flexible extension ability. You can implement more feature based on current component. For example flow data persistence、auditting、exception retry.
JDEasyFlow has very flexible extension ability. You can implement more features based on current component. For example flow data persistence、auditting、exception retry.

### Contact US
mailTo: [email protected]
2 changes: 1 addition & 1 deletion easyflow-flow-bpmn/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>easyflow-parent</artifactId>
<groupId>com.jd.easyflow</groupId>
<version>1.1.6</version>
<version>1.1.7</version>
</parent>
<artifactId>easyflow-flow-bpmn</artifactId>
<name>easyflow-flow-bpmn</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
public class BaseFlowNodeConverter implements FlowNodeConverter {

private static final Logger logger = LoggerFactory.getLogger(BaseFlowNodeConverter.class);

private static final String CONDITION_TYPE_CREATE_EXP = "createExp";
private static final String CONDITION_TYPE_CREATE_EXP_PREFIX = CONDITION_TYPE_CREATE_EXP + ":";



@Override
public Map<String, Object> convert(FlowNode flowNode, BpmnModel bpmnModel, Map<String, Object> flowDef) {
Expand Down Expand Up @@ -93,7 +98,13 @@ public Map<String, Object> convert(FlowNode flowNode, BpmnModel bpmnModel, Map<S
SequenceFlow sequenceFlow = sequenceFlowList.get(0);
String conditionExp = sequenceFlow.getConditionExpression();
if (StringUtils.isNotEmpty(conditionExp)) {
post.put(DefConstants.NODE_POST_PROP_WHEN, sequenceFlow.getConditionExpression());
conditionExp = conditionExp.trim();
if (conditionExp.startsWith(CONDITION_TYPE_CREATE_EXP_PREFIX)) {
Map<String, Object> condition = new HashMap<String, Object>();
condition.put(CONDITION_TYPE_CREATE_EXP, conditionExp.substring(CONDITION_TYPE_CREATE_EXP_PREFIX.length()));
} else {
post.put(DefConstants.NODE_POST_PROP_WHEN, conditionExp);
}
}
post.put(DefConstants.NODE_POST_PROP_TO, sequenceFlow.getTargetRef());
} else if (sequenceFlowList.size() > 1) {
Expand Down
2 changes: 1 addition & 1 deletion easyflow-flow-extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>easyflow-parent</artifactId>
<groupId>com.jd.easyflow</groupId>
<version>1.1.6</version>
<version>1.1.7</version>
</parent>
<artifactId>easyflow-flow-extension</artifactId>
<name>easyflow-flow-extension</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import org.apache.commons.lang3.tuple.Pair;

import com.jd.easyflow.flow.el.ElFactory;
import com.jd.easyflow.flow.engine.FlowContext;
import com.jd.easyflow.flow.engine.event.FlowEvent;
import com.jd.easyflow.flow.engine.event.FlowEventListener;
Expand Down Expand Up @@ -54,7 +53,7 @@ public void on(FlowEvent flowEvent) {
for (Map<String, Object> param : paramList) {
String key = (String) param.get("key");
String valueExp = (String) param.get("value");
Object value = ElFactory.get().eval(valueExp, null, context, null);
Object value = context.getElEvaluator().eval(valueExp, null, context, null);
paramMap.put(key, value);
}
context.getParam().setParam(paramMap);
Expand All @@ -69,7 +68,7 @@ public void on(FlowEvent flowEvent) {
for (Map<String, Object> result : resultList) {
String key = (String) result.get("key");
String valueExp = (String) result.get("value");
Object value = ElFactory.get().eval(valueExp, null, context, contextMap);
Object value = context.getElEvaluator().eval(valueExp, null, context, contextMap);
outputMap.put(key, value);
}
context.getResult().setResult(outputMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void postHandle(FlowContext context) {
for (Map<String, Object> result : resultList) {
String key = (String) result.get("key");
String valueExp = (String) result.get("value");
Object value = ElFactory.get().eval(valueExp, null, context, contextMap);
Object value = context.getElEvaluator().eval(valueExp, null, context, contextMap);
outputMap.put(key, value);
}
context.getResult().setResult(outputMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.jd.easyflow.flow.el.ElFactory;
import com.jd.easyflow.flow.engine.FlowContext;
import com.jd.easyflow.flow.model.FlowPreHandler;

Expand Down Expand Up @@ -36,7 +35,7 @@ public boolean preHandle(FlowContext context) {
for (Map<String, Object> param : paramList) {
String key = (String) param.get("key");
String valueExp = (String) param.get("value");
Object value = ElFactory.get().eval(valueExp, null, context, null);
Object value = context.getElEvaluator().eval(valueExp, null, context, null);
paramMap.put(key, value);
}
context.getParam().setParam(paramMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.springframework.context.ApplicationContextAware;
import org.springframework.util.ClassUtils;

import com.jd.easyflow.flow.el.ElFactory;
import com.jd.easyflow.flow.engine.FlowContext;
import com.jd.easyflow.flow.exception.FlowException;
import com.jd.easyflow.flow.model.FlowNode;
Expand Down Expand Up @@ -95,7 +94,7 @@ public <T> T execute(NodeContext nodeContext, FlowContext context) {
String valueExp = (String) param.get("value");
Map<String, Object> contextMap = new HashMap<>();
contextMap.put("node", nodeActionMap);
String value = ElFactory.get().eval(valueExp, nodeContext, context, contextMap);
String value = context.getElEvaluator().eval(valueExp, nodeContext, context, contextMap);
inputMap.put(key, value);
}
}
Expand All @@ -119,7 +118,7 @@ public <T> T execute(NodeContext nodeContext, FlowContext context) {
String valueExp = (String) result.get("value");
Object value = null;
if (StringUtils.isNotEmpty(valueExp)) {
value = ElFactory.get().eval(valueExp, null, context, contextMap);
value = context.getElEvaluator().eval(valueExp, null, context, contextMap);
} else {
value = result.get(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jd.easyflow.flow.el.ElFactory;
import com.jd.easyflow.flow.engine.FlowContext;
import com.jd.easyflow.flow.exception.FlowException;
import com.jd.easyflow.flow.model.FlowNode;
Expand All @@ -31,7 +30,7 @@ public class ShellNodeAction implements NodeAction {
public String execute(NodeContext nodeContext, FlowContext context) {
List<String> command = null;
if (StringUtils.isNotEmpty(shellCommandExp)) {
command = ElFactory.get().eval(shellCommandExp, nodeContext, context, null);
command = context.getElEvaluator().eval(shellCommandExp, nodeContext, context, null);
} else {
command = shellCommand;
}
Expand Down
2 changes: 1 addition & 1 deletion easyflow-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>easyflow-parent</artifactId>
<groupId>com.jd.easyflow</groupId>
<version>1.1.6</version>
<version>1.1.7</version>
</parent>
<artifactId>easyflow-flow</artifactId>
<name>easyflow-flow</name>
Expand Down
12 changes: 12 additions & 0 deletions easyflow-flow/src/main/java/com/jd/easyflow/flow/el/ElFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,25 @@ public static ElEvaluator get() {
}

public static ElEvaluator get(String type) {
if (type == null) {
return defaultEvaluator;
}
return evaluatorMap.get(type);
}

public static void setDefaultEvaluator(ElEvaluator evaluator) {
defaultEvaluator = evaluator;
}


public static Map<String, ElEvaluator> getEvaluatorMap() {
return evaluatorMap;
}

public static void setEvaluatorMap(Map<String, ElEvaluator> evaluatorMap) {
ElFactory.evaluatorMap = evaluatorMap;
}

public void setDefault(ElEvaluator evaluator) {
ElFactory.defaultEvaluator = evaluator;
}
Expand Down
45 changes: 30 additions & 15 deletions easyflow-flow/src/main/java/com/jd/easyflow/flow/el/ElRootMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean containsKey(Object key) {
if (key == null) {
return data == null ? false : data.containsKey(key);
}
if (key instanceof String) {
if (key.getClass() == String.class) {
switch ((String) key) {
case KEY_NODE_CONTEXT:
case KEY_ACTION_RESULT:
Expand All @@ -83,35 +83,50 @@ public Object get(Object key) {
if (key == null) {
return data == null ? null : data.get(key);
}
if (key instanceof String) {
if (key.getClass() == String.class) {
Object value = null;
switch ((String) key) {
case KEY_NODE_CONTEXT:
return nodeContext;
value = nodeContext;
break;
case KEY_ACTION_RESULT:
return actionResult;
value = actionResult;
break;
case KEY_NODE_BIZ_CONTEXT:
return nodeBizContext;
value = nodeBizContext;
break;
case KEY_CONTEXT:
return context;
value = context;
break;
case KEY_BIZ_CONTEXT:
return bizContext;
value = bizContext;
break;
case KEY_PARAM:
return param;
value = param;
break;
case KEY_BIZ_PARAM:
return bizParam;
value = bizParam;
break;
case KEY_PARAM_DATA:
return paramData;
value = paramData;
break;
case KEY_RESULT:
return result;
value = result;
break;
case KEY_BIZ_RESULT:
return bizResult;
value = bizResult;
break;
default:
return data == null ? null : data.get(key);
// NOOP
}
if (value == null && data != null) {
value = data.get(key);
}
return value;
}
return false;
return null;
}

@Override
public int size() {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.Map;

import com.jd.easyflow.flow.el.ElEvaluator;
import com.jd.easyflow.flow.model.Flow;
import com.jd.easyflow.flow.model.NodeContext;

Expand Down Expand Up @@ -164,6 +165,8 @@ public interface FlowContext {
* @param context
*/
void setContext(Object context);

ElEvaluator getElEvaluator();


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Map;

import com.jd.easyflow.flow.el.ElEvaluator;
import com.jd.easyflow.flow.model.Flow;
import com.jd.easyflow.flow.model.parser.FlowParser;

Expand Down Expand Up @@ -48,4 +49,10 @@ public interface FlowEngine {
*/
<T>T getProperty(String key);

/**
*
* @return
*/
ElEvaluator getElEvaluator();

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.jd.easyflow.flow.engine.FlowContext;
import com.jd.easyflow.flow.engine.FlowParam;

/**
Expand All @@ -26,6 +28,15 @@ public static FlowParamBuilder create(String flowId, String nodeId) {
return builder;
}

public static FlowParamBuilder create(String flowId, String[] nodeIds) {
FlowParam param = new FlowParam();
param.setFlowId(flowId);
param.setNodeIds(nodeIds);
FlowParamBuilder builder = new FlowParamBuilder();
builder.param = param;
return builder;
}

public FlowParamBuilder putParam(String key, Object value) {
if (param.getParam() == null) {
param.setParam( new HashMap<>());
Expand Down Expand Up @@ -55,6 +66,25 @@ public FlowParamBuilder paramObject(Object o) {
return this;
}

public FlowParamBuilder putData(String key, Object value) {
param.put(key, value);
return this;
}

public FlowParamBuilder putData(Map<String, Object> dataMap) {
if (dataMap != null) {
for (Entry<String, Object> entry : dataMap.entrySet()) {
param.put(entry.getKey(), entry.getValue());
}
}
return this;
}

public FlowParamBuilder setContext(FlowContext context) {
param.setContext(context);
return this;
}

public FlowParam build() {
return param;
}
Expand Down
Loading

0 comments on commit b47bd03

Please sign in to comment.