cpee 1.3.181 → 1.3.183

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/cockpit/css/ui.css +19 -60
  3. data/cockpit/css/wfadaptor.css +11 -0
  4. data/cockpit/index.html +45 -71
  5. data/cockpit/js/details.js +50 -139
  6. data/cockpit/js/instance.js +133 -185
  7. data/cockpit/js/parameters.js +57 -55
  8. data/cockpit/js/ui.js +4 -29
  9. data/cockpit/js/wfadaptor.js +190 -108
  10. data/cockpit/rngs/attributes.rng +8 -0
  11. data/cockpit/rngs/dataelements.rng +8 -0
  12. data/cockpit/rngs/endpoints.rng +8 -0
  13. data/cockpit/testsets/Concurrent.xml +6 -6
  14. data/cockpit/testsets/Coopis Testset.xml +12 -12
  15. data/cockpit/testsets/ICSOC Testset.xml +27 -27
  16. data/cockpit/testsets/Infinity.xml +4 -4
  17. data/cockpit/testsets/Linear.xml +10 -10
  18. data/cockpit/testsets/Mangler 1.xml +20 -20
  19. data/cockpit/testsets/Mangler 2.xml +18 -18
  20. data/cockpit/testsets/Promise.xml +258 -0
  21. data/cockpit/testsets/SOPROMO Test Sonification.xml +11 -11
  22. data/cockpit/testsets/Syncing P34 1.xml +12 -12
  23. data/cockpit/testsets/Syncing P34 2.xml +12 -12
  24. data/cockpit/testsets/Syncing P34 3.xml +12 -12
  25. data/cockpit/testsets/Syncing P34.xml +12 -12
  26. data/cockpit/testsets/TEST - Bad Loop.xml +39 -39
  27. data/cockpit/testsets/Update.xml +1 -1
  28. data/cockpit/testsets/Worklist Parallel.xml +8 -8
  29. data/cockpit/testsets/Worklist Test CPEE.xml +2 -2
  30. data/cockpit/testsets/Worklist Test.xml +2 -2
  31. data/cockpit/testsets/testsets.xml +2 -0
  32. data/cockpit/themes/adventure/rngs/alternative.rng +5 -0
  33. data/cockpit/themes/adventure/rngs/call.rng +29 -0
  34. data/cockpit/{rngtest2.rng → themes/adventure/rngs/callmanipulate.rng} +9 -9
  35. data/cockpit/themes/adventure/rngs/choose.rng +8 -0
  36. data/cockpit/themes/adventure/rngs/critical.rng +5 -0
  37. data/cockpit/themes/adventure/rngs/escape.rng +1 -0
  38. data/cockpit/themes/adventure/rngs/finalize.rng +6 -0
  39. data/cockpit/themes/adventure/rngs/group.rng +3 -0
  40. data/cockpit/themes/adventure/rngs/loop.rng +11 -0
  41. data/cockpit/themes/adventure/rngs/manipulate.rng +6 -0
  42. data/cockpit/themes/adventure/rngs/otherwise.rng +1 -0
  43. data/cockpit/themes/adventure/rngs/parallel.rng +5 -0
  44. data/cockpit/themes/adventure/rngs/parallel_branch.rng +8 -0
  45. data/cockpit/themes/adventure/rngs/update.rng +6 -0
  46. data/cockpit/themes/adventure/symbols/alternative.svg +4 -0
  47. data/cockpit/themes/adventure/symbols/call.svg +4 -0
  48. data/cockpit/themes/adventure/symbols/callmanipulate.svg +6 -0
  49. data/cockpit/themes/adventure/symbols/choose.svg +5 -0
  50. data/cockpit/themes/adventure/symbols/choose_exclusive.svg +5 -0
  51. data/cockpit/themes/adventure/symbols/choose_inclusive.svg +4 -0
  52. data/cockpit/themes/adventure/symbols/critical.svg +4 -0
  53. data/cockpit/themes/adventure/symbols/escape.svg +5 -0
  54. data/cockpit/themes/adventure/symbols/loop.svg +5 -0
  55. data/cockpit/themes/adventure/symbols/manipulate.svg +4 -0
  56. data/cockpit/themes/adventure/symbols/otherwise.svg +4 -0
  57. data/cockpit/themes/adventure/symbols/parallel.svg +5 -0
  58. data/cockpit/themes/adventure/symbols/parallel_branch.svg +4 -0
  59. data/cockpit/themes/adventure/symbols/scripts.svg +4 -0
  60. data/cockpit/themes/adventure/symbols/start.svg +3 -0
  61. data/cockpit/themes/adventure/theme.js +729 -0
  62. data/cockpit/themes/default/rngs/alternative.rng +5 -0
  63. data/cockpit/themes/default/rngs/call.rng +29 -0
  64. data/cockpit/themes/default/rngs/callmanipulate.rng +41 -0
  65. data/cockpit/themes/default/rngs/choose.rng +8 -0
  66. data/cockpit/themes/default/rngs/critical.rng +5 -0
  67. data/cockpit/themes/default/rngs/escape.rng +1 -0
  68. data/cockpit/themes/default/rngs/finalize.rng +6 -0
  69. data/cockpit/themes/default/rngs/group.rng +3 -0
  70. data/cockpit/themes/default/rngs/loop.rng +11 -0
  71. data/cockpit/themes/default/rngs/manipulate.rng +6 -0
  72. data/cockpit/themes/default/rngs/otherwise.rng +1 -0
  73. data/cockpit/themes/default/rngs/parallel.rng +5 -0
  74. data/cockpit/themes/default/rngs/parallel_branch.rng +8 -0
  75. data/cockpit/themes/default/rngs/update.rng +6 -0
  76. data/cockpit/themes/default/symbols/alternative.svg +4 -0
  77. data/cockpit/themes/default/symbols/call.svg +4 -0
  78. data/cockpit/themes/default/symbols/callmanipulate.svg +6 -0
  79. data/cockpit/themes/default/symbols/choose.svg +5 -0
  80. data/cockpit/themes/default/symbols/choose_exclusive.svg +5 -0
  81. data/cockpit/themes/default/symbols/choose_inclusive.svg +4 -0
  82. data/cockpit/themes/default/symbols/critical.svg +4 -0
  83. data/cockpit/themes/default/symbols/escape.svg +5 -0
  84. data/cockpit/themes/default/symbols/loop.svg +5 -0
  85. data/cockpit/themes/default/symbols/manipulate.svg +4 -0
  86. data/cockpit/themes/default/symbols/otherwise.svg +4 -0
  87. data/cockpit/themes/default/symbols/parallel.svg +5 -0
  88. data/cockpit/themes/default/symbols/parallel_branch.svg +4 -0
  89. data/cockpit/themes/default/symbols/scripts.svg +4 -0
  90. data/cockpit/themes/default/symbols/start.svg +3 -0
  91. data/cockpit/themes/default/theme.js +729 -0
  92. data/cockpit/themes/lego/rngs/alternative.rng +5 -0
  93. data/cockpit/themes/lego/rngs/call.rng +41 -0
  94. data/cockpit/themes/lego/rngs/choose.rng +8 -0
  95. data/cockpit/themes/lego/rngs/critical.rng +5 -0
  96. data/cockpit/themes/lego/rngs/loop.rng +11 -0
  97. data/cockpit/themes/lego/rngs/manipulate.rng +6 -0
  98. data/cockpit/themes/lego/rngs/parallel.rng +5 -0
  99. data/cockpit/themes/lego/rngs/parallel_branch.rng +8 -0
  100. data/cockpit/themes/lego/symbols/alternative.svg +4 -0
  101. data/cockpit/themes/lego/symbols/call.svg +4 -0
  102. data/cockpit/themes/lego/symbols/callmanipulate.svg +6 -0
  103. data/cockpit/themes/lego/symbols/callori.svg +4 -0
  104. data/cockpit/themes/lego/symbols/choose.svg +4 -0
  105. data/cockpit/themes/lego/symbols/choose_exclusive.svg +5 -0
  106. data/cockpit/themes/lego/symbols/choose_inclusive.svg +4 -0
  107. data/cockpit/themes/lego/symbols/critical.svg +4 -0
  108. data/cockpit/themes/lego/symbols/escape.svg +5 -0
  109. data/cockpit/themes/lego/symbols/lego.svg +72 -0
  110. data/cockpit/themes/lego/symbols/loop.svg +5 -0
  111. data/cockpit/themes/lego/symbols/manipulate.svg +4 -0
  112. data/cockpit/themes/lego/symbols/otherwise.svg +4 -0
  113. data/cockpit/themes/lego/symbols/parallel.svg +6 -0
  114. data/cockpit/themes/lego/symbols/parallel_branch.svg +4 -0
  115. data/cockpit/themes/lego/symbols/scripts.svg +4 -0
  116. data/cockpit/themes/lego/symbols/start.svg +3 -0
  117. data/cockpit/themes/lego/theme.js +742 -0
  118. data/cockpit/themes/promise/rngs/alternative.rng +5 -0
  119. data/cockpit/themes/promise/rngs/call.rng +41 -0
  120. data/cockpit/themes/promise/rngs/choose.rng +8 -0
  121. data/cockpit/themes/promise/rngs/critical.rng +5 -0
  122. data/cockpit/themes/promise/rngs/loop.rng +11 -0
  123. data/cockpit/themes/promise/rngs/manipulate.rng +6 -0
  124. data/cockpit/themes/promise/rngs/parallel.rng +5 -0
  125. data/cockpit/themes/promise/rngs/parallel_branch.rng +8 -0
  126. data/cockpit/themes/promise/symbols/alternative.svg +4 -0
  127. data/cockpit/themes/promise/symbols/call.svg +4 -0
  128. data/cockpit/themes/promise/symbols/callmanipulate.svg +6 -0
  129. data/cockpit/themes/promise/symbols/choose.svg +4 -0
  130. data/cockpit/themes/promise/symbols/choose_exclusive.svg +5 -0
  131. data/cockpit/themes/promise/symbols/choose_inclusive.svg +4 -0
  132. data/cockpit/themes/promise/symbols/critical.svg +4 -0
  133. data/cockpit/themes/promise/symbols/escape.svg +5 -0
  134. data/cockpit/themes/promise/symbols/loop.svg +5 -0
  135. data/cockpit/themes/promise/symbols/manipulate.svg +4 -0
  136. data/cockpit/themes/promise/symbols/otherwise.svg +4 -0
  137. data/cockpit/themes/promise/symbols/parallel.svg +6 -0
  138. data/cockpit/themes/promise/symbols/parallel_branch.svg +4 -0
  139. data/cockpit/themes/promise/symbols/preminder.svg +6 -0
  140. data/cockpit/themes/promise/symbols/scripts.svg +4 -0
  141. data/cockpit/themes/promise/symbols/start.svg +3 -0
  142. data/cockpit/themes/promise/theme.js +742 -0
  143. data/cpee.gemspec +2 -2
  144. data/lib/cpee/implementation.rb +15 -15
  145. data/server/handlerwrappers/default.rb +19 -19
  146. data/server/handlerwrappers/log.rb +264 -0
  147. data/server/instances/10/properties.xml +148 -0
  148. data/server/instances/11/properties.xml +149 -0
  149. data/server/instances/12/properties.xml +149 -0
  150. data/server/instances/13/properties.xml +149 -0
  151. data/server/instances/14/properties.xml +111 -0
  152. data/server/instances/15/properties.xml +113 -0
  153. data/server/instances/16/properties.xml +113 -0
  154. data/server/instances/17/properties.xml +149 -0
  155. data/server/instances/18/properties.xml +149 -0
  156. data/server/instances/19/properties.xml +114 -0
  157. data/server/instances/2/properties.xml +1 -1
  158. data/server/instances/20/properties.xml +113 -0
  159. data/server/instances/21/notifications/0851248d60c898cadd743d0dd5b6d273/consumer-secret +1 -0
  160. data/server/instances/21/notifications/0851248d60c898cadd743d0dd5b6d273/producer-secret +1 -0
  161. data/server/instances/21/notifications/0851248d60c898cadd743d0dd5b6d273/subscription.xml +6 -0
  162. data/server/instances/21/notifications/b7bac3f3010d433ce5d8f29338a06f9a/consumer-secret +1 -0
  163. data/server/instances/21/notifications/b7bac3f3010d433ce5d8f29338a06f9a/producer-secret +1 -0
  164. data/server/instances/21/notifications/b7bac3f3010d433ce5d8f29338a06f9a/subscription.xml +23 -0
  165. data/server/instances/21/properties.xml +149 -0
  166. data/server/instances/22/properties.xml +113 -0
  167. data/server/instances/23/properties.xml +88 -0
  168. data/server/instances/24/properties.xml +168 -0
  169. data/server/instances/25/properties.xml +149 -0
  170. data/server/instances/26/properties.xml +113 -0
  171. data/server/instances/27/properties.xml +141 -0
  172. data/server/instances/3/properties.xml +46 -0
  173. data/server/instances/4/properties.xml +148 -0
  174. data/server/instances/5/properties.xml +148 -0
  175. data/server/instances/6/properties.xml +148 -0
  176. data/server/instances/7/properties.xml +148 -0
  177. data/server/instances/8/properties.xml +148 -0
  178. data/server/instances/9/properties.xml +46 -0
  179. data/server/resources/properties.init +2 -1
  180. data/server/resources/transformation_dslx.xsl +12 -12
  181. data/server/server.pid +1 -0
  182. data/server/server.rb +2 -0
  183. metadata +152 -12
  184. data/cockpit/js/wfadaptor.cpee.js +0 -936
  185. data/cockpit/rngtest1.html +0 -53
  186. data/cockpit/rngtest1.rng +0 -38
  187. data/cockpit/rngtest1.xml +0 -16
  188. data/cockpit/rngtest2.html +0 -53
  189. data/cockpit/rngtest2.xml +0 -11
  190. data/cockpit/test.html +0 -46
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cpee"
3
- s.version = "1.3.181"
3
+ s.version = "1.3.183"
4
4
  s.platform = Gem::Platform::RUBY
