public
Description: RESTful workflow / bpm engine based on Sinatra and OpenWFEru
Homepage: http://openwferu.rubyforge.org
Clone URL: git://github.com/jmettraux/ruote-rest.git
Search Repo:
/workitems done in HTML
jmettraux (author)
Wed Apr 30 05:36:42 -0700 2008
commit  af7ddf7fab42628970e5a0e2bbdbe554b2318a2f
tree    8fce5f2ab986f57cde671899f0f3fcbdf130a4a0
parent  39355a5997775c41c51db22abfe1043afc9a2c99
...
97
98
99
 
 
 
 
100
101
102
...
97
98
99
100
101
102
103
104
105
106
0
@@ -97,6 +97,10 @@
0
 
0
     returns a workitem
0
 
0
+GET /workitems?wfid=x
0
+
0
+ returns all the workitems belonging to a [business] process instance
0
+
0
 PUT /workitems/{wid}
0
 
0
     updates a workitem
...
9
10
11
 
 
12
13
14
 
 
 
 
15
16
17
...
9
10
11
12
13
14
15
 
16
17
18
19
20
21
22
0
@@ -9,9 +9,14 @@
0
 
0
 configure do
0
 
0
+ ev = Sinatra.application.options.env
0
+
0
     ac = {}
0
 
0
- ac[:work_directory] = "work_#{Sinatra.application.options.env}"
0
+ ac[:work_directory] = "work_#{ev}"
0
+
0
+ ac[:logger] = Logger.new "logs/openwferu_#{ev}.log", 10, 1024000
0
+ ac[:logger].level = (ev == 'production') ? Logger::INFO : Logger::DEBUG
0
 
0
     ac[:remote_definitions_allowed] = true
0
         #
...
142
143
144
 
 
 
 
 
 
 
 
 
 
 
 
 
...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
0
@@ -142,4 +142,17 @@
0
         l
0
     end
0
 end
0
+
0
+class OpenWFE::InFlowWorkItem
0
+
0
+ #
0
+ # Returns the 'ruote-rest' link for this workitem
0
+ #
0
+ def link (request=nil)
0
+
0
+ return request.link(:workitems, db_id) if request
0
+
0
+ "/workitems/#{db_id}"
0
+ end
0
+end
...
59
60
61
62
 
63
64
65
66
67
68
 
69
70
71
...
59
60
61
 
62
63
64
65
66
67
 
68
69
70
71
0
@@ -59,13 +59,13 @@
0
     fields = JSON.parse(request.params['fields'])
0
 
0
     if pdef.strip != ""
0
- li = OpenWFE::LaunchItem.new url
0
+ li = OpenWFE::LaunchItem.new pdef
0
     else
0
         li = OpenWFE::LaunchItem.new
0
         li.workflow_definition_url = url
0
     end
0
 
0
- li.fields = fields
0
+ li.attributes.merge! fields
0
 
0
     li
0
 end
...
38
39
40
41
42
 
43
44
 
 
45
46
47
 
48
 
 
49
50
51
 
52
53
 
54
55
56
57
58
59
60
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
63
64
65
66
67
 
68
69
70
71
72
73
 
 
 
 
 
 
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
...
38
39
40
 
 
41
42
 
43
44
45
 
 
46
47
48
49
50
 
 
51
52
 
53
54
 
 
 
 
 
 
 
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 
79
 
80
81
 
 
 
 
 
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
0
@@ -38,39 +38,74 @@
0
 #
0
 
0
 
0
-#
0
-# IN
0
+helpers do
0
 
0
-def parse_workitem_xml (xml)
0
+ #
0
+ # IN
0
 
0
- OpenWFE::Xml.workitem_from_xml xml
0
-end
0
+ def parse_workitem_xml (xml)
0
 
0
+ OpenWFE::Xml.workitem_from_xml xml
0
+ end
0
 
0
-#
0
-# OUT
0
+ def parse_workitem_form (x)
0
 
0
-def render_workitems_xml (wis)
0
+ wi = OpenWFE::InFlowWorkItem.new
0
 
