openwferu-extras 0.9.13 → 0.9.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,12 +43,15 @@ require_gem 'activerecord'
43
43
 
44
44
  require 'openwfe/workitem'
45
45
  require 'openwfe/flowexpressionid'
46
+ require 'openwfe/engine/engine'
46
47
  require 'openwfe/participants/participant'
47
48
 
48
49
 
49
50
  module OpenWFE
50
51
  module Extras
51
52
 
53
+ MUTEX = Mutex.new
54
+
52
55
  #
53
56
  # The migration for ActiveParticipant and associated classes.
54
57
  #
@@ -70,14 +73,19 @@ module Extras
70
73
  t.column :wf_name, :string
71
74
  t.column :wf_revision, :string
72
75
  t.column :participant_name, :string
73
- t.column :store, :string
76
+ t.column :store_name, :string
77
+ t.column :dispatch_time, :timestamp
78
+ t.column :last_modified, :timestamp
74
79
  end
75
80
  create_table :fields do |t|
76
81
  t.column :key, :string, :null => false
77
- t.column :value, :text
82
+ t.column :svalue, :string
83
+ t.column :yvalue, :text
78
84
  t.column :workitem_id, :integer, :null => false
79
85
  end
80
- add_index :fields, [ :workitem_id, :key], :unique => true
86
+ add_index :fields, [ :workitem_id, :key ], :unique => true
87
+ add_index :fields, :key
88
+ add_index :fields, :svalue
81
89
  end
82
90
  def self.down
83
91
  drop_table :workitems
@@ -132,25 +140,35 @@ module Extras
132
140
  #
133
141
  # This is a 'static' method :
134
142
  #
135
- # awi = OpenWFE::Densha::Workitem.from_owfe_workitem(wi)
143
+ # awi = OpenWFE::Extras::Workitem.from_owfe_workitem(wi)
136
144
  #
137
145
  # (This method will not save the 'ActiveWorkitem').
138
146
  #
139
- def self.from_owfe_workitem (wi)
147
+ def Workitem.from_owfe_workitem (wi, store_name=nil)
148
+
149
+ i = nil
150
+
151
+ MUTEX.synchronize do
152
+
153
+ i = Workitem.new
154
+ i.fei = wi.fei.to_s
155
+ i.wfid = wi.fei.wfid
156
+ i.wf_name = wi.fei.workflow_definition_name
157
+ i.wf_revision = wi.fei.workflow_definition_revision
158
+ i.participant_name = wi.participant_name
159
+ i.dispatch_time = wi.dispatch_time
160
+ i.last_modified = nil
161
+
162
+ i.store_name = store_name
140
163
 
141
- i = Workitem.new
142
- i.fei = wi.fei.to_s
143
- i.wfid = wi.fei.wfid
144
- i.wf_name = wi.fei.workflow_definition_name
145
- i.wf_revision = wi.fei.workflow_definition_revision
146
- i.participant_name = wi.participant_name
164
+ wi.attributes.each do |k, v|
165
+ i.fields << Field.new_field(k, v)
166
+ end
167
+
168
+ i.save!
147
169
 
148
- wi.attributes.each do |k, v|
149
- f = Field.new
150
- f.key = k
151
- f.value = v
152
- i.fields << f
153
170
  end
171
+
154
172
  i
155
173
  end
156
174
 
@@ -163,6 +181,7 @@ module Extras
163
181
  wi.fei = full_fei
164
182
  wi.participant_name = participant_name
165
183
  wi.attributes = fields_hash
184
+ # don't care about dispatch_time and last_modified
166
185
  wi
167
186
  end
168
187
 
@@ -180,6 +199,26 @@ module Extras
180
199
  h
181
200
  end
182
201
 
202
+ #
203
+ # Replaces the current fields of this workitem with the given hash.
204
+ #
205
+ # This method modifies the content of the db.
206
+ #
207
+ def replace_fields (fhash)
208
+
209
+ fields.delete_all
210
+
211
+ fhash.each do |k, v|
212
+ fields << Field.new_field(k, v)
213
+ end
214
+
215
+ #f = Field.new_field("___map_type", "smap")
216
+ #
217
+ # an old trick for backward compatibility with OpenWFEja
218
+
219
+ save!
220
+ end
221
+
183
222
  #
184
223
  # Returns the Field instance with the given key. This method accept
