Skip to content

Commit 40d0046

Browse files
committed
fix processNodes NPE
1 parent 07eb6c5 commit 40d0046

2 files changed

Lines changed: 28 additions & 18 deletions

File tree

flow-engine-framework/src/main/java/com/codingapi/flow/service/impl/FlowProcessNodeService.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.codingapi.flow.action.IFlowAction;
44
import com.codingapi.flow.action.actions.PassAction;
5+
import com.codingapi.flow.cache.FlowOperatorLocalThreadCache;
56
import com.codingapi.flow.exception.FlowNotFoundException;
67
import com.codingapi.flow.form.FormData;
78
import com.codingapi.flow.manager.ActionManager;
@@ -94,30 +95,31 @@ private IFlowOperator loadRecordOperator(long operatorId) {
9495
return flowOperator;
9596
}
9697

97-
private void fetchFlowRecordOperatorList(){
98+
private void fetchFlowRecordOperatorList() {
9899
List<Long> operatorIds = new ArrayList<>();
99100

100-
for(FlowRecord flowRecord:this.recordList){
101-
if(!operatorIds.contains(flowRecord.getCreateOperatorId())){
101+
for (FlowRecord flowRecord : this.recordList) {
102+
if (!operatorIds.contains(flowRecord.getCreateOperatorId())) {
102103
operatorIds.add(flowRecord.getCreateOperatorId());
103104
}
104-
if(!operatorIds.contains(flowRecord.getCurrentOperatorId())){
105+
if (!operatorIds.contains(flowRecord.getCurrentOperatorId())) {
105106
operatorIds.add(flowRecord.getCurrentOperatorId());
106107
}
107-
if(!operatorIds.contains(flowRecord.getSubmitOperatorId())){
108+
if (!operatorIds.contains(flowRecord.getSubmitOperatorId())) {
108109
operatorIds.add(flowRecord.getSubmitOperatorId());
109110
}
110111
}
111112

112113
List<IFlowOperator> operatorList = this.repositoryHolder.findOperatorByIds(operatorIds);
113-
if(operatorList!=null && !operatorList.isEmpty()){
114-
for(IFlowOperator operator:operatorList){
114+
if (operatorList != null && !operatorList.isEmpty()) {
115+
for (IFlowOperator operator : operatorList) {
115116
this.recordOperatorMap.put(operator.getUserId(), operator);
116117
}
117118
}
118119
}
119120

120121
public List<ProcessNode> processNodes() {
122+
FlowOperatorLocalThreadCache.getInstance().clear();
121123
// load history data
122124
if (this.flowRecord != null) {
123125
this.loadHistoryData();
@@ -151,9 +153,6 @@ private void loadEndNode(boolean finish) {
151153
}
152154

153155

154-
155-
156-
157156
private List<FlowRecord> loadLatestRecords() {
158157
List<FlowRecord> flowRecords = new ArrayList<>();
159158
for (FlowRecord flowRecord : this.recordList) {
@@ -169,7 +168,11 @@ private void loadNextData() {
169168
if (this.flowRecord == null) {
170169
IFlowNode currentNode = this.workflow.getStartNode();
171170
IFlowOperator currentOperator = this.loadRecordOperator(this.request.getOperatorId());
172-
FlowSession flowSession = this.buildFlowSession(currentNode, currentOperator, currentOperator, currentOperator, 0);
171+
FlowSession flowSession = this.buildFlowSession(null, currentNode, currentOperator, currentOperator, currentOperator, 0);
172+
List<FlowRecord> flowRecords = currentNode.generateCurrentRecords(flowSession);
173+
FlowRecord startRecord = flowRecords.get(0);
174+
flowSession.setCurrentRecord(startRecord);
175+
173176
this.addFlowNode(currentNode, flowSession);
174177
this.fetchFlowNode(flowSession);
175178
} else {
@@ -181,19 +184,21 @@ private void loadNextData() {
181184
IFlowOperator createOperator = this.loadRecordOperator(todoRecord.getCreateOperatorId());
182185
IFlowOperator submitOperator = this.loadRecordOperator(todoRecord.getSubmitOperatorId());
183186

184-
FlowSession flowSession = this.buildFlowSession(currentNode, currentOperator, createOperator, submitOperator, todoRecord.getWorkRuntimeId());
187+
FlowSession flowSession = this.buildFlowSession(todoRecord, currentNode, currentOperator, createOperator, submitOperator, todoRecord.getWorkRuntimeId());
185188
this.fetchFlowNode(flowSession);
186189
}
187190
}
188191
}
189192
}
190193

191194

192-
private FlowSession buildFlowSession(IFlowNode currentNode,
193-
IFlowOperator currentOperator,
194-
IFlowOperator createdOperator,
195-
IFlowOperator submitOperator,
196-
long backupId) {
195+
private FlowSession buildFlowSession(
196+
FlowRecord flowRecord,
197+
IFlowNode currentNode,
198+
IFlowOperator currentOperator,
199+
IFlowOperator createdOperator,
200+
IFlowOperator submitOperator,
201+
long backupId) {
197202
ActionManager actionManager = currentNode.actionManager();
198203
IFlowAction flowAction = actionManager.getAction(PassAction.class);
199204
FormData formData = new FormData(this.workflow.getForm());
@@ -208,7 +213,7 @@ private FlowSession buildFlowSession(IFlowNode currentNode,
208213
currentNode,
209214
flowAction,
210215
formData,
211-
this.flowRecord,
216+
flowRecord,
212217
new ArrayList<>(),
213218
backupId,
214219
FlowAdvice.nullFlowAdvice()

flow-engine-framework/src/test/java/com/codingapi/flow/service/FlowSampleServiceTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,11 @@ void parallel() {
931931
List<FlowRecord> userRecordList = factory.flowRecordRepository.findTodoByOperator(user.getUserId());
932932
assertEquals(1, userRecordList.size());
933933

934+
935+
List<ProcessNode> nodeList = factory.flowService.processNodes(new FlowProcessNodeRequest(workflow.getId(), user.getUserId(),data));
936+
assertEquals(5,nodeList.size());
937+
assertEquals(0,nodeList.stream().filter(ProcessNode::isHistory).toList().size());
938+
934939
FlowActionRequest userRequest = new FlowActionRequest();
935940
userRequest.setFormData(data);
936941
userRequest.setRecordId(userRecordList.get(0).getId());

0 commit comments

Comments
 (0)