0
- builder do |xml|
0
- xml.instruct!
0
- xml.workitems :count => wis.size do
0
- wis.each do |wi|
0
- owi = wi.as_owfe_workitem
0
- owi._uri = request.link(:workitems, wi.id)
0
- OpenWFE::Xml._workitem_to_xml xml, owi
0
+ wi.attributes = JSON.parse(params[:attributes])
0
+
0
+ wi._state = 'proceeded' if params[:proceed] == 'proceed'
0
+
0
+ wi
0
+ end
0
+
0
+
0
+ #
0
+ # OUT
0
+
0
+ def render_workitems_xml (wis)
0
+
0
+ builder do |xml|
0
+ xml.instruct!
0
+ xml.workitems :count => wis.size do
0
+ wis.each do |wi|
0
+ owi = wi.as_owfe_workitem
0
+ owi._uri = request.link(:workitems, wi.id)
0
+ OpenWFE::Xml._workitem_to_xml xml, owi
0
+ end
0
             end
0
         end
0
     end
0
-end
0
 
0
-def render_workitem_xml (wi)
0
+ def render_workitem_xml (wi)
0
 
0
- builder do |xml|
0
- xml.instruct!
0
- owi = wi.as_owfe_workitem
0
- owi._uri = request.link(:workitems, wi.id)
0
- OpenWFE::Xml._workitem_to_xml xml, owi
0
+ builder do |xml|
0
+ xml.instruct!
0
+ owi = wi.as_owfe_workitem
0
+ owi._uri = request.link(:workitems, wi.id)
0
+ OpenWFE::Xml._workitem_to_xml xml, owi
0
+ end
0
     end
0
+
0
+ def render_workitems_html (wis)
0
+
0
+ @workitems = wis.sort_by { |wi| wi.participant_name }
0
+ @workitems = @workitems.collect { |wi| wi.as_owfe_workitem }
0
+
0
+ _erb :workitems, :layout => :html
0
+ end
0
+
0
+ def render_workitem_html (wi, detailed=true)
0
+
0
+ @workitem = wi
0
+ @workitem = wi.as_owfe_workitem if wi.is_a?(OpenWFE::Extras::Workitem)
0
+
0
+ @detailed = detailed
0
+
0
+ layout = @detailed ? :html : nil
0
+
0
+ _erb :workitem, :layout => layout
0
+ end
0
+
0
 end
...
59
60
61
 
 
62
63
64
65
...
92
93
94
 
95
96
97
98
99
100
 
 
101
102
103
...
59
60
61
62
63
64
65
66
67
...
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
0
@@ -59,6 +59,8 @@
0
 
0
     if state == 'proceeded'
0
 
0
+ owi.fei = wi.full_fei
0
+
0
         $engine.reply owi
0
         wi.destroy
0
 
0
0
@@ -92,12 +94,15 @@
0
 
0
         #pname = params[:pname]
0
         sn = get_store_names
0
+ wfid = params[:wfid]
0
         q = params[:q]
0
 
0
         if q
0
             OpenWFE::Extras::Workitem.search q, sn
0
         elsif sn
0
             OpenWFE::Extras::Workitem.find_in_stores sn
0
+ elsif wfid
0
+ OpenWFE::Extras::Workitem.find_all_by_wfid wfid
0
         else
0
             OpenWFE::Extras::Workitem.find :all
0
         end
...
1
2
3
4
5
 
6
7
...
1
2
3
 
4
5
6
7
0
@@ -1,8 +1,8 @@
0
 
0
 class Test0 < OpenWFE::ProcessDefinition
0
     sequence do
0
- alpha
0
         bravo
0
+ alpha
0
     end
0
 end
...
29
30
31
32
 
33
34
35
...
56
57
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
60
61
...
29
30
31
 
32
33
34
35
...
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
0
@@ -29,7 +29,7 @@
0
 
0
     def test_0
0
 
0
- $engine.launch <<-EOS
0
+ fei = $engine.launch <<-EOS
0
             class Test0 < OpenWFE::ProcessDefinition
0
                 sequence do
0
                     alpha
0
@@ -56,6 +56,21 @@
0
         workitem = OpenWFE::Xml.workitem_from_xml @response.body
0
 
0
         assert_equal workitems.first._uri, workitem._uri
0
+
0
+ #
0
+ # get /workitems?wfid=x
0
+
0
+ get_it "/workitems?wfid=#{fei.wfid}"
0
+
0
+ workitems = OpenWFE::Xml.workitems_from_xml @response.body
0
+
0
+ assert_equal 1, workitems.size
0
+
0
+ get_it "/workitems?wfid=#{fei.wfid}nada"
0
+
0
+ workitems = OpenWFE::Xml.workitems_from_xml @response.body
0
+
0
+ assert_equal 0, workitems.size
0
 