185
224
  # symbols as well as strings as its parameter.
@@ -207,6 +246,49 @@ module Extras
207
246
 
208
247
  alias :forward :reply
209
248
  alias :proceed :reply
249
+
250
+ #
251
+ # Opening engine to update its reply method to accept these
252
+ # active record workitems.
253
+ #
254
+ class OpenWFE::Engine
255
+
256
+ alias :oldreply :reply
257
+
258
+ def reply (workitem)
259
+
260
+ if workitem.is_a?(Workitem)
261
+
262
+ oldreply(workitem.as_owfe_workitem)
263
+ workitem.destroy
264
+ else
265
+
266
+ oldreply(workitem)
267
+ end
268
+ end
269
+
270
+ alias :forward :reply
271
+ alias :proceed :reply
272
+ end
273
+
274
+ #
275
+ # Returns all the workitems belonging to the stores listed
276
+ # in the parameter storename_list.
277
+ # The result is a Hash whose keys are the store names and whose
278
+ # values are list of workitems.
279
+ #
280
+ def Workitem.find_in_stores (storename_list)
281
+
282
+ workitems = find_all_by_store_name(storename_list)
283
+
284
+ result = {}
285
+
286
+ workitems.each do |wi|
287
+ (result[wi.store_name] ||= []) << wi
288
+ end
289
+
290
+ result
291
+ end
210
292
  end
211
293
 
212
294
  #
@@ -215,7 +297,7 @@ module Extras
215
297
  class Field < ActiveRecord::Base
216
298
 
217
299
  belongs_to :workitem
218
- serialize :value
300
+ serialize :yvalue
219
301
 
220
302
  #
221
303
  # A quick method for doing
@@ -228,12 +310,30 @@ module Extras
228
310
  #
229
311
  # wi.fields << Field.new_field("toto", "b")
230
312
  #
313
+ # This method does not save the new Field.
314
+ #
231
315
  def self.new_field (key, value)
316
+
232
317
  f = Field.new
233
318
  f.key = key
234
319
  f.value = value
235
320
  f
236
321
  end
322
+
323
+ def value= (v)
324
+
325
+ if v.is_a?(String)
326
+ self.svalue = v
327
+ else
328
+ self.yvalue = v
329
+ end
330
+ end
331
+
332
+ def value
333
+
334
+ return self.svalue if self.svalue
335
+ self.yvalue
336
+ end
237
337
  end
238
338
 
239
339
 
@@ -280,13 +380,7 @@ module Extras
280
380
  #
281
381
  def consume (workitem)
282
382
 
283
- awi = Workitem.from_owfe_workitem(workitem)
284
- #
285
- # turns the workitem into an 'active' one
286
-
287
- awi.save
288
- #
289
- # and saves it in the db.
383
+ Workitem.from_owfe_workitem(workitem)
290
384
  end
291
385
 
292
386
  #
@@ -320,12 +414,42 @@ module Extras
320
414
  end
321
415
 
322
416
  #
323
- # TODO : please document me
417
+ # An extension of ActiveParticipant. It has a 'store_name' and it
418
+ # makes sure to flag every workitem it 'consumes' with that name
419
+ # (in its 'store_name' column/field).
420
+ #
421
+ # This is the participant used mainly in 'densha' for human users.
324
422
  #
325
423
  class ActiveStoreParticipant < ActiveParticipant
326
424
  include Enumerable
327
425
 
426
+ def initialize (store_name)
427
+
428
+ super()
429
+ @store_name = store_name
430
+ end
431
+
432
+ #
433
+ # This is the method called by the OpenWFEru engine to hand a
434
+ # workitem to this participant.
435
+ #
436
+ def consume (workitem)
437
+
438
+ Workitem.from_owfe_workitem(workitem, @store_name)
439
+ end
440
+
441
+ #
442
+ # Iterates over the workitems currently in this store.
443
+ #
328
444
  def each (&block)
445
+
446
+ return unless block
447
+
448
+ wis = Workitem.find_by_store_name @store_name
449
+
450
+ wis.each do |wi|
451
+ block.call wi
452
+ end
329
453
  end
330
454
  end
331
455
 
@@ -30,8 +30,6 @@
30
30
  # POSSIBILITY OF SUCH DAMAGE.
31
31
  #++
32
32
  #
33
- # $Id$
34
- #
35
33
 
36
34
  #
