Commit 20ee9b58 authored by iv's avatar iv

ERP5Workflow: some refactoring on dc_workflow_asERP5Object

parent c33ac428
...@@ -86,7 +86,7 @@ for workflow in selected_workflow_list:\n ...@@ -86,7 +86,7 @@ for workflow in selected_workflow_list:\n
url_quote(\'workflow(s) is already exist.\')))\n url_quote(\'workflow(s) is already exist.\')))\n
\n \n
# conversion and reassignment\n # conversion and reassignment\n
new_workflow = context.dc_workflow_asERP5Object(context, workflow, temp=0)\n new_workflow = context.dc_workflow_asERP5Object(workflow, is_temporary=False)\n
context.reassignWorkflow(new_workflow.getId())\n context.reassignWorkflow(new_workflow.getId())\n
selected_workflow_id_list.append(new_workflow.getId())\n selected_workflow_id_list.append(new_workflow.getId())\n
\n \n
......
...@@ -1014,14 +1014,14 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin): ...@@ -1014,14 +1014,14 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
workflow = workflow_tool._getOb(workflow_id) workflow = workflow_tool._getOb(workflow_id)
if workflow.getPortalType() not in ['Workflow', 'Interaction Workflow', 'Configuration Workflow']: if workflow.getPortalType() not in ['Workflow', 'Interaction Workflow', 'Configuration Workflow']:
LOG("### workflow id" , 0, workflow_id) LOG("### workflow id" , 0, workflow_id)
new_workflow = workflow_tool.dc_workflow_asERP5Object(workflow_tool, workflow, temp=0) new_workflow = workflow_tool.dc_workflow_asERP5Object(workflow, is_temporary=False)
workflow_tool.reassignWorkflow(workflow_id) workflow_tool.reassignWorkflow(workflow_id)
self.commit() self.commit()
LOG("### reassigned" , 0, workflow_id) LOG("### reassigned" , 0, workflow_id)
# force convert edit_workflow: Why have to load edit_workflow this way? # force convert edit_workflow: Why have to load edit_workflow this way?
edit_workflow = workflow_tool._getOb('edit_workflow', None) edit_workflow = workflow_tool._getOb('edit_workflow', None)
if edit_workflow is not None: if edit_workflow is not None:
new_workflow = workflow_tool.dc_workflow_asERP5Object(workflow_tool, edit_workflow, temp=0) new_workflow = workflow_tool.dc_workflow_asERP5Object(edit_workflow, is_temporary=False)
workflow_tool.reassignWorkflow('edit_workflow') workflow_tool.reassignWorkflow('edit_workflow')
LOG("### edit workflow" , 0, "after reassignment") LOG("### edit workflow" , 0, "after reassignment")
self.commit() self.commit()
......
...@@ -177,7 +177,8 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -177,7 +177,8 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
if wf.getPortalType() == 'Workflow': if wf.getPortalType() == 'Workflow':
# workflow compatibility # workflow compatibility
action = 'transition_' + action_ref action = 'transition_' + action_ref
else: action = action_ref else:
action = action_ref
if wf.isActionSupported(ob, action, **kw): if wf.isActionSupported(ob, action, **kw):
found = 1 found = 1
break break
...@@ -249,42 +250,38 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -249,42 +250,38 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
workflow_type = dc_workflow.__class__.__name__ workflow_type = dc_workflow.__class__.__name__
if workflow_type in ['Workflow', 'Interaction Workflow', 'Configuration Workflow']: if workflow_type in ['Workflow', 'Interaction Workflow', 'Configuration Workflow']:
continue continue
temp_workflow = self.dc_workflow_asERP5Object(self, dc_workflow, temp_obj) temp_workflow = self.dc_workflow_asERP5Object(dc_workflow, is_temporary=temp_obj)
temp_workflow_list.append(temp_workflow) temp_workflow_list.append(temp_workflow)
temp_workflow_id_list.append(temp_workflow.getTitle()) temp_workflow_id_list.append(temp_workflow.getTitle())
return temp_workflow_list return temp_workflow_list
def dc_workflow_asERP5Object(self, container, dc_workflow, temp): def dc_workflow_asERP5Object(self, dc_workflow, is_temporary=False):
# convert DC Workflow to New Workflow """ convert DC Workflow to New Workflow """
workflow_type_id = dc_workflow.__class__.__name__ workflow_type_id = dc_workflow.__class__.__name__
if workflow_type_id in ['DCWorkflowDefinition', 'InteractionWorkflowDefinition']: if workflow_type_id in ['DCWorkflowDefinition', 'InteractionWorkflowDefinition']:
# Only convert old workflow objects. # Only convert old workflow objects.
if workflow_type_id == 'DCWorkflowDefinition': if is_temporary:
if temp == 0:
new_id = 'converting_'+dc_workflow.id
else:
new_id = dc_workflow.id new_id = dc_workflow.id
else:
new_id = 'converting_' + dc_workflow.id
uid = self.encodeWorkflowUid(new_id) uid = self.encodeWorkflowUid(new_id)
workflow = container.newContent(id=new_id, portal_type='Workflow', temp_object=temp) portal_type = ('Workflow' if workflow_type_id == 'DCWorkflowDefinition' else 'Interaction Workflow')
workflow = self.newContent(id=new_id, temp_object=is_temporary,
portal_type=portal_type)
if workflow_type_id == 'DCWorkflowDefinition':
workflow.setStateVariable(dc_workflow.state_var) workflow.setStateVariable(dc_workflow.state_var)
workflow.setWorkflowManagedPermission(dc_workflow.permissions) workflow.setWorkflowManagedPermission(dc_workflow.permissions)
workflow.setManagerBypass(dc_workflow.manager_bypass) workflow.setManagerBypass(dc_workflow.manager_bypass)
elif workflow_type_id == 'InteractionWorkflowDefinition':
if temp == 0:
new_id = 'converting_'+dc_workflow.id
else:
new_id = dc_workflow.id
uid = self.encodeWorkflowUid(new_id)
workflow = container.newContent(id=new_id, portal_type='Interaction Workflow', temp_object=temp)
if temp == 1: if is_temporary:
# give temp workflow an uid for form_dialog. # give temp workflow an uid for form_dialog.
workflow.uid = uid workflow.uid = uid
workflow.default_reference = dc_workflow.id workflow.default_reference = dc_workflow.id
workflow.setTitle(dc_workflow.title) workflow.setTitle(dc_workflow.title)
workflow.setDescription(dc_workflow.description) workflow.setDescription(dc_workflow.description)
if temp == 0: if not is_temporary:
# create transitions # create transitions
if workflow_type_id == 'DCWorkflowDefinition': if workflow_type_id == 'DCWorkflowDefinition':
# remove default state and variables # remove default state and variables
...@@ -296,7 +293,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -296,7 +293,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
# create transition (portal_type = Transition) # create transition (portal_type = Transition)
for tid in dc_workflow_transition_value_list: for tid in dc_workflow_transition_value_list:
tdef = dc_workflow_transition_value_list.get(tid) 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=is_temporary)
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)
transition.setTitle(tdef.title) transition.setTitle(tdef.title)
...@@ -338,7 +335,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -338,7 +335,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
# create states (portal_type = State) # create states (portal_type = State)
for sid in dc_workflow.states: for sid in dc_workflow.states:
sdef = dc_workflow.states.get(sid) sdef = dc_workflow.states.get(sid)
state = workflow.newContent(portal_type='State', temp_object=temp) state = workflow.newContent(portal_type='State', temp_object=is_temporary)
if sdef.title == '' or sdef.title is None: if sdef.title == '' or sdef.title is None:
sdef.title = UpperCase(sdef.id) sdef.title = UpperCase(sdef.id)
if hasattr(sdef, 'type_list'): state.setStateType(sdef.type_list) if hasattr(sdef, 'type_list'): state.setStateType(sdef.type_list)
...@@ -382,7 +379,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -382,7 +379,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
# worklists (portal_type = Worklist) # worklists (portal_type = Worklist)
for qid in dc_workflow.worklists: for qid in dc_workflow.worklists:
qdef = dc_workflow.worklists.get(qid) qdef = dc_workflow.worklists.get(qid)
worklist = workflow.newContent(portal_type='Worklist', temp_object=temp) worklist = workflow.newContent(portal_type='Worklist', temp_object=is_temporary)
worklist.setTitle(qdef.title) worklist.setTitle(qdef.title)
worklist.setReference(qdef.id) worklist.setReference(qdef.id)
worklist.setDescription(qdef.description) worklist.setDescription(qdef.description)
...@@ -427,11 +424,11 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -427,11 +424,11 @@ 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':
dc_workflow_interaction_value_list = dc_workflow.interactions dc_workflow_interaction_value_dict = dc_workflow.interactions
# create interactions (portal_type = Interaction) # create interactions (portal_type = Interaction)
for tid in dc_workflow_interaction_value_list: for tid in dc_workflow_interaction_value_dict:
interaction = workflow.newContent(portal_type='Interaction', temp_object=temp) interaction = workflow.newContent(portal_type='Interaction', temp_object=is_temporary)
tdef = dc_workflow_interaction_value_list.get(tid) tdef = dc_workflow_interaction_value_dict.get(tid)
if tdef.title: if tdef.title:
interaction.setTitle(tdef.title) interaction.setTitle(tdef.title)
interaction.setReference(tdef.id) interaction.setReference(tdef.id)
...@@ -488,9 +485,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -488,9 +485,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
script = dc_workflow_script_list.get(script_id) 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=is_temporary)
else: else:
workflow_script = workflow.newContent(id=script_id ,portal_type='Workflow Script', temp_object=temp) workflow_script = workflow.newContent(id=script_id, portal_type='Workflow Script', temp_object=is_temporary)
workflow_script.setTitle(script.title) workflow_script.setTitle(script.title)
workflow_script.default_reference = script_id workflow_script.default_reference = script_id
workflow_script.setParameterSignature(script._params) workflow_script.setParameterSignature(script._params)
...@@ -498,31 +495,32 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -498,31 +495,32 @@ 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)
dc_workflow_variable_list = dc_workflow.variables for variable_id, variable_definition in dc_workflow.variables.items():
for vid in dc_workflow_variable_list: variable = workflow.newContent(portal_type='Variable', temp_object=is_temporary)
vdef = dc_workflow_variable_list.get(vid) variable.setTitle(variable_definition.title)
variable = workflow.newContent(portal_type='Variable', temp_object=temp) variable.setReference(variable_id)
variable.setTitle(vdef.title) variable.setAutomaticUpdate(variable_definition.update_always)
variable.setReference(vdef.id) if getattr(variable_definition, 'default_expr', None) is not None:
variable.setAutomaticUpdate(vdef.update_always)
if getattr(vdef, 'default_expr', None) is not None:
# for a very specific case, action return the reference of transition # for a very specific case, action return the reference of transition
# in order to generation correct workflow history. # in order to generation correct workflow history.
if vid == 'action': LOG("### workflow:", INFO, workflow)
LOG("### variable_definition:", INFO, variable_definition)
if variable_id == 'action':
variable.setDefaultExpression('transition/getReference|nothing') variable.setDefaultExpression('transition/getReference|nothing')
else: variable.setDefaultExpression(vdef.default_expr.text) else:
if vdef.info_guard: variable.setDefaultExpression(variable_definition.default_expr.text)
variable.info_guard = vdef.info_guard if variable_definition.info_guard:
variable.setRoleList(vdef.info_guard.roles) variable.info_guard = variable_definition.info_guard
variable.setPermissionList(vdef.info_guard.permissions) variable.setRoleList(variable_definition.info_guard.roles)
variable.setGroupList(vdef.info_guard.groups) variable.setPermissionList(variable_definition.info_guard.permissions)
if vdef.info_guard.expr is not None: variable.setGroupList(variable_definition.info_guard.groups)
if variable_definition.info_guard.expr is not None:
# Here add expression text, convert to expression in getMatchVar. # Here add expression text, convert to expression in getMatchVar.
variable.setExpression(tdef.info_guard.expr.text) variable.setExpression(tdef.info_guard.expr.text)
variable.setForCatalog(vdef.for_catalog) variable.setForCatalog(variable_definition.for_catalog)
variable.setForStatus(vdef.for_status) variable.setForStatus(variable_definition.for_status)
variable.setInitialValue(vdef.default_value) variable.setInitialValue(variable_definition.default_value)
variable.setDescription(vdef.description) variable.setDescription(variable_definition.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:
dc_workflow_transition_value_list = dc_workflow.transitions dc_workflow_transition_value_list = dc_workflow.transitions
...@@ -534,7 +532,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -534,7 +532,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
var_exprs = {} var_exprs = {}
else: var_exprs = origin_tdef.var_exprs else: var_exprs = origin_tdef.var_exprs
for key in var_exprs: for key in var_exprs:
tr_var = transition.newContent(portal_type='Transition Variable', temp_object=temp) tr_var = transition.newContent(portal_type='Transition Variable', temp_object=is_temporary)
tr_var.setDefaultExpression(var_exprs[key].text) tr_var.setDefaultExpression(var_exprs[key].text)
tr_var_path = getattr(workflow, 'variable_'+key).getPath() tr_var_path = getattr(workflow, 'variable_'+key).getPath()
tr_var_path = '/'.join(tr_var_path.split('/')[2:]) tr_var_path = '/'.join(tr_var_path.split('/')[2:])
...@@ -551,7 +549,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -551,7 +549,7 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
var_exprs = {} var_exprs = {}
else: var_exprs = origin_tdef.var_exprs else: var_exprs = origin_tdef.var_exprs
for key in var_exprs: for key in var_exprs:
tr_var = interaction.newContent(portal_type='Transition Variable', temp_object=temp) tr_var = interaction.newContent(portal_type='Transition Variable', temp_object=is_temporary)
tr_var.setDefaultExpression(var_exprs[key].text) tr_var.setDefaultExpression(var_exprs[key].text)
tr_var_path = getattr(workflow, 'variable_'+key).getPath() tr_var_path = getattr(workflow, 'variable_'+key).getPath()
tr_var_path = '/'.join(tr_var_path.split('/')[2:]) tr_var_path = '/'.join(tr_var_path.split('/')[2:])
......
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