|
| 1 | +package com.codingapi.flow.mock; |
| 2 | + |
| 3 | +import com.codingapi.flow.domain.DelayTask; |
| 4 | +import com.codingapi.flow.domain.UrgeInterval; |
| 5 | +import com.codingapi.flow.gateway.FlowOperatorGateway; |
| 6 | +import com.codingapi.flow.mock.repository.*; |
| 7 | +import com.codingapi.flow.operator.IFlowOperator; |
| 8 | +import com.codingapi.flow.record.FlowRecord; |
| 9 | +import com.codingapi.flow.repository.*; |
| 10 | +import com.codingapi.flow.service.FlowRecordService; |
| 11 | +import com.codingapi.flow.service.FlowService; |
| 12 | +import com.codingapi.flow.service.WorkflowService; |
| 13 | +import com.codingapi.flow.service.impl.FlowActionService; |
| 14 | +import com.codingapi.flow.service.impl.FlowDelayTriggerService; |
| 15 | +import com.codingapi.flow.session.FlowSession; |
| 16 | +import com.codingapi.flow.session.IRepositoryHolder; |
| 17 | +import lombok.Getter; |
| 18 | + |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +@Getter |
| 22 | +public class MockRepositoryHolder implements IRepositoryHolder { |
| 23 | + |
| 24 | + private final DelayTaskRepository delayTaskRepository; |
| 25 | + private final ParallelBranchRepository parallelBranchRepository; |
| 26 | + private final UrgeIntervalRepository urgeIntervalRepository; |
| 27 | + private final FlowRecordRepository flowRecordRepository; |
| 28 | + private final FlowTodoMergeRepository flowTodoMergeRepository; |
| 29 | + private final FlowTodoRecordRepository flowTodoRecordRepository; |
| 30 | + private final WorkflowRepository workflowRepository; |
| 31 | + private final WorkflowRuntimeRepository workflowRuntimeRepository; |
| 32 | + private final WorkflowVersionRepository workflowVersionRepository; |
| 33 | + private final FlowRecordService flowRecordService; |
| 34 | + private final WorkflowService workflowService; |
| 35 | + private final FlowOperatorGateway flowOperatorGateway; |
| 36 | + private final String mockKey; |
| 37 | + |
| 38 | + public MockRepositoryHolder(String mockKey, FlowOperatorGateway flowOperatorGateway) { |
| 39 | + this.mockKey = mockKey; |
| 40 | + this.flowOperatorGateway = flowOperatorGateway; |
| 41 | + this.delayTaskRepository = new DelayTaskRepositoryMockImpl(); |
| 42 | + this.flowRecordRepository = new FlowRecordRepositoryMockImpl(); |
| 43 | + this.flowTodoMergeRepository = new FlowTodoMergeRepositoryMockImpl(); |
| 44 | + this.flowTodoRecordRepository = new FlowTodoRecordRepositoryMockImpl(); |
| 45 | + this.parallelBranchRepository = new ParallelBranchRepositoryMockImpl(); |
| 46 | + this.urgeIntervalRepository = new UrgeIntervalRepositoryMockImpl(); |
| 47 | + this.workflowRepository = new WorkflowRepositoryMockImpl(); |
| 48 | + this.workflowRuntimeRepository = new WorkflowRuntimeRepositoryMockImpl(); |
| 49 | + this.workflowVersionRepository = new WorkflowVersionRepositoryMockImpl(); |
| 50 | + this.flowRecordService = new FlowRecordService(flowTodoRecordRepository, flowTodoMergeRepository, flowRecordRepository); |
| 51 | + this.workflowService = new WorkflowService(workflowVersionRepository, workflowRepository, workflowRuntimeRepository); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public WorkflowService getWorkflowService() { |
| 56 | + return workflowService; |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public FlowRecordService getFlowRecordService() { |
| 61 | + return flowRecordService; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public FlowOperatorGateway getFlowOperatorGateway() { |
| 66 | + return flowOperatorGateway; |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public FlowDelayTriggerService createDelayTriggerService(DelayTask task) { |
| 71 | + return new FlowDelayTriggerService(task, this); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public FlowActionService createFlowActionService(FlowSession flowSession) { |
| 76 | + return new FlowActionService(flowSession.toActionRequest(), this); |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public FlowService createFlowService() { |
| 81 | + return new FlowService(this); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public FlowRecord getRecordById(long recordId) { |
| 86 | + return this.flowRecordService.getFlowRecord(recordId); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public List<IFlowOperator> findOperatorByIds(List<Long> ids) { |
| 91 | + return this.flowOperatorGateway.findByIds(ids); |
| 92 | + } |
| 93 | + |
| 94 | + @Override |
| 95 | + public IFlowOperator getOperatorById(long id) { |
| 96 | + return this.flowOperatorGateway.get(id); |
| 97 | + } |
| 98 | + |
| 99 | + @Override |
| 100 | + public void saveDelayTask(DelayTask delayTask) { |
| 101 | + this.delayTaskRepository.save(delayTask); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public void deleteDelayTask(DelayTask delayTask) { |
| 106 | + this.delayTaskRepository.delete(delayTask); |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + public void saveRecords(List<FlowRecord> flowRecords) { |
| 111 | + this.flowRecordService.saveFlowRecords(flowRecords); |
| 112 | + } |
| 113 | + |
| 114 | + @Override |
| 115 | + public void saveRecord(FlowRecord flowRecord) { |
| 116 | + this.flowRecordService.saveFlowRecord(flowRecord); |
| 117 | + } |
| 118 | + |
| 119 | + @Override |
| 120 | + public List<FlowRecord> findCurrentNodeRecords(long fromId, String nodeId) { |
| 121 | + return this.flowRecordService.findFlowRecordCurrentNodeRecords(fromId, nodeId); |
| 122 | + } |
| 123 | + |
| 124 | + @Override |
| 125 | + public List<FlowRecord> findProcessRecords(String processId) { |
| 126 | + return this.flowRecordService.findFlowRecordByProcessId(processId); |
| 127 | + } |
| 128 | + |
| 129 | + @Override |
| 130 | + public List<FlowRecord> findAfterRecords(String processId, long currentId) { |
| 131 | + return this.flowRecordService.findFlowRecordAfterRecords(processId, currentId); |
| 132 | + } |
| 133 | + |
| 134 | + @Override |
| 135 | + public int getParallelBranchTriggerCount(String parallelId) { |
| 136 | + return this.parallelBranchRepository.getTriggerCount(parallelId); |
| 137 | + } |
| 138 | + |
| 139 | + @Override |
| 140 | + public void addParallelTriggerCount(String parallelId) { |
| 141 | + this.parallelBranchRepository.addTriggerCount(parallelId); |
| 142 | + } |
| 143 | + |
| 144 | + @Override |
| 145 | + public void clearParallelTriggerCount(String parallelId) { |
| 146 | + this.parallelBranchRepository.clearTriggerCount(parallelId); |
| 147 | + } |
| 148 | + |
| 149 | + @Override |
| 150 | + public void saveUrgeInterval(UrgeInterval interval) { |
| 151 | + this.urgeIntervalRepository.save(interval); |
| 152 | + } |
| 153 | + |
| 154 | + @Override |
| 155 | + public UrgeInterval getLatestUrgeInterval(String processId, long recordId) { |
| 156 | + return this.urgeIntervalRepository.getLatest(processId, recordId); |
| 157 | + } |
| 158 | + |
| 159 | + @Override |
| 160 | + public List<DelayTask> findDelayTasks() { |
| 161 | + return this.delayTaskRepository.findAll(); |
| 162 | + } |
| 163 | +} |
0 commit comments