lib/openwfe/participants/participants.rb in ruote-0.9.19 vs lib/openwfe/participants/participants.rb in ruote-0.9.20

- old
+ new

@@ -1,43 +1,29 @@ -# #-- -# Copyright (c) 2006-2008, John Mettraux, OpenWFE.org -# All rights reserved. +# Copyright (c) 2006-2009, John Mettraux, jmettraux@gmail.com # -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: +# 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 +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: # -# . Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. # -# . Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. # -# . Neither the name of the "OpenWFE" nor the names of its contributors may be -# used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. +# Made in Japan. #++ -# -# -# "made in Japan" -# -# John Mettraux at openwfe.org -# require 'yaml' require 'openwfe/utils' require 'openwfe/util/dollar' @@ -65,21 +51,21 @@ # The constructor expects as a unique optional param either the # application_context either the 'output' dir for the participant. # def initialize (context_or_dir=nil) - @workdir = get_work_directory(context_or_dir) + "/out/" + @workdir = get_work_directory(context_or_dir) + '/out/' @reply_anyway = false end # # The method called by the engine for each incoming workitem. # def consume (workitem) - FileUtils.makedirs(@workdir) unless File.exist?(@workdir) + FileUtils.mkdir_p(@workdir) unless File.exist?(@workdir) file_name = @workdir + determine_file_name(workitem) dump_to_file(file_name, workitem) @@ -91,12 +77,12 @@ # YAML to a file). # It can be easily overriden. # def dump_to_file (file_name, workitem) - File.open(file_name, "w") do |file| - file.print encode_workitem(workitem) + File.open(file_name, 'w') do |file| + file.print(encode_workitem(workitem)) end end # # You can override this method to control into which file (name) @@ -109,23 +95,23 @@ fei = workitem.fei OpenWFE::ensure_for_filename( "#{fei.wfid}_#{fei.expression_id}__" + "#{fei.workflow_definition_name}__" + - "#{fei.workflow_definition_revision}" + + "#{fei.workflow_definition_revision}__" + "#{workitem.participant_name}.yaml") end protected - # - # By default, uses YAML to serialize the workitem - # (of course you can override this method). - # - def encode_workitem (wi) - YAML.dump wi - end + # + # By default, uses YAML to serialize the workitem + # (of course you can override this method). + # + def encode_workitem (wi) + YAML.dump(wi) + end end # # This participant is used by the register_participant() method of # Engine class. @@ -155,29 +141,24 @@ # class BlockParticipant include LocalParticipant def initialize (block0=nil, &block1) - @block = if block1 - block1 - else - block0 - end - raise "Missing a block parameter" \ - unless @block + + @block = block1 ? block1 : block0 + + raise 'Missing a block parameter' unless @block end def consume (workitem) - result = call_block @block, workitem + result = call_block(@block, workitem) - workitem.set_result(result) \ - if result and result != workitem + workitem.set_result(result) if result and result != workitem - reply_to_engine(workitem) \ - if workitem.kind_of? InFlowWorkItem - # else it's a cancel ite + reply_to_engine(workitem) if workitem.kind_of?(InFlowWorkItem) + # else it's a cancel item end end # # Simply aliasing a participant. @@ -236,11 +217,11 @@ # # Simply discards the incoming workitem # def consume (workitem) - reply_to_engine workitem + reply_to_engine(workitem) end end # # The PrintParticipant will just emit its name to the @@ -335,28 +316,21 @@ # def initialize (object) super() - template_uri = OpenWFE::parse_known_uri object + template_uri = OpenWFE::parse_known_uri(object) @template = template_uri || object end # # This is the method called by the engine when it has a workitem # for this participant. # def consume (workitem) - #get_expression_pool.launch_template( - # get_flow_expression(workitem), - # nil, # new environment - # 0, # sub_id - # @template, - # workitem) - # #params) get_expression_pool.launch_subprocess( get_flow_expression(workitem), @template, false, # don't forget workitem, @@ -376,15 +350,15 @@ # # Given a workitem, expands the template and returns it as a String. # def eval_template (workitem) - fe = get_flow_expression workitem + fe = get_flow_expression(workitem) template = if @block_template - call_block @block_template, workitem + call_block(@block_template, workitem) elsif @template template = if @template.kind_of?(File) @template.readlines @@ -395,12 +369,12 @@ else nil end - return "(no template given)" unless template + return '(no template given)' unless template - OpenWFE::dosub template, fe, workitem + OpenWFE::dosub(template, fe, workitem) end end end