Class: OpenWFE::OldRestWorklistServlet

Inherits:
OldRestServlet
  • Object
show all
Defined in:
lib/openwfe/worklist/oldrest.rb

Overview

This webrick servlet provides a REST interface for an old style OpenWFE worklist.

Constant Summary

Constants inherited from OldRestServlet

OpenWFE::OldRestServlet::CT, OpenWFE::OldRestServlet::MUTEX

Instance Method Summary collapse

Methods inherited from OldRestServlet

get_instance, #service

Constructor Details

#initialize(server, params) ⇒ OldRestWorklistServlet

Returns a new instance of OldRestWorklistServlet.



53
54
55
56
# File 'lib/openwfe/worklist/oldrest.rb', line 53

def initialize (server, params)
    super
    @worklist = params[:Worklist]
end

Instance Method Details

#do__findflowinstance(req, res) ⇒ Object

Returns the flow expression ids of the workitems with a given workflow instance id in a store.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/openwfe/worklist/oldrest.rb', line 159

def do__findflowinstance (req, res)

    store_name = get_store_name req

    wfid = req.query['id']
    raise "404 'id' not specified" unless wfid

    wis = @worklist.list_workitems(
        req.attributes['username'], store_name, wfid)

    e = REXML::Element.new 'stores'

    wis.each do |wi|
        e << OpenWFE::XmlCodec::encode(wi.fei)
    end

    reply_with_xml res, 200, e
end

#do__forwardworkitem(req, res) ⇒ Object

Forwards the workitem (makes the worklist reply to the engine with the modified workitem)



198
199
200
201
# File 'lib/openwfe/worklist/oldrest.rb', line 198

def do__forwardworkitem (req, res)

    execute_wi_post :forward, req, res
end

#do__getandlockworkitem(req, res) ⇒ Object

Retrieves a workitem from the worklist, locks it and returns it



150
151
152
153
# File 'lib/openwfe/worklist/oldrest.rb', line 150

def do__getandlockworkitem (req, res)

    execute_wi_get :get_and_lock, req, res
end

#do__getheaders(req, res) ⇒ Object

This implementation simply encodes the workitem, no transformation into headers at all.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/openwfe/worklist/oldrest.rb', line 93

def do__getheaders (req, res)

    limit = req.query['limit']
    limit = limit.to_s.to_i if limit
    limit = nil if limit and limit < 1

    hs = @worklist.get_headers(
        req.attributes['username'],
        get_store_name(req),
        limit)

    # TODO raise "404 no store named '#{store_name}'" unless store
    # TODO raise "403 forbidden"

    e = REXML::Element.new 'headers'

    hs.each do |h|

        workitem, locked = h

        e << OpenWFE::XmlCodec::encode_workitem_as_header(
            workitem, locked)
    end

    reply_with_xml res, 200, e
end

#do__getstorenames(req, res) ⇒ Object Also known as: do__liststores

Lists the stores in the worklist



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/openwfe/worklist/oldrest.rb', line 68

def do__getstorenames (req, res)

    e = REXML::Element.new 'stores'

    @worklist.each_store do |regex, store_name, store|

        perms = @worklist.get_permissions(
            req.attributes['username'], store_name)

        es = REXML::Element.new 'store'
        es.add_attribute 'name', store_name
        es.add_attribute 'workitem-count', store.size
        es.add_attribute 'permissions', perms
        e << es
    end

    reply_with_xml res, 200, e
end

#do__getworkitem(req, res) ⇒ Object

Retrieves a workitem from the worklist



142
143
144
145
# File 'lib/openwfe/worklist/oldrest.rb', line 142

def do__getworkitem (req, res)

    execute_wi_get :get, req, res
end

#do__launchflow(req, res) ⇒ Object

Launches a new process instance.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/openwfe/worklist/oldrest.rb', line 123

def do__launchflow (req, res)

    engine_name = req.query['engineid']
    engine_name = "__nil__" unless engine_name

    launch_item = OpenWFE::XmlCodec::decode req.body

    r = @worklist.launch_flow engine_name, launch_item

    e = REXML::Element.new 'ok'

    e.add_attribute 'flow-id', r.to_s

    reply_with_xml res, 200, e
end

#do__releaseworkitem(req, res) ⇒ Object

Releases a workitem (unlocks it).



181
182
183
184
# File 'lib/openwfe/worklist/oldrest.rb', line 181

def do__releaseworkitem (req, res)

    execute_wi_post :release, req, res
end

#do__saveworkitem(req, res) ⇒ Object

Simply saves the workitem and the modifications done to it.



189
190
191
192
# File 'lib/openwfe/worklist/oldrest.rb', line 189

def do__saveworkitem (req, res)

    execute_wi_post :save, req, res
end

#get_realm_nameObject

The realm for HTTP authentication.



61
62
63
# File 'lib/openwfe/worklist/oldrest.rb', line 61

def get_realm_name
    "worklist"
end