flowable 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +83 -0
- data/LICENSE +21 -0
- data/README.md +872 -0
- data/bin/flowable +510 -0
- data/lib/flowable/flowable.rb +273 -0
- data/lib/flowable/resources/base.rb +44 -0
- data/lib/flowable/resources/bpmn_deployments.rb +90 -0
- data/lib/flowable/resources/bpmn_history.rb +228 -0
- data/lib/flowable/resources/case_definitions.rb +115 -0
- data/lib/flowable/resources/case_instances.rb +188 -0
- data/lib/flowable/resources/deployments.rb +87 -0
- data/lib/flowable/resources/executions.rb +134 -0
- data/lib/flowable/resources/history.rb +264 -0
- data/lib/flowable/resources/plan_item_instances.rb +131 -0
- data/lib/flowable/resources/process_definitions.rb +142 -0
- data/lib/flowable/resources/process_instances.rb +200 -0
- data/lib/flowable/resources/tasks.rb +281 -0
- data/lib/flowable/version.rb +37 -0
- data/lib/flowable/workflow.rb +444 -0
- data/lib/flowable.rb +9 -0
- data/lib/flowable_client/resources/bpmn_history.rb +228 -0
- data/lib/flowable_client/resources/process_definitions.rb +142 -0
- data/lib/flowable_client/resources/process_instances.rb +200 -0
- metadata +104 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Flowable
|
|
4
|
+
module Resources
|
|
5
|
+
class History < Base
|
|
6
|
+
# --- Historic Case Instances ---
|
|
7
|
+
|
|
8
|
+
# List historic case instances
|
|
9
|
+
# @param options [Hash] Query parameters
|
|
10
|
+
# @option options [String] :caseInstanceId Filter by case instance ID
|
|
11
|
+
# @option options [String] :caseDefinitionKey Filter by definition key
|
|
12
|
+
# @option options [String] :caseDefinitionId Filter by definition ID
|
|
13
|
+
# @option options [String] :businessKey Filter by business key
|
|
14
|
+
# @option options [String] :involvedUser Filter by involved user
|
|
15
|
+
# @option options [Boolean] :finished Only finished instances
|
|
16
|
+
# @option options [String] :finishedAfter Finished after date (ISO-8601)
|
|
17
|
+
# @option options [String] :finishedBefore Finished before date (ISO-8601)
|
|
18
|
+
# @option options [String] :startedAfter Started after date
|
|
19
|
+
# @option options [String] :startedBefore Started before date
|
|
20
|
+
# @option options [String] :startedBy Filter by starter user
|
|
21
|
+
# @option options [Boolean] :includeCaseVariables Include variables
|
|
22
|
+
# @option options [String] :tenantId Filter by tenant
|
|
23
|
+
# @return [Hash] Paginated list of historic case instances
|
|
24
|
+
def case_instances(**options)
|
|
25
|
+
params = paginate_params(options)
|
|
26
|
+
%i[caseInstanceId caseDefinitionKey caseDefinitionId businessKey
|
|
27
|
+
involvedUser startedBy tenantId tenantIdLike].each do |key|
|
|
28
|
+
params[key] = options[key] if options[key]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
%i[finished includeCaseVariables withoutTenantId].each do |key|
|
|
32
|
+
params[key] = options[key] if options.key?(key)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
%i[finishedAfter finishedBefore startedAfter startedBefore].each do |key|
|
|
36
|
+
params[key] = format_date(options[key]) if options[key]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
client.get('cmmn-history/historic-case-instances', params)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Get a specific historic case instance
|
|
43
|
+
# @param case_instance_id [String] The case instance ID
|
|
44
|
+
# @return [Hash] Historic case instance details
|
|
45
|
+
def case_instance(case_instance_id)
|
|
46
|
+
client.get("cmmn-history/historic-case-instances/#{case_instance_id}")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Delete a historic case instance
|
|
50
|
+
# @param case_instance_id [String] The case instance ID
|
|
51
|
+
# @return [Boolean] true if successful
|
|
52
|
+
def delete_case_instance(case_instance_id)
|
|
53
|
+
client.delete("cmmn-history/historic-case-instances/#{case_instance_id}")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Query historic case instances with complex filters
|
|
57
|
+
# Note: CMMN API doesn't support POST query endpoint, uses GET with parameters
|
|
58
|
+
# @param query [Hash] Query parameters (same as case_instances)
|
|
59
|
+
# @return [Hash] Paginated list of historic case instances
|
|
60
|
+
def query_case_instances(query)
|
|
61
|
+
# Convert query hash to keyword arguments for case_instances
|
|
62
|
+
case_instances(**query.transform_keys(&:to_sym))
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Get identity links for a historic case instance
|
|
66
|
+
# @param case_instance_id [String] The case instance ID
|
|
67
|
+
# @return [Array<Hash>] List of identity links
|
|
68
|
+
def case_instance_identity_links(case_instance_id)
|
|
69
|
+
client.get("cmmn-history/historic-case-instance/#{case_instance_id}/identitylinks")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Get stage overview for a historic case instance
|
|
73
|
+
# @param case_instance_id [String] The case instance ID
|
|
74
|
+
# @return [Array<Hash>] List of stages
|
|
75
|
+
def case_instance_stage_overview(case_instance_id)
|
|
76
|
+
client.get("cmmn-history/historic-case-instances/#{case_instance_id}/stage-overview")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# --- Historic Milestones ---
|
|
80
|
+
|
|
81
|
+
# List historic milestones
|
|
82
|
+
# @param options [Hash] Query parameters
|
|
83
|
+
# @option options [String] :caseInstanceId Filter by case instance
|
|
84
|
+
# @option options [String] :caseDefinitionId Filter by case definition
|
|
85
|
+
# @option options [String] :milestoneId Filter by milestone ID
|
|
86
|
+
# @option options [String] :milestoneName Filter by name
|
|
87
|
+
# @option options [String] :reachedBefore Reached before date
|
|
88
|
+
# @option options [String] :reachedAfter Reached after date
|
|
89
|
+
# @return [Hash] Paginated list of milestones
|
|
90
|
+
def milestones(**options)
|
|
91
|
+
params = paginate_params(options)
|
|
92
|
+
%i[caseInstanceId caseDefinitionId milestoneId milestoneName].each do |key|
|
|
93
|
+
params[key] = options[key] if options[key]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
%i[reachedBefore reachedAfter].each do |key|
|
|
97
|
+
params[key] = format_date(options[key]) if options[key]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
client.get('cmmn-history/historic-milestone-instances', params)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Get a specific historic milestone
|
|
104
|
+
# @param milestone_id [String] The milestone instance ID
|
|
105
|
+
# @return [Hash] Milestone details
|
|
106
|
+
def milestone(milestone_id)
|
|
107
|
+
client.get("cmmn-history/historic-milestone-instances/#{milestone_id}")
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# --- Historic Plan Item Instances ---
|
|
111
|
+
|
|
112
|
+
# List historic plan item instances
|
|
113
|
+
# @param options [Hash] Query parameters
|
|
114
|
+
# @option options [String] :caseInstanceId Filter by case instance
|
|
115
|
+
# @option options [String] :caseDefinitionId Filter by case definition
|
|
116
|
+
# @option options [String] :planItemInstanceId Filter by ID
|
|
117
|
+
# @option options [String] :planItemInstanceName Filter by name
|
|
118
|
+
# @option options [String] :planItemInstanceState Filter by state
|
|
119
|
+
# @option options [String] :stageInstanceId Filter by parent stage
|
|
120
|
+
# @option options [String] :elementId Filter by element ID
|
|
121
|
+
# @option options [String] :planItemDefinitionId Filter by definition ID
|
|
122
|
+
# @option options [String] :planItemDefinitionType Filter by type
|
|
123
|
+
# @option options [String] :tenantId Filter by tenant
|
|
124
|
+
# @return [Hash] Paginated list of historic plan item instances
|
|
125
|
+
def plan_item_instances(**options)
|
|
126
|
+
params = paginate_params(options)
|
|
127
|
+
%i[caseInstanceId caseDefinitionId planItemInstanceId planItemInstanceName
|
|
128
|
+
planItemInstanceState stageInstanceId elementId planItemDefinitionId
|
|
129
|
+
planItemDefinitionType referenceId referenceType startUserId tenantId].each do |key|
|
|
130
|
+
params[key] = options[key] if options[key]
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Date filters - there are many for plan items
|
|
134
|
+
%i[createdBefore createdAfter lastAvailableBefore lastAvailableAfter
|
|
135
|
+
lastEnabledBefore lastEnabledAfter lastDisabledBefore lastDisabledAfter
|
|
136
|
+
lastStartedBefore lastStartedAfter lastSuspendedBefore lastSuspendedAfter
|
|
137
|
+
completedBefore completedAfter terminatedBefore terminatedAfter
|
|
138
|
+
occurredBefore occurredAfter exitBefore exitAfter
|
|
139
|
+
endedBefore endedAfter].each do |key|
|
|
140
|
+
params[key] = format_date(options[key]) if options[key]
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
params[:withoutTenantId] = options[:withoutTenantId] if options.key?(:withoutTenantId)
|
|
144
|
+
|
|
145
|
+
client.get('cmmn-history/historic-planitem-instances', params)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Get a specific historic plan item instance
|
|
149
|
+
# @param plan_item_instance_id [String] The plan item instance ID
|
|
150
|
+
# @return [Hash] Plan item instance details
|
|
151
|
+
def plan_item_instance(plan_item_instance_id)
|
|
152
|
+
client.get("cmmn-history/historic-planitem-instances/#{plan_item_instance_id}")
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# --- Historic Tasks ---
|
|
156
|
+
|
|
157
|
+
# List historic task instances
|
|
158
|
+
# @param options [Hash] Query parameters
|
|
159
|
+
# @option options [String] :taskId Filter by task ID
|
|
160
|
+
# @option options [String] :caseInstanceId Filter by case instance
|
|
161
|
+
# @option options [String] :caseDefinitionId Filter by case definition
|
|
162
|
+
# @option options [String] :taskName Filter by name
|
|
163
|
+
# @option options [String] :taskNameLike Filter by name pattern
|
|
164
|
+
# @option options [String] :taskAssignee Filter by assignee
|
|
165
|
+
# @option options [String] :taskOwner Filter by owner
|
|
166
|
+
# @option options [String] :taskInvolvedUser Filter by involved user
|
|
167
|
+
# @option options [Boolean] :finished Only finished tasks
|
|
168
|
+
# @option options [String] :tenantId Filter by tenant
|
|
169
|
+
# @return [Hash] Paginated list of historic tasks
|
|
170
|
+
def task_instances(**options)
|
|
171
|
+
params = paginate_params(options)
|
|
172
|
+
%i[taskId caseInstanceId caseDefinitionId taskDefinitionKey
|
|
173
|
+
taskName taskNameLike taskDescription taskDescriptionLike
|
|
174
|
+
taskCategory taskDeleteReason taskDeleteReasonLike
|
|
175
|
+
taskAssignee taskAssigneeLike taskOwner taskOwnerLike
|
|
176
|
+
taskInvolvedUser taskPriority parentTaskId tenantId tenantIdLike].each do |key|
|
|
177
|
+
params[key] = options[key] if options[key]
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
%i[finished caseFinished withoutDueDate includeTaskLocalVariables withoutTenantId].each do |key|
|
|
181
|
+
params[key] = options[key] if options.key?(key)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
%i[dueDate dueDateAfter dueDateBefore taskCompletedOn taskCompletedAfter
|
|
185
|
+
taskCompletedBefore taskCreatedOn taskCreatedBefore taskCreatedAfter].each do |key|
|
|
186
|
+
params[key] = format_date(options[key]) if options[key]
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
client.get('cmmn-history/historic-task-instances', params)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# Get a specific historic task
|
|
193
|
+
# @param task_id [String] The task ID
|
|
194
|
+
# @return [Hash] Historic task details
|
|
195
|
+
def task_instance(task_id)
|
|
196
|
+
client.get("cmmn-history/historic-task-instances/#{task_id}")
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# Delete a historic task
|
|
200
|
+
# @param task_id [String] The task ID
|
|
201
|
+
# @return [Boolean] true if successful
|
|
202
|
+
def delete_task_instance(task_id)
|
|
203
|
+
client.delete("cmmn-history/historic-task-instances/#{task_id}")
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# Query historic tasks with complex filters
|
|
207
|
+
# @param query [Hash] Query body
|
|
208
|
+
# @return [Hash] Paginated list of historic tasks
|
|
209
|
+
def query_task_instances(query)
|
|
210
|
+
client.post('query/historic-task-instances', query)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Get identity links for a historic task
|
|
214
|
+
# @param task_id [String] The task ID
|
|
215
|
+
# @return [Array<Hash>] List of identity links
|
|
216
|
+
def task_instance_identity_links(task_id)
|
|
217
|
+
client.get("cmmn-history/historic-task-instance/#{task_id}/identitylinks")
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# --- Historic Variables ---
|
|
221
|
+
|
|
222
|
+
# List historic variable instances
|
|
223
|
+
# @param options [Hash] Query parameters
|
|
224
|
+
# @option options [String] :caseInstanceId Filter by case instance
|
|
225
|
+
# @option options [String] :taskId Filter by task
|
|
226
|
+
# @option options [Boolean] :excludeTaskVariables Exclude task variables
|
|
227
|
+
# @option options [String] :variableName Filter by variable name
|
|
228
|
+
# @option options [String] :variableNameLike Filter by name pattern
|
|
229
|
+
# @return [Hash] Paginated list of historic variables
|
|
230
|
+
def variable_instances(**options)
|
|
231
|
+
params = paginate_params(options)
|
|
232
|
+
%i[caseInstanceId taskId variableName variableNameLike].each do |key|
|
|
233
|
+
params[key] = options[key] if options[key]
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
params[:excludeTaskVariables] = options[:excludeTaskVariables] if options.key?(:excludeTaskVariables)
|
|
237
|
+
|
|
238
|
+
client.get('cmmn-history/historic-variable-instances', params)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# Query historic variables with complex filters
|
|
242
|
+
# @param query [Hash] Query body
|
|
243
|
+
# @return [Hash] Paginated list of historic variables
|
|
244
|
+
def query_variable_instances(query)
|
|
245
|
+
client.post('query/historic-variable-instances', query)
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# Aliases for convenience
|
|
249
|
+
alias tasks task_instances
|
|
250
|
+
alias task task_instance
|
|
251
|
+
alias delete_task delete_task_instance
|
|
252
|
+
alias variables variable_instances
|
|
253
|
+
|
|
254
|
+
private
|
|
255
|
+
|
|
256
|
+
def format_date(date)
|
|
257
|
+
return date if date.is_a?(String)
|
|
258
|
+
return date.iso8601 if date.respond_to?(:iso8601)
|
|
259
|
+
|
|
260
|
+
date.to_s
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Flowable
|
|
4
|
+
module Resources
|
|
5
|
+
class PlanItemInstances < Base
|
|
6
|
+
BASE_PATH = 'cmmn-runtime/plan-item-instances'
|
|
7
|
+
|
|
8
|
+
# List all plan item instances
|
|
9
|
+
# @param options [Hash] Query parameters
|
|
10
|
+
# @option options [String] :id Filter by ID
|
|
11
|
+
# @option options [String] :caseDefinitionId Filter by case definition
|
|
12
|
+
# @option options [String] :caseInstanceId Filter by case instance
|
|
13
|
+
# @option options [String] :stageInstanceId Filter by parent stage
|
|
14
|
+
# @option options [String] :planItemDefinitionId Filter by plan item definition
|
|
15
|
+
# @option options [String] :planItemDefinitionType Filter by type (stage, milestone, humanTask, etc.)
|
|
16
|
+
# @option options [String] :planItemDefinitionTypes Comma-separated types
|
|
17
|
+
# @option options [String] :state Filter by state (available, active, enabled, disabled, completed, etc.)
|
|
18
|
+
# @option options [String] :name Filter by name
|
|
19
|
+
# @option options [String] :elementId Filter by element ID from model
|
|
20
|
+
# @option options [String] :tenantId Filter by tenant
|
|
21
|
+
# @return [Hash] Paginated list of plan item instances
|
|
22
|
+
def list(**options)
|
|
23
|
+
params = paginate_params(options)
|
|
24
|
+
%i[id caseDefinitionId caseInstanceId stageInstanceId
|
|
25
|
+
planItemDefinitionId planItemDefinitionType planItemDefinitionTypes
|
|
26
|
+
state name elementId referenceId referenceType
|
|
27
|
+
startUserId tenantId].each do |key|
|
|
28
|
+
params[key] = options[key] if options[key]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Date filters
|
|
32
|
+
%i[createdBefore createdAfter].each do |key|
|
|
33
|
+
params[key] = format_date(options[key]) if options[key]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
params[:withoutTenantId] = options[:withoutTenantId] if options.key?(:withoutTenantId)
|
|
37
|
+
|
|
38
|
+
client.get(BASE_PATH, params)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Get a specific plan item instance
|
|
42
|
+
# @param plan_item_instance_id [String] The plan item instance ID
|
|
43
|
+
# @return [Hash] Plan item instance details
|
|
44
|
+
def get(plan_item_instance_id)
|
|
45
|
+
client.get("#{BASE_PATH}/#{plan_item_instance_id}")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Execute an action on a plan item instance
|
|
49
|
+
# @param plan_item_instance_id [String] The plan item instance ID
|
|
50
|
+
# @param action [String] Action to execute
|
|
51
|
+
# @return [Hash] Response
|
|
52
|
+
def execute_action(plan_item_instance_id, action)
|
|
53
|
+
client.put("#{BASE_PATH}/#{plan_item_instance_id}", { action: action })
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Start a plan item (must be in enabled state)
|
|
57
|
+
# @param plan_item_instance_id [String] The plan item instance ID
|
|
58
|
+
# @return [Hash] Response
|
|
59
|
+
def start(plan_item_instance_id)
|
|
60
|
+
execute_action(plan_item_instance_id, 'start')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Trigger a plan item (for items waiting for trigger)
|
|
64
|
+
# @param plan_item_instance_id [String] The plan item instance ID
|
|
65
|
+
# @return [Hash] Response
|
|
66
|
+
def trigger(plan_item_instance_id)
|
|
67
|
+
execute_action(plan_item_instance_id, 'trigger')
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Enable a plan item (must be currently disabled)
|
|
71
|
+
# @param plan_item_instance_id [String] The plan item instance ID
|
|
72
|
+
# @return [Hash] Response
|
|
73
|
+
def enable(plan_item_instance_id)
|
|
74
|
+
execute_action(plan_item_instance_id, 'enable')
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Disable a plan item (must be currently enabled)
|
|
78
|
+
# @param plan_item_instance_id [String] The plan item instance ID
|
|
79
|
+
# @return [Hash] Response
|
|
80
|
+
def disable(plan_item_instance_id)
|
|
81
|
+
execute_action(plan_item_instance_id, 'disable')
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Evaluate criteria on a plan item
|
|
85
|
+
# @param plan_item_instance_id [String] The plan item instance ID
|
|
86
|
+
# @return [Hash] Response
|
|
87
|
+
def evaluate_criteria(plan_item_instance_id)
|
|
88
|
+
execute_action(plan_item_instance_id, 'evaluateCriteria')
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# --- Helper methods ---
|
|
92
|
+
|
|
93
|
+
# List all active plan items for a case instance
|
|
94
|
+
# @param case_instance_id [String] The case instance ID
|
|
95
|
+
# @return [Hash] Paginated list of active plan items
|
|
96
|
+
def active_for_case(case_instance_id)
|
|
97
|
+
list(caseInstanceId: case_instance_id, state: 'active')
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# List all stages for a case instance
|
|
101
|
+
# @param case_instance_id [String] The case instance ID
|
|
102
|
+
# @return [Hash] Paginated list of stages
|
|
103
|
+
def stages_for_case(case_instance_id)
|
|
104
|
+
list(caseInstanceId: case_instance_id, planItemDefinitionType: 'stage')
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# List all human tasks for a case instance
|
|
108
|
+
# @param case_instance_id [String] The case instance ID
|
|
109
|
+
# @return [Hash] Paginated list of human tasks
|
|
110
|
+
def human_tasks_for_case(case_instance_id)
|
|
111
|
+
list(caseInstanceId: case_instance_id, planItemDefinitionType: 'humantask')
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# List all milestones for a case instance
|
|
115
|
+
# @param case_instance_id [String] The case instance ID
|
|
116
|
+
# @return [Hash] Paginated list of milestones
|
|
117
|
+
def milestones_for_case(case_instance_id)
|
|
118
|
+
list(caseInstanceId: case_instance_id, planItemDefinitionType: 'milestone')
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
private
|
|
122
|
+
|
|
123
|
+
def format_date(date)
|
|
124
|
+
return date if date.is_a?(String)
|
|
125
|
+
return date.iso8601 if date.respond_to?(:iso8601)
|
|
126
|
+
|
|
127
|
+
date.to_s
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Flowable
|
|
4
|
+
module Resources
|
|
5
|
+
class ProcessDefinitions < Base
|
|
6
|
+
BASE_PATH = 'service/repository/process-definitions'
|
|
7
|
+
|
|
8
|
+
# List all process definitions
|
|
9
|
+
# @param options [Hash] Query parameters
|
|
10
|
+
# @option options [String] :key Filter by key
|
|
11
|
+
# @option options [String] :keyLike Filter by key pattern
|
|
12
|
+
# @option options [String] :name Filter by name
|
|
13
|
+
# @option options [String] :nameLike Filter by name pattern
|
|
14
|
+
# @option options [Integer] :version Filter by version
|
|
15
|
+
# @option options [String] :deploymentId Filter by deployment
|
|
16
|
+
# @option options [Boolean] :latest Only return latest versions
|
|
17
|
+
# @option options [Boolean] :suspended Filter by suspension state
|
|
18
|
+
# @option options [String] :tenantId Filter by tenant
|
|
19
|
+
# @return [Hash] Paginated list of process definitions
|
|
20
|
+
def list(**options)
|
|
21
|
+
params = paginate_params(options)
|
|
22
|
+
%i[key keyLike name nameLike resourceName resourceNameLike
|
|
23
|
+
category categoryLike categoryNotEquals deploymentId
|
|
24
|
+
startableByUser tenantId tenantIdLike].each do |key|
|
|
25
|
+
params[key] = options[key] if options[key]
|
|
26
|
+
end
|
|
27
|
+
params[:version] = options[:version] if options[:version]
|
|
28
|
+
params[:latest] = options[:latest] if options.key?(:latest)
|
|
29
|
+
params[:suspended] = options[:suspended] if options.key?(:suspended)
|
|
30
|
+
params[:withoutTenantId] = options[:withoutTenantId] if options.key?(:withoutTenantId)
|
|
31
|
+
|
|
32
|
+
client.get(BASE_PATH, params)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Get a specific process definition
|
|
36
|
+
# @param process_definition_id [String] The process definition ID
|
|
37
|
+
# @return [Hash] Process definition details
|
|
38
|
+
def get(process_definition_id)
|
|
39
|
+
client.get("#{BASE_PATH}/#{process_definition_id}")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Get process definition by key (returns latest version)
|
|
43
|
+
# @param key [String] The process definition key
|
|
44
|
+
# @param tenant_id [String] Optional tenant ID
|
|
45
|
+
# @return [Hash] Process definition details
|
|
46
|
+
def get_by_key(key, tenant_id: nil)
|
|
47
|
+
params = { key: key, latest: true }
|
|
48
|
+
params[:tenantId] = tenant_id if tenant_id
|
|
49
|
+
|
|
50
|
+
result = client.get(BASE_PATH, params)
|
|
51
|
+
result['data']&.first
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Update the category of a process definition
|
|
55
|
+
# @param process_definition_id [String] The process definition ID
|
|
56
|
+
# @param category [String] The new category
|
|
57
|
+
# @return [Hash] Updated process definition
|
|
58
|
+
def update_category(process_definition_id, category)
|
|
59
|
+
client.put("#{BASE_PATH}/#{process_definition_id}", { category: category })
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Suspend a process definition
|
|
63
|
+
# @param process_definition_id [String] The process definition ID
|
|
64
|
+
# @param include_instances [Boolean] Also suspend running instances
|
|
65
|
+
# @param date [String] Effective date (ISO-8601)
|
|
66
|
+
# @return [Hash] Updated process definition
|
|
67
|
+
def suspend(process_definition_id, include_instances: false, date: nil)
|
|
68
|
+
body = { action: 'suspend', includeProcessInstances: include_instances }
|
|
69
|
+
body[:date] = date if date
|
|
70
|
+
client.put("#{BASE_PATH}/#{process_definition_id}", body)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Activate a process definition
|
|
74
|
+
# @param process_definition_id [String] The process definition ID
|
|
75
|
+
# @param include_instances [Boolean] Also activate suspended instances
|
|
76
|
+
# @param date [String] Effective date (ISO-8601)
|
|
77
|
+
# @return [Hash] Updated process definition
|
|
78
|
+
def activate(process_definition_id, include_instances: false, date: nil)
|
|
79
|
+
body = { action: 'activate', includeProcessInstances: include_instances }
|
|
80
|
+
body[:date] = date if date
|
|
81
|
+
client.put("#{BASE_PATH}/#{process_definition_id}", body)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Get the BPMN XML content of a process definition
|
|
85
|
+
# @param process_definition_id [String] The process definition ID
|
|
86
|
+
# @return [String] BPMN XML content
|
|
87
|
+
def resource_data(process_definition_id)
|
|
88
|
+
client.get("#{BASE_PATH}/#{process_definition_id}/resourcedata")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
alias resource_content resource_data
|
|
92
|
+
|
|
93
|
+
# Get the BPMN model as JSON
|
|
94
|
+
# @param process_definition_id [String] The process definition ID
|
|
95
|
+
# @return [Hash] BPMN model structure
|
|
96
|
+
def model(process_definition_id)
|
|
97
|
+
client.get("#{BASE_PATH}/#{process_definition_id}/model")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Get process diagram image (PNG)
|
|
101
|
+
# @param process_definition_id [String] The process definition ID
|
|
102
|
+
# @return [String] Binary image data
|
|
103
|
+
def diagram(process_definition_id)
|
|
104
|
+
client.get("#{BASE_PATH}/#{process_definition_id}/image")
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
alias image diagram
|
|
108
|
+
|
|
109
|
+
# Get all candidate starters for a process definition
|
|
110
|
+
# @param process_definition_id [String] The process definition ID
|
|
111
|
+
# @return [Array<Hash>] List of identity links
|
|
112
|
+
def identity_links(process_definition_id)
|
|
113
|
+
client.get("#{BASE_PATH}/#{process_definition_id}/identitylinks")
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Add a candidate starter (user) to a process definition
|
|
117
|
+
# @param process_definition_id [String] The process definition ID
|
|
118
|
+
# @param user_id [String] The user ID
|
|
119
|
+
# @return [Hash] Created identity link
|
|
120
|
+
def add_candidate_user(process_definition_id, user_id)
|
|
121
|
+
client.post("#{BASE_PATH}/#{process_definition_id}/identitylinks", { user: user_id })
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Add a candidate starter (group) to a process definition
|
|
125
|
+
# @param process_definition_id [String] The process definition ID
|
|
126
|
+
# @param group_id [String] The group ID
|
|
127
|
+
# @return [Hash] Created identity link
|
|
128
|
+
def add_candidate_group(process_definition_id, group_id)
|
|
129
|
+
client.post("#{BASE_PATH}/#{process_definition_id}/identitylinks", { group: group_id })
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Remove a candidate starter from a process definition
|
|
133
|
+
# @param process_definition_id [String] The process definition ID
|
|
134
|
+
# @param family [String] 'users' or 'groups'
|
|
135
|
+
# @param identity_id [String] The user or group ID
|
|
136
|
+
# @return [Boolean] true if successful
|
|
137
|
+
def remove_candidate(process_definition_id, family, identity_id)
|
|
138
|
+
client.delete("#{BASE_PATH}/#{process_definition_id}/identitylinks/#{family}/#{identity_id}")
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|