Commit e0ca9a3d authored by iv's avatar iv

ERP5Workflow: set categories on interactions while converting them

to ERP5 Workflow and use them
parent 82b70919
......@@ -64,7 +64,6 @@ class Interaction(IdAsReferenceMixin('interaction_', "prefix"), XMLObject,
trigger_once_per_transaction = False
temporary_document_disallowed = False
var_exprs = None # A mapping.
guard = None
default_reference = ''
# Declarative security
......
......@@ -240,10 +240,8 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
sci = StateChangeInfo(
ob, self, former_status, tdef, None, None, kwargs=kw)
before_script_list = tdef.getBeforeScriptNameList()
if before_script_list != [] and before_script_list is not None:
for script_name in before_script_list:
script = self._getOb(script_name, None)
before_script_list = tdef.getBeforeScriptValueList()
for script in before_script_list:
if script: script(sci)
return filtered_transition_list
......@@ -306,28 +304,22 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
ob, self, former_status, tdef, None, None, kwargs=kw)
# Execute the "after" script.
after_script_list = tdef.getAfterScriptNameList()
if after_script_list != [] and after_script_list is not None:
for script_name in after_script_list:
# try to get the script without calling it.
script = self._getOb(script_name, None)
# Pass lots of info to the script in a single parameter.
after_script_list = tdef.getAfterScriptValueList()
for script in after_script_list:
if script: script(sci) # May throw an exception
# Queue the "Before Commit" scripts
sm = getSecurityManager()
before_commit_script_list = tdef.getBeforeCommitScriptNameList()
if before_commit_script_list != [] and before_commit_script_list is not None:
for script_name in before_commit_script_list:
before_commit_script_list = tdef.getBeforeCommitScriptValueList()
for script in before_commit_script_list:
transaction.get().addBeforeCommitHook(self._before_commit,
(sci, script_name, sm))
(sci, script.id, sm))
# Execute "activity" scripts
activity_script_list = tdef.getActivateScriptNameList()
if activity_script_list != [] and activity_script_list is not None:
activity_script_list = tdef.getActivateScriptValueList()
for script_name in activity_script_list:
self.activate(activity='SQLQueue')\
.activeScript(script_name, ob.getRelativeUrl(),
.activeScript(script.id, ob.getRelativeUrl(),
status, tdef.getId())
def _before_commit(self, sci, script_name, security_manager):
......
......@@ -87,22 +87,6 @@ Most of the code in this file has been taken from patches/WorkflowTool.py.
_marker = [] # Create a new marker object.
def getERP5ScriptPath(erp5_workflow, dc_workflow, dc_script_name, category_name):
# XXX(WORKFLOW): remove hardcoded paths
if dc_script_name is not None:
script_path_base = category_name.strip('/') + '/' + 'portal_workflow/' + \
erp5_workflow.getId() + '/'
# check script is a Transition or a Script:
if dc_script_name in dc_workflow.transitions:
return(script_path_base + 'transition_' + dc_script_name)
elif dc_script_name in dc_workflow.scripts.objectIds():
# add a prefix if there is a conflict
if hasattr(erp5_workflow, dc_script_name):
return(script_path_base + 'ScriptPrefix_' + dc_script_name)
else:
return(script_path_base + dc_script_name)
return None
class WorkflowTool(BaseTool, OriginalWorkflowTool):
"""
A new container for DC workflow and workflow;
......@@ -273,6 +257,17 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
temp_workflow_id_list.append(temp_workflow.getTitle())
return temp_workflow_list
def initialize_script_categories(self, workflow, initial_script_name_list, method):
script_path_list = []
if isinstance(initial_script_name_list, str):
initial_script_name_list = [initial_script_name_list]
for script_name in initial_script_name_list:
if script_name:
script = getattr(workflow, 'ScriptPrefix_' + script_name, None) or getattr(workflow, script_name, None) or getattr(workflow, 'transition_' + script_name, None)
script_path = script.getRelativeUrl()
script_path_list.append(script_path)
method(tuple(script_path_list))
def dc_workflow_asERP5Object(self, dc_workflow, is_temporary=False):
""" convert DC Workflow to New Workflow """
......@@ -302,6 +297,23 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
if not is_temporary:
# create state and transitions (Workflow)
# or interactions (Interaction Workflow)
# create scripts (portal_type = Workflow Script)
dc_workflow_script_list = dc_workflow.scripts
for script_id in dc_workflow_script_list:
script = dc_workflow_script_list.get(script_id)
# add a prefix if there is a script & method conflict
if hasattr(workflow, script_id):
workflow_script = workflow.newContent(id='ScriptPrefix_'+script_id, portal_type='Workflow Script', temp_object=is_temporary)
else:
workflow_script = workflow.newContent(id=script_id, portal_type='Workflow Script', temp_object=is_temporary)
workflow_script.setTitle(script.title)
workflow_script.default_reference = script_id
workflow_script.setParameterSignature(script._params)
#workflow_script.setCallableType(script.callable_type)# not defined in python script?
workflow_script.setBody(script._body)
workflow_script.setProxyRole(script._proxy_roles)
if workflow_type_id == 'DCWorkflowDefinition':
# remove default state and variables
for def_var in workflow.objectValues(portal_type='Workflow Variable'):
......@@ -309,6 +321,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
workflow._delObject('state_draft')
dc_workflow_transition_value_list = dc_workflow.transitions
dc_workflow_transition_id_list = dc_workflow_transition_value_list.objectIds()
# create transition (portal_type = Transition)
for tid in dc_workflow_transition_value_list:
tdef = dc_workflow_transition_value_list.get(tid)
......@@ -324,20 +337,6 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
transition.setAction(tdef.actbox_url)
transition.setDescription(tdef.description)
before_script_path = getERP5ScriptPath(workflow, dc_workflow,
tdef.script_name,
'before_script')
after_script_path = getERP5ScriptPath(workflow, dc_workflow,
tdef.after_script_name,
'after_script')
if before_script_path or after_script_path:
script_list = transition.getCategoryList()
if before_script_path:
script_list.append(before_script_path)
if after_script_path:
script_list.append(after_script_path)
transition.setCategoryList(script_list)
# configure guard
if tdef.guard:
transition.guard = tdef.guard
......@@ -346,6 +345,18 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
transition.setGuardGroupList(tdef.guard.groups)
if tdef.guard.expr is not None:
transition.setGuardExpression(tdef.guard.expr.text)
for transition in workflow.objectValues(portal_type='Transition'):
# configure after/before scripts
# we have to loop again over transitions because some
# before/after/... scripts are transitions and obviously, all of
# them were not defined on the new workflow in the previous loop
self.initialize_script_categories(workflow, tdef.script_name,
transition.setBeforeScriptValueList)
self.initialize_script_categories(workflow, tdef.after_script_name,
transition.setAfterScriptValueList)
# create states (portal_type = State)
for sid in dc_workflow.states:
sdef = dc_workflow.states.get(sid)
......@@ -446,31 +457,19 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
if tdef.title:
interaction.setTitle(tdef.title)
interaction.setReference(tdef.id)
script_list = []
for script_name in tdef.activate_script_name:
# Add a prefix iif there is a conflict (script and accessor).
if hasattr(workflow, script_name):
script_name = 'ScriptPrefix_' + script_name
script_list.append(script_name)
interaction.setActivateScriptNameList(tuple(script_list))
script_list = []
for script_name in tdef.after_script_name:
if hasattr(workflow, script_name):
script_name = 'ScriptPrefix_' + script_name
script_list.append(script_name)
interaction.setAfterScriptNameList(tuple(script_list))
script_list = []
for script_name in tdef.before_commit_script_name:
if hasattr(workflow, script_name):
script_name = 'ScriptPrefix_' + script_name
script_list.append(script_name)
interaction.setBeforeCommitScriptNameList(tuple(script_list))
script_list = []
for script_name in tdef.script_name:
if hasattr(workflow, script_name):
script_name = 'ScriptPrefix_' + script_name
script_list.append(script_name)
interaction.setBeforeScriptNameList(tuple(script_list))
# configure after/before/before commit/activate scripts
# no need to loop again over interactions as made for transitions
# because interactions xxx_script are not interactions
self.initialize_script_categories(workflow, tdef.script_name,
interaction.setBeforeScriptValueList)
self.initialize_script_categories(workflow, tdef.after_script_name,
interaction.setAfterScriptValueList)
self.initialize_script_categories(workflow, tdef.activate_script_name,
interaction.setActivateScriptValueList)
self.initialize_script_categories(workflow, tdef.before_commit_script_name,
interaction.setBeforeCommitScriptValueList)
# configure guard
if tdef.guard:
interaction.guard = tdef.guard
......@@ -494,21 +493,6 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
interaction.setTriggerType(tdef.trigger_type)
interaction.setDescription(tdef.description)
# create scripts (portal_type = Workflow Script)
dc_workflow_script_list = dc_workflow.scripts
for script_id in dc_workflow_script_list:
script = dc_workflow_script_list.get(script_id)
# add a prefix if there is a script & method conflict
if hasattr(workflow, script_id):
workflow_script = workflow.newContent(id='ScriptPrefix_'+script_id, portal_type='Workflow Script', temp_object=is_temporary)
else:
workflow_script = workflow.newContent(id=script_id, portal_type='Workflow Script', temp_object=is_temporary)
workflow_script.setTitle(script.title)
workflow_script.default_reference = script_id
workflow_script.setParameterSignature(script._params)
#workflow_script.setCallableType(script.callable_type)# not defined in python script?
workflow_script.setBody(script._body)
workflow_script.setProxyRole(script._proxy_roles)
# create variables (portal_type = Variable)
for variable_id, variable_definition in dc_workflow.variables.items():
variable = workflow.newContent(portal_type='Workflow Variable', temp_object=is_temporary)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment