Class: OpenWFE::WorklistClient

Inherits:
RestClient show all
Defined in:
lib/openwfe/orest/worklistclient.rb

Overview

a client to an OpenWFE worklists.

Instance Attribute Summary

Attributes inherited from RestClient

#host, #port, #resource, #session_id

Instance Method Summary collapse

Methods inherited from RestClient

#close

Constructor Details

#initialize(url, username, password) ⇒ WorklistClient

Returns a new instance of WorklistClient.



62
63
64
# File 'lib/openwfe/orest/worklistclient.rb', line 62

def initialize (url, username, password)
    super
end

Instance Method Details

#delegate(workitem, targetStoreName) ⇒ Object

Delegate the workitem (transfer it to another store).



217
218
219
220
221
222
223
224
225
# File 'lib/openwfe/orest/worklistclient.rb', line 217

def delegate (workitem, targetStoreName)

    ewi = OpenWFE.encode(workitem)

    params = {}
    params[TARGETSTORE] = targetStoreName

    decode(post('delegate', workitem.store, params, ewi))
end

#delegate_to_participant(workitem, targetParticipantName) ⇒ Object

Delegate the workitem (ask the worklist to deliver it to another participant).



231
232
233
234
235
236
237
238
239
# File 'lib/openwfe/orest/worklistclient.rb', line 231

def delegate_to_participant (workitem, targetParticipantName)

    ewi = OpenWFE.encode(workitem)

    params = {}
    params[TARGETPARTICIPANT] = targetParticipantName

    decode(post('delegate', workitem.store, params, ewi))
end

#find_flow_instance(store_name, workflow_instance_id) ⇒ Object

TODO : rdoc me



93
94
95
96
97
98
99
# File 'lib/openwfe/orest/worklistclient.rb', line 93

def find_flow_instance (store_name, workflow_instance_id)

    params = {}
    params["id"] = workflow_instance_id

    decode(get('findFlowInstance', store_name, params))
end

#get_and_lock_workitem(storeName, flowExpressionId) ⇒ Object

Returns a workitem and makes sure it’s locked in the worklist. Thus, the usage of the methods saveWorkitem() and forwardWorkitem() is possible.



131
132
133
134
135
136
# File 'lib/openwfe/orest/worklistclient.rb', line 131

def get_and_lock_workitem (storeName, flowExpressionId)

    #puts "...getAndLockWorkitem() for #{flowExpressionId}"

    get_item('getAndLockWorkitem', storeName, flowExpressionId)
end

#get_headers(storeName, limit = 1000) ⇒ Object

Returns the headers of a given store.



82
83
84
85
86
87
88
# File 'lib/openwfe/orest/worklistclient.rb', line 82

def get_headers (storeName, limit=1000)

    params = {}
    params["limit"] = limit

    decode(get('getHeaders', storeName, params))
end

#get_workitem(storeName, flowExpressionId) ⇒ Object

Returns a workitem (but doesn’t put a lock on it, thus modifications to it cannot be communicated with saveWorkitem() or forwardWorkitem() to the worklist)



121
122
123
124
# File 'lib/openwfe/orest/worklistclient.rb', line 121

def get_workitem (storeName, flowExpressionId)

    get_item('getWorkitem', storeName, flowExpressionId)
end

#launch_flow(engineId, launchitem) ⇒ Object

Launches a flow (on a given engine and with a given launchitem). The ‘engineId’ corresponds to an engine’s participant name (see etc/engine/participant-map.xml)



106
107
108
109
110
111
112
113
114
# File 'lib/openwfe/orest/worklistclient.rb', line 106

def launch_flow (engineId, launchitem)

    eli = OpenWFE::XmlCodec::encode(launchitem)

    params = {}
    params[ENGINEID] = engineId

    decode(post('launchFlow', nil, params, eli))
end

#list_launchablesObject

Returns the list of flow URLs the user owning this session may launch.



207
208
209
210
211
212
# File 'lib/openwfe/orest/worklistclient.rb', line 207

def list_launchables ()

    params = {}

    decode(get('listLaunchables', nil, params))
end

#list_storesObject Also known as: get_store_names

Returns the list of stores the worklist hosts



69
70
71
72
# File 'lib/openwfe/orest/worklistclient.rb', line 69

def list_stores
    r = get('listStores', nil, nil)
    decode(r)
end

#proceed_workitem(workitem) ⇒ Object Also known as: forward_workitem

Returns the workitem to the worklist so that it can resume its flow (changes to the workitem are saved).



196
197
198
199
# File 'lib/openwfe/orest/worklistclient.rb', line 196

def proceed_workitem (workitem)

    post_item('forwardWorkitem', workitem)
end

#query_and_lock_workitem(storeName, queryMap) ⇒ Object

Given a queryMap (a dict of keys and values), locks and returns the first workitem matching.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/openwfe/orest/worklistclient.rb', line 142

def query_and_lock_workitem (storeName, queryMap)

    hs = get_headers(storeName)
    hs.each do |h|

        #puts "...h.id  #{h.flowExpressionId}"
        #h.attributes.each do |k, v|
        #    puts "......h '#{k}' => '#{v}'"
        #end

        ok = true
        id = nil

        queryMap.each do |key, value|

            #puts "...'#{key}' => '#{h.attributes[key]}' ?= '#{value}'"
            ok = (ok and h.attributes[key] == value)
                #
                # the parenthesis are very important

            #puts "  .ok is #{ok}"
            #puts "  .id is #{h.flowExpressionId}"
            break unless ok
        end

        #puts "  .id is #{h.flowExpressionId}"

        get_and_lock_workitem(storeName, h.flow_expression_id) if ok
    end

    nil
end

#release_workitem(workitem) ⇒ Object

Notifies the worklist that the given workitem has to be unlocked any local (client-side) modification to it are ignored.



179
180
181
182
# File 'lib/openwfe/orest/worklistclient.rb', line 179

def release_workitem (workitem)

    post_item('releaseWorkitem', workitem)
end

#save_workitem(workitem) ⇒ Object

Saves back the workitem in the worklist (and releases it)



187
188
189
190
# File 'lib/openwfe/orest/worklistclient.rb', line 187

def save_workitem (workitem)

    post_item('saveWorkitem', workitem)
end