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