Commit bfa70657 authored by wenjie.zheng's avatar wenjie.zheng

WorkflowTool.py: speedup conversion by replacing accessors with variables.

parent 02ec7e00
...@@ -286,8 +286,10 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -286,8 +286,10 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
for def_var in workflow.objectValues(portal_type='Variable'): for def_var in workflow.objectValues(portal_type='Variable'):
workflow._delObject(def_var.getId()) workflow._delObject(def_var.getId())
workflow._delObject('state_draft') workflow._delObject('state_draft')
for tid in dc_workflow.transitions: dc_workflow_transition_value_list = dc_workflow.transitions
tdef = dc_workflow.transitions.get(tid) dc_workflow_transition_id_list = dc_workflow_transition_value_list.objectIds()
for tid in dc_workflow_transition_value_list:
tdef = dc_workflow_transition_value_list.get(tid)
transition = workflow.newContent(portal_type='Transition', temp_object=temp) transition = workflow.newContent(portal_type='Transition', temp_object=temp)
if tdef.title == '' or tdef.title is None: if tdef.title == '' or tdef.title is None:
tdef.title = UpperCase(tdef.id) tdef.title = UpperCase(tdef.id)
...@@ -301,7 +303,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -301,7 +303,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
transition.setDescription(tdef.description) transition.setDescription(tdef.description)
if tdef.after_script_name is not None: if tdef.after_script_name is not None:
# check after script is a Transion or a Script: # check after script is a Transion or a Script:
if tdef.after_script_name in dc_workflow.transitions.objectIds(): if tdef.after_script_name in dc_workflow_transition_id_list:
transition.setAfterScriptId('transition_'+tdef.after_script_name) transition.setAfterScriptId('transition_'+tdef.after_script_name)
elif tdef.after_script_name in dc_workflow.scripts.objectIds(): elif tdef.after_script_name in dc_workflow.scripts.objectIds():
# add a prefix if there is a script & method conflict # add a prefix if there is a script & method conflict
...@@ -311,7 +313,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -311,7 +313,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
transition.setAfterScriptId(tdef.after_script_name) transition.setAfterScriptId(tdef.after_script_name)
if tdef.script_name is not None: if tdef.script_name is not None:
# check before script is a Transion or a Script: # check before script is a Transion or a Script:
if tdef.script_name in dc_workflow.transitions.objectIds(): if tdef.script_name in dc_workflow_transition_id_list:
transition.setBeforeScriptId('transition_'+tdef.script_name) transition.setBeforeScriptId('transition_'+tdef.script_name)
elif tdef.script_name in dc_workflow.scripts.objectIds(): elif tdef.script_name in dc_workflow.scripts.objectIds():
if hasattr(workflow, tdef.script_name): if hasattr(workflow, tdef.script_name):
...@@ -362,9 +364,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -362,9 +364,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
for transition_id in dc_workflow.states.get(sid).transitions: for transition_id in dc_workflow.states.get(sid).transitions:
sdef.addPossibleTransition(transition_id) sdef.addPossibleTransition(transition_id)
# set transition's destination state: # set transition's destination state:
for tid in dc_workflow.transitions: for tid in dc_workflow_transition_value_list:
tdef = workflow._getOb('transition_'+tid) tdef = workflow._getOb('transition_'+tid)
state = getattr(workflow, 'state_'+dc_workflow.transitions.get(tid).new_state_id, None) state = getattr(workflow, 'state_'+dc_workflow_transition_value_list.get(tid).new_state_id, None)
if state is None: if state is None:
# it's a remain in state transition. # it's a remain in state transition.
continue continue
...@@ -417,9 +419,10 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -417,9 +419,10 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
if qdef.guard.expr is not None: if qdef.guard.expr is not None:
worklist.setExpression(qdef.guard.expr.text) worklist.setExpression(qdef.guard.expr.text)
elif workflow_type_id == 'InteractionWorkflowDefinition': elif workflow_type_id == 'InteractionWorkflowDefinition':
for tid in dc_workflow.interactions: dc_workflow_interaction_value_list = dc_workflow.interactions
for tid in dc_workflow_interaction_value_list:
interaction = workflow.newContent(portal_type='Interaction', temp_object=temp) interaction = workflow.newContent(portal_type='Interaction', temp_object=temp)
tdef = dc_workflow.interactions.get(tid) tdef = dc_workflow_interaction_value_list.get(tid)
if tdef.title == '' or tdef.title is None: if tdef.title == '' or tdef.title is None:
tdef.title = UpperCase(tdef.id) tdef.title = UpperCase(tdef.id)
interaction.setTitle(tdef.title) interaction.setTitle(tdef.title)
...@@ -470,8 +473,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -470,8 +473,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
interaction.setTriggerType(tdef.trigger_type) interaction.setTriggerType(tdef.trigger_type)
interaction.setDescription(tdef.description) interaction.setDescription(tdef.description)
# create scripts (portal_type = Workflow Script) # create scripts (portal_type = Workflow Script)
for script_id in dc_workflow.scripts: dc_workflow_script_list = dc_workflow.scripts
script = dc_workflow.scripts.get(script_id) 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 # add a prefix if there is a script & method conflict
if hasattr(workflow, script_id): if hasattr(workflow, script_id):
workflow_script = workflow.newContent(id='ScriptPrefix_'+script_id, portal_type='Workflow Script', temp_object=temp) workflow_script = workflow.newContent(id='ScriptPrefix_'+script_id, portal_type='Workflow Script', temp_object=temp)
...@@ -484,8 +488,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -484,8 +488,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
workflow_script.setBody(script._body) workflow_script.setBody(script._body)
workflow_script.setProxyRole(script._proxy_roles) workflow_script.setProxyRole(script._proxy_roles)
# create variables (portal_type = Variable) # create variables (portal_type = Variable)
for vid in dc_workflow.variables: dc_workflow_variable_list = dc_workflow.variables
vdef = dc_workflow.variables.get(vid) for vid in dc_workflow_variable_list:
vdef = dc_workflow_variable_list.get(vid)
variable = workflow.newContent(portal_type='Variable', temp_object=temp) variable = workflow.newContent(portal_type='Variable', temp_object=temp)
variable.setTitle(vdef.title) variable.setTitle(vdef.title)
variable.setReference(vdef.id) variable.setReference(vdef.id)
...@@ -503,8 +508,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -503,8 +508,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
variable.setDescription(vdef.description) variable.setDescription(vdef.description)
# configure transition variable # configure transition variable
if getattr(dc_workflow, 'transitions', None) is not None: if getattr(dc_workflow, 'transitions', None) is not None:
for tid in dc_workflow.transitions: dc_workflow_transition_value_list = dc_workflow.transitions
origin_tdef = dc_workflow.transitions[tid] for tid in dc_workflow_transition_value_list:
origin_tdef = dc_workflow_transition_value_list[tid]
transition = workflow._getOb('transition_'+tid) transition = workflow._getOb('transition_'+tid)
new_category = [] new_category = []
if origin_tdef.var_exprs is None: if origin_tdef.var_exprs is None:
...@@ -518,8 +524,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -518,8 +524,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
new_category.append(tr_var_path) new_category.append(tr_var_path)
tr_var.setCausalityList(new_category) tr_var.setCausalityList(new_category)
if getattr(dc_workflow, 'interactions', None) is not None: if getattr(dc_workflow, 'interactions', None) is not None:
for tid in dc_workflow.interactions: dc_workflow_interaction_value_list = dc_workflow.interactions
origin_tdef = dc_workflow.interactions[tid] for tid in dc_workflow_interaction_value_list:
origin_tdef = dc_workflow_interaction_value_list[tid]
interaction = workflow._getOb('interaction_'+tid) interaction = workflow._getOb('interaction_'+tid)
new_category = [] new_category = []
if origin_tdef.var_exprs is None: if origin_tdef.var_exprs is None:
......
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