lib/openwfe/expool/expressionpool.rb in openwferu-0.9.7 vs lib/openwfe/expool/expressionpool.rb in openwferu-0.9.8

- old
+ new

@@ -53,10 +53,11 @@ require 'openwfe/util/safe' require 'openwfe/util/observable' require 'openwfe/expressions/environment' require 'openwfe/expressions/raw_xml' require 'openwfe/expressions/raw_prog' +require 'openwfe/expressions/simplerep' include OpenWFE module OpenWFE @@ -188,11 +189,11 @@ end raise "didn't find process definition at '#{wfdurl}'" \ unless definition - raw_expression = build_raw_expression(wfdurl, definition) + raw_expression = build_raw_expression(launchitem, definition) raw_expression.check_parameters(launchitem) # # will raise an exception if there are requirements # and one of them is not met @@ -253,11 +254,11 @@ rawexp = if template.is_a? RawExpression template elsif template.is_a? FlowExpressionId fetch_expression(template) else - build_raw_expression("no-url", template) + build_raw_expression(nil, template) end #raise "did not find expression at #{template.to_s}" \ # unless rawexp @@ -385,11 +386,11 @@ onotify :cancel, fei inflowitem = exp.cancel() remove(exp) - return inflowitem + inflowitem end # # Given any expression of a process, cancels the complete process # instance. @@ -420,25 +421,40 @@ end # # Replies to the parent of the given expression. # - def reply_to_parent (exp, workitem) + def reply_to_parent (exp, workitem, remove=true) ldebug { "reply_to_parent() for #{exp.fei.to_debug_s}" } workitem.last_expression_id = exp.fei onotify :reply_to_parent, exp.fei, workitem - remove(exp) + if remove + remove(exp) + # + # remove the expression itself + + exp.clean_children() + # + # remove all the children of the expression + end + # - # remove all the children of the expression + # manage tag, have to remove it so it can get 'redone' or 'undone' + # (preventing abuse) - exp.clean_children() + tagname = exp.attributes["tag"] if exp.attributes + exp.delete_variable(tagname) if tagname + + # + # flow terminated ? + if not exp.parent_id ldebug do "reply_to_parent() process " + "#{exp.fei.workflow_instance_id} terminated" end @@ -446,19 +462,25 @@ onotify :terminate, exp.fei return end + # + # else, gone parent ? + if exp.parent_id == GONE_PARENT_ID ldebug do "reply_to_parent() parent is gone for " + exp.fei.to_debug_s end return end + # + # parent still present, reply to it + reply(exp.parent_id, workitem) end # # Triggers the reply expression of the expression given by its id. @@ -490,11 +512,14 @@ t = Timer.new onotify :update, flow_expression.fei, flow_expression - ldebug { "update() took #{t.duration} ms" } + ldebug do + "update() took #{t.duration} ms " + + "#{flow_expression.fei.to_debug_s}" + end flow_expression end # @@ -517,11 +542,11 @@ raise \ "Cannot fetch expression with key : "+ "'#{fei}' (#{fei.class})" end - ldebug { "fetch() for #{fei.to_debug_s}" } + #ldebug { "fetch() for #{fei.to_debug_s}" } return get_expression_storage()[fei], fei end end @@ -788,11 +813,11 @@ #ldebug do # "determine_representation() " + # "param of class #{param.class.name}" #end - return param if param.is_a? ProgExpRepresentation + return param if param.is_a? SimpleExpRepresentation return param.make if param.is_a? ProcessDefinition return param.do_make if param.is_a? Class raise "cannot handle definition of class #{param.class.name}" \ unless param.is_a? String @@ -827,43 +852,49 @@ # # Builds a FlowExpressionId instance for process being # launched. # - def new_fei (flow_url, flow_name, flow_revision, exp_name) + def new_fei (launchitem, flow_name, flow_revision, exp_name) + url = if launchitem + launchitem.workflow_definition_url + else + "no-url" + end + fei = FlowExpressionId.new fei.owfe_version = OPENWFERU_VERSION fei.engine_id = OpenWFE::stu get_engine.service_name fei.initial_engine_id = OpenWFE::stu fei.engine_id - fei.workflow_definition_url = OpenWFE::stu flow_url + fei.workflow_definition_url = OpenWFE::stu url fei.workflow_definition_name = OpenWFE::stu flow_name fei.workflow_definition_revision = OpenWFE::stu flow_revision - fei.workflow_instance_id = get_wfid_generator.generate + fei.wfid = get_wfid_generator.generate launchitem fei.expression_id = "0" fei.expression_name = exp_name return fei end # # Builds the RawExpression instance at the root of the flow # being launched. # - # The param can be a LaunchItem, an URI, anything accepted - # by the determine_representation() method. + # The param can be a template or a definition (anything + # accepted by the determine_representation() method). # - def build_raw_expression (url, param) + def build_raw_expression (launchitem, param) procdef = determine_representation(param) #return procdef if procdef.is_a? RawExpression flow_name = procdef.attributes['name'] flow_revision = procdef.attributes['revision'] exp_name = procdef.name - fei = new_fei(url, flow_name, flow_revision, exp_name) + fei = new_fei(launchitem, flow_name, flow_revision, exp_name) #puts procdef.raw_expression_class #puts procdef.raw_expression_class.public_methods return procdef.raw_expression_class\