001/*
002 *    Copyright 2024-2025, Warm-Flow (290631660@qq.com).
003 *
004 *    Licensed under the Apache License, Version 2.0 (the "License");
005 *    you may not use this file except in compliance with the License.
006 *    You may obtain a copy of the License at
007 *
008 *       https://www.apache.org/licenses/LICENSE-2.0
009 *
010 *    Unless required by applicable law or agreed to in writing, software
011 *    distributed under the License is distributed on an "AS IS" BASIS,
012 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *    See the License for the specific language governing permissions and
014 *    limitations under the License.
015 */
016package org.dromara.warm.flow.core.listener;
017
018import org.dromara.warm.flow.core.dto.FlowParams;
019import org.dromara.warm.flow.core.entity.Definition;
020import org.dromara.warm.flow.core.entity.Instance;
021import org.dromara.warm.flow.core.entity.Node;
022import org.dromara.warm.flow.core.entity.Task;
023
024import java.util.List;
025import java.util.Map;
026
027/**
028 * 监听器变量
029 *
030 * @author warm
031 */
032public class ListenerVariable {
033
034    /**
035     * 流程定义
036     */
037    private Definition definition;
038
039    /**
040     * 流程实例
041     */
042    private Instance instance;
043
044    /**
045     * 监听器对应的节点
046     */
047    private Node node;
048
049    /**
050     * 当前任务
051     */
052    private Task task;
053
054    /**
055     * 下一次执行的节点集合
056     */
057    private List<Node> nextNodes;
058
059    /**
060     * 新创建任务集合
061     */
062    private List<Task> nextTasks;
063
064    /**
065     * 流程变量
066     */
067    private Map<String, Object> variable;
068
069    /**
070     * 工作流内置参数
071     */
072    private FlowParams flowParams;
073
074    /**
075     * 权限监听器使用
076     * 权限标识 例如:[role:admin,user:2]
077     */
078    @Deprecated
079    private List<NodePermission> nodePermissionList;
080
081    public ListenerVariable() {
082    }
083
084    public ListenerVariable(Definition definition, Instance instance, Map<String, Object> variable) {
085        this.definition = definition;
086        this.instance = instance;
087        this.variable = variable;
088    }
089
090    public ListenerVariable(Definition definition, Instance instance, Node node, Map<String, Object> variable) {
091        this.definition = definition;
092        this.instance = instance;
093        this.node = node;
094        this.variable = variable;
095    }
096
097    public ListenerVariable(Definition definition, Instance instance, Map<String, Object> variable, Task task) {
098        this.definition = definition;
099        this.instance = instance;
100        this.variable = variable;
101        this.task = task;
102    }
103
104    public ListenerVariable(Definition definition, Instance instance, Node node, Map<String, Object> variable, Task task) {
105        this.definition = definition;
106        this.instance = instance;
107        this.node = node;
108        this.variable = variable;
109        this.task = task;
110    }
111
112    public ListenerVariable(Definition definition, Instance instance, Node node, Map<String, Object> variable, Task task, List<Node> nextNodes) {
113        this.definition = definition;
114        this.instance = instance;
115        this.node = node;
116        this.variable = variable;
117        this.task = task;
118        this.nextNodes = nextNodes;
119    }
120
121    public ListenerVariable(Definition definition, Instance instance, Node node , Map<String, Object> variable, Task task
122            , List<Node> nextNodes, List<Task> nextTasks) {
123        this.definition = definition;
124        this.instance = instance;
125        this.node = node;
126        this.variable = variable;
127        this.task = task;
128        this.nextNodes = nextNodes;
129        this.nextTasks = nextTasks;
130    }
131
132    public Definition getDefinition() {
133        return definition;
134    }
135
136    public ListenerVariable setDefinition(Definition definition) {
137        this.definition = definition;
138        return this;
139    }
140
141    public Instance getInstance() {
142        return instance;
143    }
144
145    public ListenerVariable setInstance(Instance instance) {
146        this.instance = instance;
147        return this;
148    }
149
150    public Node getNode() {
151        return node;
152    }
153
154    public ListenerVariable setNode(Node node) {
155        this.node = node;
156        return this;
157    }
158
159    public Task getTask() {
160        return task;
161    }
162
163    public ListenerVariable setTask(Task task) {
164        this.task = task;
165        return this;
166    }
167
168    public List<Node> getNextNodes() {
169        return nextNodes;
170    }
171
172    public ListenerVariable setNextNodes(List<Node> nextNodes) {
173        this.nextNodes = nextNodes;
174        return this;
175    }
176
177    public List<Task> getNextTasks() {
178        return nextTasks;
179    }
180
181    public ListenerVariable setNextTasks(List<Task> nextTasks) {
182        this.nextTasks = nextTasks;
183        return this;
184    }
185
186    public Map<String, Object> getVariable() {
187        return variable;
188    }
189
190    public ListenerVariable setVariable(Map<String, Object> variable) {
191        this.variable = variable;
192        return this;
193    }
194
195    public List<NodePermission> getNodePermissionList() {
196        return nodePermissionList;
197    }
198
199    public void setNodePermissionList(List<NodePermission> nodePermissionList) {
200        this.nodePermissionList = nodePermissionList;
201    }
202
203    public NodePermission getPermissionByNode(String nodeCode) {
204
205        return nodePermissionList.stream().filter(t -> t.getNodeCode().equals(nodeCode))
206                .findFirst()
207                .orElse(null);
208    }
209
210    public FlowParams getFlowParams() {
211        return flowParams;
212    }
213
214    public ListenerVariable setFlowParams(FlowParams flowParams) {
215        this.flowParams = flowParams;
216        return this;
217    }
218
219    @Override
220    public String toString() {
221        return "ListenerVariable{" +
222                "definition=" + definition +
223                ", instance=" + instance +
224                ", node=" + node +
225                ", task=" + task +
226                ", nextNodes=" + nextNodes +
227                ", nextTasks=" + nextTasks +
228                ", variable=" + variable +
229                ", flowParams=" + flowParams +
230                ", nodePermissionList=" + nodePermissionList +
231                '}';
232    }
233
234}