5
- s.license = "LGPL-3"
5
+ s.license = "LGPL-3.0"
6
6
  s.summary = "Preliminary release of cloud process execution engine (cpee). If you just need workflow execution, without a rest/xmpp service exposing it, then use WEEL"
7
7
 
8
8
  s.description = "see http://cpee.org"
@@ -1,13 +1,13 @@
1
1
  # This file is part of CPEE.
2
- #
2
+ #
3
3
  # CPEE is free software: you can redistribute it and/or modify it under the terms
4
4
  # of the GNU General Public License as published by the Free Software Foundation,
5
5
  # either version 3 of the License, or (at your option) any later version.
6
- #
6
+ #
7
7
  # CPEE is distributed in the hope that it will be useful, but WITHOUT ANY
8
8
  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
9
9
  # PARTICULAR PURPOSE. See the GNU General Public License for more details.
10
- #
10
+ #
11
11
  # You should have received a copy of the GNU General Public License along with
12
12
  # CPEE (file COPYING in the main directory). If not, see
13
13
  # <http://www.gnu.org/licenses/>.
@@ -37,7 +37,7 @@ module CPEE
37
37
  opts[:empty_dslx] ||= File.expand_path(File.dirname(__FILE__) + '/../../server/resources/empty_dslx.xml')
