Class: Bumbleworks::Process

Inherits:
Object
  • Object
show all
Includes:
WorkitemEntityStorage
Defined in:
lib/bumbleworks/process.rb,
lib/bumbleworks/process/error_record.rb

Defined Under Namespace

Classes: EntityConflict, ErrorRecord

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WorkitemEntityStorage

#wrapped_workitem

Constructor Details

#initialize(wfid) ⇒ Process



32
33
34
# File 'lib/bumbleworks/process.rb', line 32

def initialize(wfid)
  @id = wfid
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/bumbleworks/process.rb', line 143

def method_missing(method, *args)
  ps = process_status
  if ps.respond_to?(method)
    return ps.send(method, *args)
  end
  super
end

Instance Attribute Details

#idObject (readonly) Also known as: wfid

Returns the value of attribute id.



10
11
12
# File 'lib/bumbleworks/process.rb', line 10

def id
  @id
end

Class Method Details

.all(options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/bumbleworks/process.rb', line 13

def all(options = {})
  ids(options).map do |wfid|
    new(wfid)
  end
end

.countObject



27
28
29
# File 'lib/bumbleworks/process.rb', line 27

def count
  ids.count
end

.ids(options = {}) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/bumbleworks/process.rb', line 19

def ids(options = {})
  wfids = Bumbleworks.dashboard.process_wfids
  wfids.reverse! if options[:reverse]
  limit = options[:limit] || wfids.count
  offset = options[:offset] || 0
  wfids[offset, limit]
end

Instance Method Details

#<=>(other) ⇒ Object



45
46
47
# File 'lib/bumbleworks/process.rb', line 45

def <=>(other)
  wfid <=> other.wfid
end

#==(other) ⇒ Object



49
50
51
# File 'lib/bumbleworks/process.rb', line 49

def ==(other)
  wfid == other.wfid
end

#all_subscribed_tagsObject



107
108
109
110
111
112
113
114
115
116
# File 'lib/bumbleworks/process.rb', line 107

def all_subscribed_tags
  @all_subscribed_tags ||= trackers.inject({ :global => [] }) do |memo, t|
    if t.global?
      memo[:global].concat t.tags
    else
      (memo[t.wfid] ||= []).concat t.tags
    end
    memo
  end
end

#cancel!Object



130
131
132
# File 'lib/bumbleworks/process.rb', line 130

def cancel!
  Bumbleworks.cancel_process!(wfid)
end

#definition_nameObject



138
139
140
141
# File 'lib/bumbleworks/process.rb', line 138

def definition_name
  root_ruote_expression.attribute('name') ||
    root_ruote_expression.attribute_text
end

#entity_storage_workitemObject



61
62
63
# File 'lib/bumbleworks/process.rb', line 61

def entity_storage_workitem
  super(entity_workitem)
end

#entity_workitemObject



53
54
55
56
57
58
59
# File 'lib/bumbleworks/process.rb', line 53

def entity_workitem
  @entity_workitem ||= if workitems.map(&:entity_fields).uniq.length <= 1
    workitems.first
  else
    raise EntityConflict
  end
end

#errorsObject



75
76
77
78
79
80
81
# File 'lib/bumbleworks/process.rb', line 75

def errors
  @errors ||= Bumbleworks.dashboard.context.storage.get_many('errors', [wfid]).map { |err|
    Bumbleworks::Process::ErrorRecord.new(
      ::Ruote::ProcessError.new(err)
    )
  }
end

#expression_at_position(position) ⇒ Object



71
72
73
# File 'lib/bumbleworks/process.rb', line 71

def expression_at_position(position)
  expressions.detect { |exp| exp.expid == position }
end

#expressionsObject



65
66
67
68
69
# File 'lib/bumbleworks/process.rb', line 65

def expressions
  @expressions ||= ruote_expressions.map { |rexp|
    Bumbleworks::Expression.new(rexp)
  }
end

#is_waiting_for?(event) ⇒ Boolean



122
123
124
# File 'lib/bumbleworks/process.rb', line 122

def is_waiting_for?(event)
  subscribed_events.include? event.to_s
end

#kill!Object



126
127
128
# File 'lib/bumbleworks/process.rb', line 126

def kill!
  Bumbleworks.kill_process!(wfid)
end

#leavesObject



83
84
85
86
87
88
89
# File 'lib/bumbleworks/process.rb', line 83

def leaves
  @leaves ||= ruote_expressions.inject([]) { |a, exp|
    a.select { |e| ! exp.ancestor?(e.fei) } + [ exp ]
  }.map { |leaf|
    Bumbleworks::Expression.new(leaf)
  }
end

#process_statusObject



134
135
136
# File 'lib/bumbleworks/process.rb', line 134

def process_status
  @process_status ||= Bumbleworks.dashboard.process(id)
end

#reloadObject



36
37
38
39
40
41
# File 'lib/bumbleworks/process.rb', line 36

def reload
  (instance_variables - [:@id]).each do |memo|
    instance_variable_set(memo, nil)
  end
  self
end

#subscribed_eventsObject



118
119
120
# File 'lib/bumbleworks/process.rb', line 118

def subscribed_events
  all_subscribed_tags[:global]
end

#tasksObject



95
96
97
# File 'lib/bumbleworks/process.rb', line 95

def tasks
  @tasks ||= Bumbleworks::Task.for_process(wfid)
end

#trackersObject



99
100
101
102
103
104
105
# File 'lib/bumbleworks/process.rb', line 99

def trackers
  @trackers ||= Bumbleworks.dashboard.get_trackers.select { |tid, attrs|
    attrs['msg']['fei'] && attrs['msg']['fei']['wfid'] == id
  }.map { |tid, original_hash|
    Bumbleworks::Tracker.new(tid, original_hash)
  }
end

#workitemsObject



91
92
93
# File 'lib/bumbleworks/process.rb', line 91

def workitems
  @workitems ||= leaves.map(&:workitem)
end