lib/ruote/receiver/base.rb in ruote-2.1.11 vs lib/ruote/receiver/base.rb in ruote-2.2.0
- old
+ new
@@ -1,7 +1,7 @@
#--
-# Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
+# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -35,11 +35,11 @@
module ReceiverMixin
# This method pipes back a workitem into the engine, letting it resume
# in its flow, hopefully.
#
- def receive (workitem)
+ def receive(workitem)
workitem = workitem.to_h if workitem.respond_to?(:to_h)
@context.storage.put_msg(
'receive',
@@ -55,24 +55,24 @@
# This method is mostly used from the Ruote::Engine class (which includes
# this mixin).
#
# process_definition must be a result of Ruote.process_definition call
# or XML or JSON serialized process definition, as accepted by
- # Ruote::Parser#parse.
+ # Ruote::Reader#read.
#
# fields are workflow parameters that will be placed in workitem.fields.
#
# variables contain engine variables.
#
- def launch (process_definition, fields={}, variables={})
+ def launch(process_definition, fields={}, variables={})
wfid = @context.wfidgen.generate
@context.storage.put_msg(
'launch',
'wfid' => wfid,
- 'tree' => @context.parser.parse(process_definition),
+ 'tree' => @context.reader.read(process_definition),
'workitem' => { 'fields' => fields },
'variables' => variables)
wfid
end
@@ -80,23 +80,23 @@
# Wraps a call to receive(workitem)
#
# Not aliasing so that if someone changes the receive implementation,
# reply is affected as well.
#
- def reply (workitem)
+ def reply(workitem)
- receive (workitem)
+ receive(workitem)
end
# Wraps a call to receive(workitem)
#
# Not aliasing so that if someone changes the receive implementation,
# reply_to_engine is affected as well.
#
- def reply_to_engine (workitem)
+ def reply_to_engine(workitem)
- receive (workitem)
+ receive(workitem)
end
# A receiver signs a workitem when it comes back.
#
# Not used much as of now.
@@ -107,11 +107,11 @@
end
# Convenience method, given a workitem or a fei, returns the
# corresponding flow expession.
#
- def fetch_flow_expression (workitem_or_fei)
+ def fetch_flow_expression(workitem_or_fei)
Ruote::Exp::FlowExpression.fetch(
@context,
Ruote::FlowExpressionId.extract_h(workitem_or_fei))
end
@@ -122,10 +122,32 @@
# # or
# fexp = engine.fexp(workitem)
#
alias fexp fetch_flow_expression
+ # A convenience methods for advanced users (like Oleg).
+ #
+ # Given a fei (flow expression id), fetches the workitem as stored in
+ # the expression with that fei.
+ # This is the "applied workitem", if the workitem is currently handed to
+ # a participant, this method will return the workitem as applied, not
+ # the workitem as saved by the participant/user in whatever worklist it
+ # uses. If you need that workitem, do the vanilla thing and ask it to
+ # the [storage] participant or its worklist.
+ #
+ # The fei might be a string fei (result of fei.to_storage_id), a
+ # FlowExpressionId instance or a hash.
+ #
+ # on_terminate processes are not triggered for on_error processes.
+ # on_error processes are triggered for on_terminate processes as well.
+ #
+ def applied_workitem(fei)
+
+ Ruote::Workitem.new(fexp(fei).h.applied_workitem)
+ end
+ alias workitem applied_workitem
+
protected
# Stashes values in the participant expression (in the storage).
#
# put(workitem.fei, 'key' => 'value', 'colour' => 'blue')
@@ -137,11 +159,11 @@
#
# See the thread at
# http://groups.google.com/group/openwferu-users/t/2e6a95708c10847b for the
# justification.
#
- def put (fei, hash)
+ def put(fei, hash)
fexp = Ruote::Exp::FlowExpression.fetch(@context, fei.to_h)
(fexp.h['stash'] ||= {}).merge!(hash)
@@ -159,11 +181,11 @@
# # => { 'colour' => 'blue' }
#
# put & get are useful for a participant that needs to communicate
# between its consume and its cancel.
#
- def get (fei, key=nil)
+ def get(fei, key=nil)
fexp = Ruote::Exp::FlowExpression.fetch(@context, fei.to_h)
stash = fexp.h['stash'] rescue {}
@@ -178,10 +200,10 @@
class Receiver
include ReceiverMixin
# Accepts context, worker, engine or storage as first argument.
#
- def initialize (cwes, options={})
+ def initialize(cwes, options={})
@context = cwes.context
@options = options
end
end