Module: BpmManager::RedHat
- Defined in:
- lib/bpm_manager/red_hat.rb
Class Method Summary collapse
-
.assign_task(task_id, user_id) ⇒ Object
Assigns a Task for an User.
-
.clear_all_history ⇒ Object
Clears all the History –WARNING: Destructive action!–.
-
.complete_task(task_id, opts = {}) ⇒ Object
Completes a Task.
-
.complete_task_as_admin(task_id, opts = {}) ⇒ Object
Completes a Task as Administrator.
-
.create_process(deployment_id, process_definition_id, opts = {}) ⇒ Object
Creates a new Process.
-
.deployments ⇒ Object
Gets all server deployments.
-
.exit_task(task_id) ⇒ Object
Exits a Task.
-
.fail_task(task_id) ⇒ Object
Fails a Task.
-
.get_history(process_definition_id = "") ⇒ Object
Gets the Process History.
-
.get_process_sla(process_instance_id, process_sla_hours = 0, warning_offset_percent = 20) ⇒ Object
Gets the SLA for a Process Instance.
-
.get_task_sla(task_instance_id, process_sla_hours = 0, task_sla_hours = 0, warning_offset_percent = 20) ⇒ Object
Gets the SLA for a Task Instance.
-
.process_image(deployment_id, process_definition_id, process_id = '') ⇒ Object
Gets the Process image as SVG.
-
.process_instance(process_instance_id) ⇒ Object
Gets a Process Instance.
-
.process_instance_nodes(process_instance_id) ⇒ Object
Gets a Process Instance Nodes.
-
.process_instance_variables(process_instance_id) ⇒ Object
Gets a Process Instance Variables.
-
.process_instances ⇒ Object
Gets all Process Instances.
-
.processes ⇒ Object
Gets all available processes.
-
.processes_query_with_opts(opts = {}) ⇒ Object
Gets all the runtime processes with query options.
-
.release_task(task_id) ⇒ Object
Releases a Task.
-
.resume_task(task_id) ⇒ Object
Resumes a Task.
-
.skip_task(task_id) ⇒ Object
Skips a Task.
-
.start_task(task_id) ⇒ Object
Starts a Task.
-
.stop_task(task_id) ⇒ Object
Stops a Task.
- .structure_task_data(input) ⇒ Object
- .structure_task_query_data(input) ⇒ Object
-
.suspend_task(task_id) ⇒ Object
Suspends a Task.
-
.task_query(task_id) ⇒ Object
Gets all the information for a Task ID.
-
.tasks(user_id = '') ⇒ Object
Gets all tasks, optionally you could specify an user id.
-
.tasks_query_with_opts(opts = {}) ⇒ Object
Gets all the runtime Tasks with query options.
-
.tasks_with_opts(opts = {}) ⇒ Object
Gets all tasks with options.
Class Method Details
.assign_task(task_id, user_id) ⇒ Object
Assigns a Task for an User
82 83 84 |
# File 'lib/bpm_manager/red_hat.rb', line 82 def self.assign_task(task_id, user_id) BpmManager.server['/task/' + task_id.to_s + '/delegate'].post(:targetEntityId => user_id.to_s) end |
.clear_all_history ⇒ Object
Clears all the History –WARNING: Destructive action!–
162 163 164 |
# File 'lib/bpm_manager/red_hat.rb', line 162 def self.clear_all_history() BpmManager.server['/history/clear'].post({}) end |
.complete_task(task_id, opts = {}) ⇒ Object
Completes a Task
131 132 133 |
# File 'lib/bpm_manager/red_hat.rb', line 131 def self.complete_task(task_id, opts = {}) BpmManager.server['/task/' + task_id.to_s + '/complete'].post(opts) end |
.complete_task_as_admin(task_id, opts = {}) ⇒ Object
Completes a Task as Administrator
136 137 138 139 140 |
# File 'lib/bpm_manager/red_hat.rb', line 136 def self.complete_task_as_admin(task_id, opts = {}) self.release_task(task_id) self.start_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/complete'].post(opts) end |
.create_process(deployment_id, process_definition_id, opts = {}) ⇒ Object
Creates a new Process
18 19 20 |
# File 'lib/bpm_manager/red_hat.rb', line 18 def self.create_process(deployment_id, process_definition_id, opts = {}) BpmManager.server['/runtime/' + deployment_id.to_s + '/process/' + process_definition_id.to_s + '/start'].post(opts) end |
.deployments ⇒ Object
Gets all server deployments
8 9 10 |
# File 'lib/bpm_manager/red_hat.rb', line 8 def self.deployments() JSON.parse(BpmManager.server['/deployment'].get) end |
.exit_task(task_id) ⇒ Object
Exits a Task
148 149 150 |
# File 'lib/bpm_manager/red_hat.rb', line 148 def self.exit_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/exit'].post({}) end |
.fail_task(task_id) ⇒ Object
Fails a Task
143 144 145 |
# File 'lib/bpm_manager/red_hat.rb', line 143 def self.fail_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/fail'].post({}) end |
.get_history(process_definition_id = "") ⇒ Object
Gets the Process History
153 154 155 156 157 158 159 |
# File 'lib/bpm_manager/red_hat.rb', line 153 def self.get_history(process_definition_id = "") if process_definition_id.empty? JSON.parse(BpmManager.server['/history/instances'].get) else JSON.parse(BpmManager.server['/history/process/' + process_definition_id.to_s].get) end end |
.get_process_sla(process_instance_id, process_sla_hours = 0, warning_offset_percent = 20) ⇒ Object
Gets the SLA for a Process Instance
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/bpm_manager/red_hat.rb', line 167 def self.get_process_sla(process_instance_id, process_sla_hours = 0, warning_offset_percent = 20) my_process = JSON.parse(BpmManager.server['/history/instance/' + process_instance_id.to_s].get) unless my_process.nil? sla = OpenStruct.new(:process => OpenStruct.new) start = my_process['start'].to_i / 1000 # Calculates the process sla sla.process.status = calculate_sla(start, process_sla_hours, warning_offset_percent) sla.process.status_name = (calculate_sla(start, process_sla_hours, warning_offset_percent) == 0) ? 'ok' : (calculate_sla(start, process_sla_hours, warning_offset_percent) == 1 ? 'warning' : 'due') sla.process.percentages = calculate_sla_percent(start, process_sla_hours, warning_offset_percent) else sla = nil end return sla end |
.get_task_sla(task_instance_id, process_sla_hours = 0, task_sla_hours = 0, warning_offset_percent = 20) ⇒ Object
Gets the SLA for a Task Instance
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/bpm_manager/red_hat.rb', line 186 def self.get_task_sla(task_instance_id, process_sla_hours = 0, task_sla_hours = 0, warning_offset_percent = 20) my_task = self.tasks_with_opts('taskId' => task_instance_id).first unless my_task.nil? sla = OpenStruct.new(:task => OpenStruct.new, :process => OpenStruct.new) # Calculates the process sla sla.process.status = calculate_sla(my_task.process.start_on, process_sla_hours, warning_offset_percent) sla.process.status_name = (calculate_sla(my_task.process.start_on, process_sla_hours, warning_offset_percent) == 0) ? 'ok' : (calculate_sla(my_task.process.start_on, process_sla_hours, warning_offset_percent) == 1 ? 'warning' : 'due') sla.process.percentages = calculate_sla_percent(my_task.process.start_on, process_sla_hours, warning_offset_percent) # Calculates the task sla sla.task.status = calculate_sla(my_task.created_on, task_sla_hours, warning_offset_percent) sla.task.status_name = (calculate_sla(my_task.created_on, task_sla_hours, warning_offset_percent) == 0) ? 'ok' : (calculate_sla(my_task.created_on, task_sla_hours, warning_offset_percent) == 1 ? 'warning' : 'due') sla.task.percentages = calculate_sla_percent(my_task.created_on, task_sla_hours, warning_offset_percent) else sla = nil end return sla end |
.process_image(deployment_id, process_definition_id, process_id = '') ⇒ Object
Gets the Process image as SVG
63 64 65 66 67 68 69 |
# File 'lib/bpm_manager/red_hat.rb', line 63 def self.process_image(deployment_id, process_definition_id, process_id = '') begin BpmManager.server['/runtime/' + deployment_id.to_s + '/process/' + process_definition_id.to_s + '/image' + ((process_id.to_s.nil? || process_id.to_s.empty?) ? '' : '/' + process_id.to_s)].get rescue return '' # returns an empty string in case of error end end |
.process_instance(process_instance_id) ⇒ Object
Gets a Process Instance
33 34 35 36 37 38 39 |
# File 'lib/bpm_manager/red_hat.rb', line 33 def self.process_instance(process_instance_id) begin JSON.parse(BpmManager.server['/history/instance/' + process_instance_id.to_s].get) rescue Exception {} # returns nil string in case of error end end |
.process_instance_nodes(process_instance_id) ⇒ Object
Gets a Process Instance Nodes
42 43 44 45 46 47 48 |
# File 'lib/bpm_manager/red_hat.rb', line 42 def self.process_instance_nodes(process_instance_id) begin JSON.parse(BpmManager.server['/history/instance/' + process_instance_id.to_s + '/node'].get)['historyLogList'] rescue {} # returns nil string in case of error end end |
.process_instance_variables(process_instance_id) ⇒ Object
Gets a Process Instance Variables
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bpm_manager/red_hat.rb', line 51 def self.process_instance_variables(process_instance_id) begin result = Hash.new JSON.parse(BpmManager.server['/history/instance/' + process_instance_id.to_s + '/variable'].get)['historyLogList'].each{|e| result[e.first.second['variable-id']] = e.first.second['value']} return result rescue return {} # same result as not found record in jbpm end end |
.process_instances ⇒ Object
Gets all Process Instances
23 24 25 |
# File 'lib/bpm_manager/red_hat.rb', line 23 def self.process_instances JSON.parse(BpmManager.server['/history/instances'].get) end |
.processes ⇒ Object
Gets all available processes
13 14 15 |
# File 'lib/bpm_manager/red_hat.rb', line 13 def self.processes() JSON.parse(BpmManager.server['/deployment/processes'].get)['processDefinitionList'] end |
.processes_query_with_opts(opts = {}) ⇒ Object
Gets all the runtime processes with query options
28 29 30 |
# File 'lib/bpm_manager/red_hat.rb', line 28 def self.processes_query_with_opts(opts = {}) JSON.parse(BpmManager.server['/query/runtime/process/' + (opts.empty? ? '' : '?' + opts.map{|k,v| (v.class == Array) ? v.map{|e| k.to_s + '=' + e.to_s}.join('&') : k.to_s + '=' + v.to_s}.join('&'))].get)['processInstanceInfoList'] end |
.release_task(task_id) ⇒ Object
Releases a Task
106 107 108 |
# File 'lib/bpm_manager/red_hat.rb', line 106 def self.release_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/release'].post({}) end |
.resume_task(task_id) ⇒ Object
Resumes a Task
121 122 123 |
# File 'lib/bpm_manager/red_hat.rb', line 121 def self.resume_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/resumes'].post({}) end |
.skip_task(task_id) ⇒ Object
Skips a Task
126 127 128 |
# File 'lib/bpm_manager/red_hat.rb', line 126 def self.skip_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/skip'].post({}) end |
.start_task(task_id) ⇒ Object
Starts a Task
101 102 103 |
# File 'lib/bpm_manager/red_hat.rb', line 101 def self.start_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/start'].post({}) end |
.stop_task(task_id) ⇒ Object
Stops a Task
111 112 113 |
# File 'lib/bpm_manager/red_hat.rb', line 111 def self.stop_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/stop'].post({}) end |
.structure_task_data(input) ⇒ Object
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/bpm_manager/red_hat.rb', line 252 def self.structure_task_data(input) tasks = [] unless input['taskSummaryList'].nil? || input['taskSummaryList'].empty? input['taskSummaryList'].each do |task| task_query = self.task_query(task['id']) my_task = OpenStruct.new my_task.id = task['id'] my_task.name = task['name'] my_task.subject = task['subject'] my_task.description = task['description'] my_task.status = task['status'] my_task.priority = task['priority'] my_task.skippable = task['skippable'] my_task.created_on = Time.at(task['created-on']/1000) my_task.active_on = Time.at(task['activation-time']/1000) my_task.process_instance_id = task['process-instance-id'] my_task.process_id = task['process-id'] my_task.process_session_id = task['process-session-id'] my_task.deployment_id = task['deployment-id'] my_task.quick_task_summary = task['quick-task-summary'] my_task.parent_id = task['parent_id'] my_task.form_name = task_query['form-name'] my_task.creator = task_query['taskData']['created-by'] my_task.owner = task['actual-owner'] my_task.data = task my_task.process = OpenStruct.new my_task.process.data = self.process_instance(task['process-instance-id']) my_task.process.deployment_id = task['deployment-id'] my_task.process.id = my_task.process.data['process-id'] my_task.process.instance_id = my_task.process.data['process-instance-id'] my_task.process.start_on = my_task.process.data['start'].nil? ? Time.now : Time.at(my_task.process.data['start']/1000) my_task.process.name = my_task.process.data['process-name'] my_task.process.version = my_task.process.data['process-version'] my_task.process.creator = my_task.process.data['identity'] my_task.process.variables = self.process_instance_variables(my_task.process.instance_id) tasks << my_task end end return tasks end |
.structure_task_query_data(input) ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/bpm_manager/red_hat.rb', line 296 def self.structure_task_query_data(input) tasks = [] unless input['taskInfoList'].nil? || input['taskInfoList'].empty? input['taskInfoList'].each do |tasks_array| task = tasks_array['taskSummaries'].max_by{|e| e['created-on']} # Selects only the last active task task_query = self.task_query(task['id']) my_task = OpenStruct.new my_task.id = task['id'] my_task.name = task['name'] my_task.subject = task['subject'] my_task.description = task['description'] my_task.status = task['status'] my_task.priority = task['priority'] my_task.skippable = task['skippable'] my_task.created_on = Time.at(task['created-on']/1000) my_task.active_on = Time.at(task['activation-time']/1000) my_task.process_instance_id = task['process-instance-id'] my_task.process_id = task['process-id'] my_task.process_session_id = task['process-session-id'] my_task.deployment_id = task['deployment-id'] my_task.quick_task_summary = task['quick-task-summary'] my_task.parent_id = task['parent_id'] my_task.form_name = task_query['form-name'] my_task.creator = task_query['taskData']['created-by'] my_task.owner = task['actual-owner'] my_task.data = task my_task.process = OpenStruct.new my_task.process.data = self.process_instance(task['process-instance-id']) my_task.process.deployment_id = task['deployment-id'] my_task.process.id = my_task.process.data['process-id'] my_task.process.instance_id = my_task.process.data['process-instance-id'] my_task.process.start_on = my_task.process.data['start'].nil? ? Time.now : Time.at(my_task.process.data['start']/1000) my_task.process.name = my_task.process.data['process-name'] my_task.process.version = my_task.process.data['process-version'] my_task.process.creator = my_task.process.data['identity'] my_task.process.variables = self.process_instance_variables(my_task.process.instance_id) tasks << my_task end end return tasks end |
.suspend_task(task_id) ⇒ Object
Suspends a Task
116 117 118 |
# File 'lib/bpm_manager/red_hat.rb', line 116 def self.suspend_task(task_id) BpmManager.server['/task/' + task_id.to_s + '/suspend'].post({}) end |
.task_query(task_id) ⇒ Object
Gets all the information for a Task ID
87 88 89 90 91 92 93 |
# File 'lib/bpm_manager/red_hat.rb', line 87 def self.task_query(task_id) begin JSON.parse(BpmManager.server['/task/' + task_id.to_s].get) rescue {} # returns nil string in case of error end end |
.tasks(user_id = '') ⇒ Object
Gets all tasks, optionally you could specify an user id
72 73 74 |
# File 'lib/bpm_manager/red_hat.rb', line 72 def self.tasks(user_id = '') self.structure_task_data(JSON.parse(BpmManager.server['/task/query?taskOwner=' + user_id].get)) end |
.tasks_query_with_opts(opts = {}) ⇒ Object
Gets all the runtime Tasks with query options
96 97 98 |
# File 'lib/bpm_manager/red_hat.rb', line 96 def self.tasks_query_with_opts(opts = {}) structure_task_query_data(JSON.parse(BpmManager.server['/query/runtime/task/' + (opts.empty? ? '' : '?' + opts.map{|k,v| (v.class == Array) ? v.map{|e| k.to_s + '=' + e.to_s}.join('&') : k.to_s + '=' + v.to_s}.join('&'))].get)) end |
.tasks_with_opts(opts = {}) ⇒ Object
Gets all tasks with options
77 78 79 |
# File 'lib/bpm_manager/red_hat.rb', line 77 def self.tasks_with_opts(opts = {}) self.structure_task_data(JSON.parse(BpmManager.server['/task/query' + (opts.empty? ? '' : '?' + opts.map{|k,v| (v.class == Array) ? v.map{|e| k.to_s + '=' + e.to_s}.join('&') : k.to_s + '=' + v.to_s}.join('&'))].get)) end |