0
         #
0
         # save workitem
...
1
2
3
 
 
 
 
 
4
5
6
...
1
2
 
3
4
5
6
7
8
9
10
0
@@ -1,6 +1,10 @@
0
 <hr/>
0
 <div class="footer">
0
- <a href="/processes">GET /processes</a> | <a href="/participants">GET /participants</a> | <a href="/workitems">GET /workitems</a> | GET /errors
0
+ GET /definitions |
0
+ <a href="/processes">GET /processes</a> |
0
+ <a href="/participants">GET /participants</a> |
0
+ <a href="/workitems">GET /workitems</a> |
0
+ GET /errors
0
 </div>
0
 
0
 </body>
...
28
29
30
 
 
 
31
32
33
...
28
29
30
31
32
33
34
35
36
0
@@ -28,6 +28,9 @@
0
             .participant {
0
                 margin-top: 10px;
0
             }
0
+ .workitem {
0
+ margin-top: 10px;
0
+ }
0
         </style>
0
     </head>
0
 
...
 
1
2
3
4
5
6
...
19
20
21
22
23
24
 
25
26
 
 
 
 
 
 
27
28
29
30
31
32
33
 
34
35
36
...
1
2
3
4
5
6
7
...
20
21
22
 
23
24
25
26
 
27
28
29
30
31
32
33
34
35
36
37
38
 
39
40
41
42
0
@@ -1,3 +1,4 @@
0
+
0
 <h4>GET /processes</h4>
0
 
0
 <div class="explanation">listing all the processes currently running</div>
0
0
0
0
@@ -19,18 +20,23 @@
0
         <div><input
0
             name="pdef_url"
0
             type="text"
0
- value="public/process_definitions/sequence0.rb"
0
             size="50"
0
         /> (url)</div>
0
+ <!--value="public/process_definitions/sequence0.rb" -->
0
         or
0
- <div><textarea name="pdef"></textarea> (definition)</div>
0
+ <div><textarea name="pdef" cols="40" rows="7">class Test0 &lt; OpenWFE::ProcessDefinition
0
+ sequence do
0
+ participant ref="alpha"
0
+ participant ref="bravo"
0
+ end
0
+end</textarea> (definition)</div>
0
     </div>
0
 
0
     <br/>
0
     <br/>
0
 
0
     <div>initial payload :<br/>
0
- <div><textarea name="fields"">{ "key0": "value0", "key1": "value1" }</textarea> (json)</div>
0
+ <div><textarea name="fields" cols="40" rows="4">{ "key0": "value0", "key1": "value1" }</textarea> (json)</div>
0
     </div>
0
     <div><input type="submit" name="launch" value="launch"></div>
0
 </form>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
0
@@ -1 +1,33 @@
0
+
0
+<div class="workitem">
0
+
0
+ <div class="workitem_link"><a href="<%= @workitem.link %>">GET <%= @workitem.link %></a></div>
0
+
0
+ <%= @detailed ? "<br/>" : "" %>
0
+
0
+ <div>participant : <span class="workitem_participant"><%= @workitem.participant_name %></span></div>
0
+ <div>dispatch time : <span class="workitem_dispatch_time"><%= display_time @workitem, :dispatch_time %></span></div>
0
+
0
+ <% if @detailed %>
0
+
0
+ <div>last modified : <span class="workitem_last_modified"><%= display_time @workitem, :last_modified %></span></div>
0
+
0
+ <br/>
0
+
0
+ <form action="<%= @workitem.link %>" method="POST" enctype="multipart/form-data">
0
+ <input type="hidden" name="_method" value="PUT" />
0
+
0
+ attributes :<br/>
0
+ <textarea name="attributes" cols="80" rows="24"><%= @workitem.attributes.to_json.to_s %></textarea>(json)<br/>
0
+
0
+ proceed : <input type="checkbox" name="proceed" value="proceed" /><br/>
0
+
0
+ <br/>
0
+
0
+ <input type="submit" value="PUT <%= @workitem.link %>" />
0
+ </form>
0
+
0
+ <% end %>
0
+
0
+</div>
...
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
0
@@ -1 +1,9 @@
0
+
0
+<h4>GET /workitems</h4>
0
+
0
+<div class="explanation">the workitems waiting for [human] intervention</div>
0
+
0
+<% @workitems.each do |wi| %>
0
+ <%= render_workitem_html wi, false %>
0
+<% end %>

Comments

    No one has commented yet.