37
35
  # "made in Japan"
@@ -38,9 +38,11 @@
38
38
  #
39
39
 
40
40
  require 'csv'
41
+ require 'open-uri'
41
42
 
42
43
  require 'openwfe/utils'
43
44
  require 'openwfe/util/dollar'
45
+ require 'openwfe/workitem'
44
46
 
45
47
  include OpenWFE
46
48
 
@@ -204,24 +206,49 @@ module Extras
204
206
  end
205
207
  end
206
208
 
207
- return workitem
209
+ workitem
208
210
  end
209
211
 
210
212
  #
211
213
  # Passes a simple Hash instance though the csv table
212
214
  #
213
215
  def transform (hash)
216
+
214
217
  wi = InFlowWorkItem.new()
215
218
  wi.attributes = hash
216
- return transform_wi(nil, wi).attributes
219
+
220
+ transform_wi(nil, wi).attributes
221
+ end
222
+
223
+ #
224
+ # Outputs back this table as a CSV String
225
+ #
226
+ def to_csv
227
+
228
+ s = ""
229
+ s << @header.to_csv
230
+ s << "\n"
231
+ @rows.each do |row|
232
+ s << row.join(",")
233
+ s << "\n"
234
+ end
235
+ s
217
236
  end
218
237
 
219
238
  protected
220
239
 
221
240
  def to_csv_array (csv_data)
222
241
 
223
- return csv_data if csv_data.kind_of? Array
224
- return CSV::Reader.parse(csv_data)
242
+ return csv_data if csv_data.kind_of?(Array)
243
+
244
+ if csv_data.is_a?(URI)
245
+ csv_data = csv_data.to_s
246
+ end
247
+ if OpenWFE::parse_uri(csv_data)
248
+ csv_data = open(csv_data)
249
+ end
250
+
251
+ CSV::Reader.parse(csv_data)
225
252
  end
226
253
 
227
254
  def matches? (row, fexp, wi)
@@ -262,7 +289,7 @@ module Extras
262
289
 
263
290
  #puts "__row matches"
264
291
 
265
- return true
292
+ true
266
293
  end
267
294
 
268
295
  def regex_compare (value, cell)
@@ -314,9 +341,9 @@ module Extras
314
341
  def resolve_in_header (in_header)
315
342
 
316
343
  in_header = "f:#{in_header}" \
317
- if points_to_nothing? in_header
344
+ if points_to_nothing?(in_header)
318
345
 
319
- return "${#{in_header}}"
346
+ "${#{in_header}}"
320
347
  end
321
348
 
322
349
  def apply (row, fexp, wi)
@@ -347,7 +374,6 @@ module Extras
347
374
  elsif type == "f"
348
375
  wi.set_attribute(target, value)
349
376
  elsif type == "r"
350
- #instance_eval(value)
351
377
  OpenWFE::instance_eval_safely(self, value, 3)
352
378
  end
353
379
  end
@@ -380,12 +406,13 @@ module Extras
380
406
  end
381
407
 
382
408
  def empty_row? (row)
409
+
383
410
  return true unless row
384
411
  return true if (row.length == 1 and not row[0])
385
412
  row.each do |cell|
386
413
  return false if cell
387
414
  end
388
- return true
415
+ true
389
416
  end
390
417
 
391
418
  def points_to_nothing? (label)
@@ -418,7 +445,7 @@ module Extras
418
445
  names.each do |name|
419
446
  return label[i+1..-1] if s == name
420
447
  end
421
- return nil
448
+ nil
422
449
  end
423
450
 
424
451
  class Header
@@ -440,6 +467,18 @@ module Extras
440
467
  end
441
468
  # else don't add
442
469
  end
470
+
471
+ def to_csv
472
+
473
+ s = ""
474
+ @ins.each do |_in|
475
+ s << "in:#{_in}," if _in
476
+ end
477
+ @outs.each do |out|
478
+ s << "out:#{out}," if out
479
+ end
480
+ s[0..-2]
481
+ end
443
482
  end
444
483
  end
445
484
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: openwferu-extras
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.13
7
- date: 2007-08-01 00:00:00 +09:00
6
+ version: 0.9.14
7
+ date: 2007-09-18 00:00:00 +09:00
8
8
  summary: OpenWFEru extras (sqs, csv, ...)
9
9
  require_paths:
10
10
  - lib