38
38
  opts[:infinite_loop_stop] ||= 10000
39
39
 
40
- opts[:runtime_options] << [
40
+ opts[:runtime_options] << [
41
41
  "startclean", "Delete instances before starting.", Proc.new { |status|
42
42
  Dir.glob(File.expand_path(File.dirname(__FILE__) + '/../../server/instances/*')).each do |d|
43
43
  FileUtils.rm_r(d) if File.basename(d) =~ /^\d+$/
@@ -56,13 +56,13 @@ module CPEE
56
56
  controller = {}
57
57
  Dir[opts[:instances] + '/*/properties.xml'].each do |e|
58
58
  id = ::File::basename(::File::dirname(e))
59
- controller[id.to_i] = Controller.new(id,opts)
59
+ (controller[id.to_i] = Controller.new(id,opts)) rescue nil
60
60
  end
61
61
 
62
62
  interface 'properties' do |r|
63
63
  id = r[:h]['RIDDL_DECLARATION_PATH'].split('/')[1].to_i
64
64
  use Riddl::Utils::Properties::implementation(controller[id].properties, PropertiesHandler.new(controller[id]), opts[:mode]) if controller[id]
65
- end
65
+ end
66
66
 
67
67
  interface 'main' do
68
68
  run CPEE::Instances, controller if get '*'
@@ -74,17 +74,17 @@ module CPEE
74
74
  run CPEE::Callbacks, controller, opts if get
75
75
  on resource do
76
76
  run CPEE::ExCallback, controller if get || put || post || delete
77
- end
78
- end
79
- end
77
+ end
78
+ end
79
+ end
80
80
  end
81
81
 
82
82
  interface 'notifications' do |r|
83
83
  id = r[:h]['RIDDL_DECLARATION_PATH'].split('/')[1].to_i
84
84
  use Riddl::Utils::Notifications::Producer::implementation(controller[id].notifications, NotificationsHandler.new(controller[id]), opts[:mode]) if controller[id]
85
85
  end
86
- end
87
- end
86
+ end
87
+ end
88
88
 
89
89
  class ExCallback < Riddl::Implementation #{{{
90
90
  def response
@@ -95,7 +95,7 @@ module CPEE
95
95
  if controller[id].callbacks.has_key?(callback)
96
96
  controller[id].callbacks[callback].callback(@p,@h)
97
97
  end
98
- end
98
+ end
99
99
  end
100
100
  end #}}}
101
101
 
@@ -113,10 +113,10 @@ module CPEE
113
113
  if opts[:mode] == :debug
114
114
  controller[id].callbacks.each do |k,v|
115
115
  cb.root.add("callback",{"id" => k},"[#{v.protocol.to_s}] #{v.info}")
116
- end
116
+ end
117
117
  end
118
118
  cb.to_s
119
- end
119
+ end
120
120
  end
121
121
  end #}}}
122
122
 
@@ -146,7 +146,7 @@ module CPEE
146
146
  id += 1
147
147
  Dir.mkdir(opts[:instances] + "/#{id}") rescue nil
148
148
  break
149
- end
149
+ end
150
150
  controller[id] = Controller.new(id,opts)
151
151
  info = controller[id].properties.data.find("/p:properties/p:attributes/p:info")
152
152
  info.first.text = name if info.length == 1
@@ -29,16 +29,16 @@ class DefaultHandlerWrapper < WEEL::HandlerWrapperBase
29
29
  if passthrough.nil?
30
30
  params = []
31
31
  callback = Digest::MD5.hexdigest(Kernel::rand().to_s)
32
- (parameters[:parameters] || {}).each do |k,v|
33
- if v.is_a?(Struct)
32
+ (parameters[:arguments] || {}).each do |k,v|
33
+ if v.is_a?(Struct)
34
34
  if v.respond_to?(:mimetype)
35
35
  params << Riddl::Parameter::Complex.new("#{k}",v.mimetype,v.value)
36
- else
36
+ else
37
37
  params << Riddl::Parameter::Simple.new("#{k}",CPEE::ValueHelper::generate(v.value))
38
- end
38
+ end
39
39
  else
40
40
  params << Riddl::Parameter::Simple.new("#{k}",CPEE::ValueHelper::generate(v))
41
- end
41
+ end
42
42
  end
43
43
  params << Riddl::Header.new("CPEE_BASE",@controller.base_url)
44
44
  params << Riddl::Header.new("CPEE_INSTANCE",@controller.instance_url)
@@ -47,7 +47,7 @@ class DefaultHandlerWrapper < WEEL::HandlerWrapperBase
47
47
  params << Riddl::Header.new("CPEE_LABEL",parameters[:label])
48
48
  @controller.attributes.each do |key,value|
49
49
  params << Riddl::Header.new("CPEE_ATTR_#{key}",value)
50
- end
50
+ end
51
51
 
52
52
  type = parameters[:method] || 'post'
53
53
  client = Riddl::Client.new(@handler_endpoint)
@@ -107,7 +107,7 @@ class DefaultHandlerWrapper < WEEL::HandlerWrapperBase
107
107
  unless status.nil?
108
108
  @controller.serialize_status!
109
109
  @controller.notify("status/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :id => status.id, :message => status.message)
110
- end
110
+ end
111
111
  unless changed_dataelements.nil?
112
112
  @controller.serialize_dataelements!
113
113
  @controller.notify("dataelements/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :changed => changed_dataelements)
@@ -115,7 +115,7 @@ class DefaultHandlerWrapper < WEEL::HandlerWrapperBase
115
115
  unless changed_endpoints.nil?
116
116
  @controller.serialize_endpoints!
117
117
  @controller.notify("endpoints/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :changed => changed_endpoints)
118
- end
118
+ end
119
119
  end # }}}
120
120
  def inform_position_change(ipc={}) # {{{
121
121
  @controller.serialize_positions!
@@ -139,25 +139,25 @@ class DefaultHandlerWrapper < WEEL::HandlerWrapperBase
139
139
  def simplify_result(result)
140
140
  if result.length == 1
141
141
  if result[0].is_a? Riddl::Parameter::Simple
142
- result = result[0]
142
+ result = result[0].value
143
143
  elsif result[0].is_a? Riddl::Parameter::Complex
144
- if result[0].mimetype == 'application/json'
145
- result = JSON::parse(result[0].value.read)
144
+ if result[0].mimetype == 'application/json'
145
+ result = JSON::parse(result[0].value.read) rescue nil
146
146
  elsif result[0].mimetype == 'application/xml' || result[0].mimetype == 'text/xml'
147
- result = XML::Smart::string(result[0].value.read)
147
+ result = XML::Smart::string(result[0].value.read) rescue nil
148
148
  elsif result[0].mimetype == 'text/plain'
149
149
  result = result[0].value.read
150
150
  else
151
151
  result = result[0]
152
152
  end
153
153
  end
154
- end
154
+ end
155
155
  result
156
156
  end
157
157
 
158
158
  def callback(result=nil,options={})
159
159
  result = simplify_result(result)
160
- if options['CPEE_UPDATE']
160
+ if options['CPEE_UPDATE']
161
161
  @handler_returnValue = result
162
162
  if options['CPEE_UPDATE_STATUS']
163
163
  @controller.notify("activity/status", :instance => @controller.instance, :activity => @handler_position, :endpoint => @handler_endpoint, :status => options['CPEE_UPDATE_STATUS'])
@@ -174,11 +174,11 @@ class DefaultHandlerWrapper < WEEL::HandlerWrapperBase
174
174
  def simulate(type,nesting,tid,parent,parameters={}) #{{{
175
175
  pp "#{type} - #{nesting} - #{tid} - #{parent} - #{parameters.inspect}"
176
176
 
177
- @controller.call_vote("simulating/step",
178
- :endpoint => @handler_endpoint,
179
- :instance => @controller.instance,
180
- :activity => tid,
181
- :type => type,
177
+ @controller.call_vote("simulating/step",
178
+ :endpoint => @handler_endpoint,
179
+ :instance => @controller.instance,
180
+ :activity => tid,
181
+ :type => type,
182
182
  :nesting => nesting,
183
183
  :parent => parent,
184
184
  :parameters => parameters
@@ -0,0 +1,264 @@
1
+ # This file is part of CPEE.
2
+ #
3
+ # CPEE is free software: you can redistribute it and/or modify it under the terms
4
+ # of the GNU General Public License as published by the Free Software Foundation,
5
+ # either version 3 of the License, or (at your option) any later version.
6
+ #
7
+ # CPEE is distributed in the hope that it will be useful, but WITHOUT ANY
8
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
9
+ # PARTICULAR PURPOSE. See the GNU General Public License for more details.
10
+ #
11
+ # You should have received a copy of the GNU General Public License along with
12
+ # CPEE (file COPYING in the main directory). If not, see
13
+ # <http://www.gnu.org/licenses/>.
14
+
15
+ class PromiseHandlerWrapper < WEEL::HandlerWrapperBase
16
+ def initialize(arguments,endpoint=nil,position=nil,continue=nil) # {{{
17
+ @controller = arguments[0]
18
+ @log_hash = {}
19
+ @handler_continue = continue
20
+ @handler_endpoint = endpoint
21
+ @handler_position = position
22
+ @handler_passthrough = nil
23
+ @handler_returnValue = nil
24
+ instancenr=@controller.instance.split('/').last
25
+ instance_dir = @controller.instance_variable_get(:@opts)[:instances]
26
+ unless File.exist?(instance_dir+'/'+instancenr+'/log.xes')
27
+ FileUtils.cp(instance_dir+'/template.xes', instance_dir+'/'+instancenr+'/log.xes')
28
+ XML::Smart.modify(instance_dir+'/'+instancenr+'/log.xes') do |xml|
29
+ trace = xml.find("/xmlns:log/xmlns:trace").first
30
+ trace.add 'string', :key => "concept:name", :value => "Instance #{instancenr}"
31
+ end
32
+ end
33
+ end # }}}
34
+
35
+ def activity_handle(passthrough, parameters) # {{{
36
+ @controller.notify("activity/calling", :instance => @controller.instance, :activity => @handler_position, :passthrough => passthrough, :endpoint => @handler_endpoint, :parameters => parameters)
37
+ instancenr=@controller.instance.split('/').last
38
+ instance_dir = @controller.instance_variable_get(:@opts)[:instances]
39
+ unless File.exist?(instance_dir+'/'+instancenr+'/log.xes')
40
+ FileUtils.cp(instance_dir+'/template.xes', instance_dir+'/'+instancenr+'/log.xes')
41
+ XML::Smart.modify(instance_dir+'/'+instancenr+'/log.xes') do |xml|
42
+ trace = xml.find("/xmlns:log/xmlns:trace").first
43
+ trace.add 'string', :key => "concept:name", :value => "Instance #{instancenr}"
44
+ end
45
+ end
46
+
47
+ @log_hash[:label]||=parameters[:label]
48
+ @log_hash[:data_send]||=parameters[:arguments] unless parameters[:arguments].nil?
49
+ result = []
50
+ if passthrough.nil?
51
+ params = []
52
+ callback = Digest::MD5.hexdigest(Kernel::rand().to_s)
53
+ (parameters[:arguments] || {}).each do |k,v|
54
+ if v.is_a?(Struct)
55
+ if v.respond_to?(:mimetype)
56
+ params << Riddl::Parameter::Complex.new("#{k}",v.mimetype,v.value)
57
+ else
58
+ params << Riddl::Parameter::Simple.new("#{k}",CPEE::ValueHelper::generate(v.value))
59
+ end
60
+ else
61
+ params << Riddl::Parameter::Simple.new("#{k}",CPEE::ValueHelper::generate(v))
62
+ end
63
+ end
64
+ params << Riddl::Header.new("CPEE_BASE",@controller.base_url)
65
+ params << Riddl::Header.new("CPEE_INSTANCE",@controller.instance_url)
66
+ params << Riddl::Header.new("CPEE_CALLBACK",@controller.instance_url + '/callbacks/' + callback)
67
+ params << Riddl::Header.new("CPEE_ACTIVITY",@handler_position)
68
+ params << Riddl::Header.new("CPEE_LABEL",parameters[:label])
69
+ @controller.attributes.each do |key,value|
70
+ params << Riddl::Header.new("CPEE_ATTR_#{key}",value)
71
+ end
72
+
73
+ type = parameters[:method] || 'post'
74
+ client = Riddl::Client.new(@handler_endpoint)
75
+
76
+ status, result, headers = client.request type => params
77
+ raise "Could not #{parameters[:method] || 'post'} #{@handler_endpoint}" if status != 200
78
+
79
+ if headers["CPEE_CALLBACK"] && headers["CPEE_CALLBACK"] == 'true'
80
+ @controller.callbacks[callback] = CPEE::Callback.new("callback activity: #{@handler_position}",self,:callback,nil,nil,:http)
81
+ @handler_passthrough = callback
82
+ else
83
+ callback result
84
+ end
85
+ else
86
+ @controller.callbacks[passthrough] = CPEE::Callback.new("callback activity: #{@handler_position}",self,:callback,nil,nil,:http)
87
+ @handler_passthrough = passthrough
88
+ end
89
+ end # }}}
90
+
91
+ def activity_result_status # {{{
92
+ WEEL::Status.new(1, "everything okay")
93
+ end # }}}
94
+
95
+ def activity_result_value # {{{
96
+ @handler_returnValue
97
+ end # }}}
98
+
99
+ def activity_stop # {{{
100
+ unless @handler_passthrough.nil?
101
+ @controller.callbacks.delete(@handler_passthrough)
102
+ end
103
+ end # }}}
104
+ def activity_passthrough_value # {{{
105
+ @handler_passthrough
106
+ end # }}}
107
+
108
+ def activity_no_longer_necessary # {{{
109
+ true
110
+ end # }}}
111
+
112
+ def inform_activity_done # {{{
113
+ @controller.notify("activity/done", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
114
+ p "log"
115
+ p @log_hash
116
+ time_added=false
117
+ XML::Smart.modify(@controller.instance_variable_get(:@opts)[:instances]+'/'+@controller.instance.split('/').last+'/log.xes') do |xml|
118
+ trace = xml.find("/xmlns:log/xmlns:trace").first
119
+ event = trace.add "event"
120
+ event.add 'string', :key => "concept:name", :value => @log_hash[:label]
121
+ if @log_hash.has_key?(:data_send)
122
+ list = event.add 'list', :key => "data_send"
123
+ @log_hash[:data_send].each do |k,v|
124
+ list.add 'string', :key => k , :value => v
125
+ end
126
+ end
127
+ if @log_hash.has_key?(:data_received)
128
+ @log_hash[:data_received].delete_if do |e|
129
+ if e.keys[0]=="timestamp"
130
+ event.add 'date', :key => "time:timestamp", :value => e.values[0]
131
+ time_added=true
132
+ true
133
+ else
134
+ false
135
+ end
136
+ end
137
+ if @log_hash[:data_received].length > 0
138
+ list = event.add 'list', :key => "data_received"
139
+ @log_hash[:data_received].each{|e| list.add 'string', :key => e.keys[0] , :value => e.values[0]}
140
+ end
141
+ end
142
+ event.add 'date', :key => "time:timestamp", :value => Time.now unless time_added
143
+ end
144
+
145
+ end # }}}
146
+ def inform_activity_manipulate # {{{
147
+ @controller.notify("activity/manipulating", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
148
+ end # }}}
149
+ def inform_activity_failed(err) # {{{
150
+ puts err.message
151
+ puts err.backtrace
152
+ @controller.notify("activity/failed", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :message => err.message, :line => err.backtrace[0].match(/(.*?):(\d+):/)[2], :where => err.backtrace[0].match(/(.*?):(\d+):/)[1])
153
+ end # }}}
154
+
155
+ def inform_syntax_error(err,code)# {{{
156
+ @controller.notify("description/error", :instance => @controller.instance, :message => err.message)
157
+ end# }}}
158
+ def inform_manipulate_change(status,changed_dataelements,changed_endpoints,dataelements,endpoints) # {{{
159
+ unless status.nil?
160
+ @controller.serialize_status!
161
+ @controller.notify("status/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :id => status.id, :message => status.message)
162
+ end
163
+ unless changed_dataelements.nil?
164
+ @controller.serialize_dataelements!
165
+ @controller.notify("dataelements/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :changed => changed_dataelements)
166
+ end
167
+ unless changed_endpoints.nil?
168
+ @controller.serialize_endpoints!
169
+ @controller.notify("endpoints/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :changed => changed_endpoints)
170
+ end
171
+ end # }}}
172
+ def inform_position_change(ipc={}) # {{{
173
+ @controller.serialize_positions!
174
+ ipc[:instance] = @controller.instance
175
+ @controller.notify("position/change", ipc)
176
+ end # }}}
177
+ def inform_state_change(newstate) # {{{
178
+ if @controller
179
+ @controller.serialize_state!
180
+ @controller.notify("state/change", :instance => @controller.instance, :state => newstate)
181
+ end
182
+ end # }}}
183
+
184
+ def vote_sync_after # {{{
185
+ @controller.call_vote("activity/syncing_after", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
186
+ end # }}}
187
+ def vote_sync_before(parameters=nil) # {{{
188
+ @controller.call_vote("activity/syncing_before", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
189
+ end # }}}
190
+
191
+ def simplify_result(result)
192
+ tmp = result.map do |r|
193
+ if r.is_a? Riddl::Parameter::Simple
194
+ {r.name => r.value}
195
+ elsif r.is_a? Riddl::Parameter::Complex
196
+ if r.mimetype == 'application/json'
197
+ x = JSON::parse(r.value.read)
198
+ r.value.rewind
199
+ x
200
+ elsif r.mimetype == 'application/xml' || r.mimetype == 'text/xml'
201
+ x = {"xml" => XML::Smart::string(result[0].value.read)}
202
+ x
203
+ elsif r.mimetype == 'text/plain'
204
+ {"plain_text" => r.value.read}
205
+ elsif r.mimetype == 'text/html'
206
+ {"html_text" => r.value.read}
207
+ else
208
+ r
209
+ end
210
+ end
211
+ end
212
+ if result.length == 1
213
+ if result[0].is_a? Riddl::Parameter::Simple
214
+ result = result[0].value
215
+ elsif result[0].is_a? Riddl::Parameter::Complex
216
+ if result[0].mimetype == 'application/json'
217
+ result = JSON::parse(result[0].value.read)
218
+ elsif result[0].mimetype == 'application/xml' || result[0].mimetype == 'text/xml'
219
+ result = XML::Smart::string(result[0].value.read)
220
+ elsif result[0].mimetype == 'text/plain'
221
+ result = result[0].value.read
222
+ elsif result[0].mimetype == 'text/html'
223
+ result[0].value.read
224
+ else
225
+ result = result[0]
226
+ end
227
+ end
228
+ end
229
+ [result,tmp]
230
+ end
231
+
232
+ def callback(result=nil,options={})
233
+ result,notify_result = simplify_result(result)
234
+ pp result
235
+ @controller.notify("activity/change", :instance => @controller.instance, :activity => @handler_position, :endpoint => @handler_endpoint, :params => notify_result)
236
+ @log_hash[:data_received]||=notify_result unless notify_result.nil?
237
+ if options['CPEE_UPDATE']
238
+ @handler_returnValue = result
239
+ if options['CPEE_UPDATE_STATUS']
240
+ @controller.notify("activity/status", :instance => @controller.instance, :activity => @handler_position, :endpoint => @handler_endpoint, :status => options['CPEE_UPDATE_STATUS'])
241
+ end
242
+ @handler_continue.continue WEEL::Signal::Again
243
+ else
244
+ @controller.callbacks.delete(@handler_passthrough)
245
+ @handler_returnValue = result
246
+ @handler_passthrough = nil
247
+ @handler_continue.continue
248
+ end
249
+ end
250
+
251
+ def simulate(type,nesting,tid,parent,parameters={}) #{{{
252
+ pp "#{type} - #{nesting} - #{tid} - #{parent} - #{parameters.inspect}"
253
+
254
+ @controller.call_vote("simulating/step",
255
+ :endpoint => @handler_endpoint,
256
+ :instance => @controller.instance,
257
+ :activity => tid,
258
+ :type => type,
259
+ :nesting => nesting,
260
+ :parent => parent,
261
+ :parameters => parameters
262
+ )
263
+ end #}}}
264
+ end