Commit 0fcbca5e authored by wenjie.zheng's avatar wenjie.zheng Committed by Sebastien Robin

WorkflowTool.py: add workfow conversion related functions.

parent dd9a31cd
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
# #
############################################################################## ##############################################################################
import cPickle
import os import os
import shutil import shutil
import sys import sys
...@@ -34,7 +35,6 @@ import subprocess ...@@ -34,7 +35,6 @@ import subprocess
import time import time
import transaction import transaction
import struct import struct
import cPickle
import urllib2 import urllib2
import re import re
...@@ -215,23 +215,6 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -215,23 +215,6 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
raise WorkflowException(msg) raise WorkflowException(msg)
return res return res
def getWorkflowTempObjectList(self):
""" Return a list of converted temporary workflows. Only necessary in
Workflow Tool to get temporarilly converted DCWorkflow.
"""
temp_workflow_list = []
temp_workflow_id_list = []
for dc_workflow_id in self.getPortalObject().portal_workflow:
dc_workflow = self.getPortalObject().portal_workflow.get(dc_workflow_id)
workflow_type = dc_workflow.__class__.__name__
if workflow_type == 'Workflow' or workflow_type == 'Interaction Workflow':
continue
temp_obj = 1
temp_workflow = self.dc_workflow_asERP5Object(self, dc_workflow, temp_obj)
temp_workflow_list.append(temp_workflow)
temp_workflow_id_list.append(temp_workflow.getTitle())
return temp_workflow_list
def getWorkflowValueListFor(self, portal_type_id): def getWorkflowValueListFor(self, portal_type_id):
""" Return a list of workflows bound to selected portal_type. """ Return a list of workflows bound to selected portal_type.
""" """
...@@ -264,113 +247,158 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -264,113 +247,158 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
return wfh[-1] return wfh[-1]
return None return None
def decodeWorkflowUid(self, uid):
return cPickle.loads(b64decode(uid))
def encodeWorkflowUid(self, id):
return b64encode(cPickle.dumps(id))
def getObjectFromPath(self, path):
return self.unrestrictedTraverse(path)
def getWorkflowTempObjectList(self, temp_obj=1):
""" Return a list of converted temporary workflows. Only necessary in
Workflow Tool to get temporarilly converted DCWorkflow.
"""
temp_workflow_list = []
temp_workflow_id_list = []
for dc_workflow in self.getPortalObject().portal_workflow.objectValues():
LOG( "Getting workflow '%s'"%dc_workflow.id, WARNING, " in WorkflowTool.py 257")
workflow_type = dc_workflow.__class__.__name__
if workflow_type == 'Workflow' or workflow_type == 'Interaction Workflow':
LOG( "Ingore workflow '%s'"%dc_workflow.id, WARNING, " in WorkflowTool.py 260")
continue
temp_workflow = self.dc_workflow_asERP5Object(self, dc_workflow, 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): def dc_workflow_asERP5Object(self, container, dc_workflow, temp):
# create a temporary ERP5 Workflow # create a temporary ERP5 Workflow
workflow_type_id = dc_workflow.__class__.__name__ workflow_type_id = dc_workflow.__class__.__name__
if workflow_type_id == 'DCWorkflowDefinition': if workflow_type_id == 'DCWorkflowDefinition':
LOG("2.a Workflow '%s' is a DCWorkflow'"%dc_workflow.id,WARNING,' in WorkflowTool.py') LOG("2.a Workflow '%s' is a DCWorkflow'"%dc_workflow.id,WARNING,' in WorkflowTool.py')
workflow = container.newContent(portal_type='Workflow', temp_object=temp) if temp == 0:
new_id = 'workflow_' + dc_workflow.id
else:
new_id = dc_workflow.id
uid = self.encodeWorkflowUid(new_id)
workflow = container.newContent(id=new_id, portal_type='Workflow', temp_object=temp)
LOG(" New workflow created '%s' '%s'"%(workflow.getId(), workflow.getPortalType()), WARNING, "in WorkfowTool.py")
workflow.setStateVariable(dc_workflow.state_var) workflow.setStateVariable(dc_workflow.state_var)
workflow.setWorkflowManagedPermission(dc_workflow.permissions) workflow.setWorkflowManagedPermission(dc_workflow.permissions)
workflow.setSource(dc_workflow.initial_state)
else: else:
LOG("2.b Workflow '%s' is a DC Interaction Workflow"%dc_workflow.getTitle(),WARNING,' in WorkflowTool.py') LOG("2.b Workflow '%s' is a DC Interaction Workflow"%dc_workflow.getTitle(),WARNING,' in WorkflowTool.py')
workflow = container.newContent(portal_type='Interaction Workflow', temp_object=temp) if temp == 0:
new_id = 'interactionworkflow_' + 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)
LOG(" New workflow created '%s' '%s'"%(workflow.getId(), workflow.getPortalType()), WARNING, "in WorkfowTool.py")
workflow.setManagerBypass(dc_workflow.manager_bypass) workflow.setManagerBypass(dc_workflow.manager_bypass)
workflow.setReference(dc_workflow.id) if temp == 1:
# give temp workflow an uid for form_dialog.
workflow.uid = uid
workflow.default_reference = dc_workflow.id
workflow.edit(title=dc_workflow.title) workflow.edit(title=dc_workflow.title)
workflow.edit(description=dc_workflow.description) workflow.edit(description=dc_workflow.description)
# create transitions if temp == 0: # convert under request only
if workflow_type_id == 'DCWorkflowDefinition': LOG("Converting DCWorkflow", WARNING, " in WorkflowTool.py")
for tid in dc_workflow.transitions: # create transitions
tdef = dc_workflow.transitions.get(tid) if workflow_type_id == 'DCWorkflowDefinition':
LOG("2.1 Convert transition '%s' of workflow '%s'"%(tdef.id,workflow.getTitle()),WARNING,' in WorkflowTool.py') for tid in dc_workflow.transitions:
transition = workflow.newContent(portal_type='Transition', temp_object=temp) tdef = dc_workflow.transitions.get(tid)
transition.edit(title=tdef.title) LOG("2.1 Convert transition '%s' of workflow '%s'"%(tdef.id,workflow.getTitle()),WARNING,' in WorkflowTool.py')
transition.setReference(tdef.id) transition = workflow.newContent(portal_type='Transition', temp_object=temp)
transition.setTriggerType(tdef.trigger_type) transition.edit(title=tdef.title)
transition.setActboxCategory(tdef.actbox_category) transition.setReference(tdef.id)
transition.setActboxIcon(tdef.actbox_icon) transition.setTriggerType(tdef.trigger_type)
transition.setActboxName(tdef.actbox_name) transition.setActboxCategory(tdef.actbox_category)
transition.setActboxUrl(tdef.actbox_url) transition.setActboxIcon(tdef.actbox_icon)
transition.setAfterScriptId(tdef.after_script_name) transition.setActboxName(tdef.actbox_name)
transition.setBeforeScriptId(tdef.script_name) transition.setActboxUrl(tdef.actbox_url)
transition.setDestination(tdef.new_state_id) transition.setAfterScriptId(tdef.after_script_name)
transition.guard = tdef.guard transition.setBeforeScriptId(tdef.script_name)
# create states (portal_type = State) transition.setDestination(tdef.new_state_id)
for sid in dc_workflow.states: transition.guard = tdef.guard
sdef = dc_workflow.states.get(sid) # create states (portal_type = State)
LOG("2.2 Convert state '%s' of workflow '%s'"%(sdef.id,workflow.getTitle()),WARNING,' in WorkflowTool.py') for sid in dc_workflow.states:
state = workflow.newContent(portal_type='State', temp_object=temp) sdef = dc_workflow.states.get(sid)
state.edit(title=sdef.title) LOG("2.2 Convert state '%s' of workflow '%s'"%(sdef.id,workflow.getTitle()),WARNING,' in WorkflowTool.py')
state.setReference(sdef.id) state = workflow.newContent(portal_type='State', temp_object=temp)
state.setStatePermissionRoles(sdef.permission_roles) state.edit(title=sdef.title)
state.setDestinationList(sdef.transitions) state.setReference(sdef.id)
# create worklists (portal_type = Worklist) state.setStatePermissionRoles(sdef.permission_roles)
for qid in dc_workflow.worklists: state.setDestinationList(sdef.transitions)
qdef = dc_workflow.worklists.get(qid) workflow.setSource(getattr(workflow, 'state_'+dc_workflow.initial_state).getPath())
LOG("2.3 Convert worklist '%s' of workflow '%s'"%(qdef.id,workflow.getTitle()),WARNING,' in WorkflowTool.py') # create worklists (portal_type = Worklist)
worklist = workflow.newContent(portal_type='Worklist', temp_object=temp) for qid in dc_workflow.worklists:
worklist.edit(title=qdef.title) qdef = dc_workflow.worklists.get(qid)
worklist.setReference(qdef.id) LOG("2.3 Convert worklist '%s' of workflow '%s'"%(qdef.id,workflow.getTitle()),WARNING,' in WorkflowTool.py')
for key, values in qdef.var_matches.items(): worklist = workflow.newContent(portal_type='Worklist', temp_object=temp)
if key == 'portal_type': worklist.edit(title=qdef.title)
worklist.setMatchedPortalTypeList(values) worklist.setReference(qdef.id)
elif key == 'simulation_state': for key, values in qdef.var_matches.items():
worklist.setMatchedSimulationStateList(values) if key == 'portal_type':
elif key == 'validation_state': worklist.setMatchedPortalTypeList(values)
worklist.setMatchedValidationStateList(values) elif key == 'simulation_state':
worklist.setActboxCategory(qdef.actbox_category) worklist.setMatchedSimulationStateList(values)
worklist.setActboxIcon(qdef.actbox_icon) elif key == 'validation_state':
worklist.setActboxName(qdef.actbox_name) worklist.setMatchedValidationStateList(values)
worklist.setActboxUrl(qdef.actbox_url) worklist.setActboxCategory(qdef.actbox_category)
worklist.guard = qdef.guard worklist.setActboxIcon(qdef.actbox_icon)
else: worklist.setActboxName(qdef.actbox_name)
for tid in dc_workflow.interactions: worklist.setActboxUrl(qdef.actbox_url)
interaction = workflow.newContent(portal_type='Interaction', temp_object=temp) worklist.guard = qdef.guard
tdef = dc_workflow.interactions.get(tid) else:
LOG("2.4 Convert interaction '%s' of workflow '%s'"%(tdef.id,workflow.getTitle()),WARNING,' in WorkflowTool.py') for tid in dc_workflow.interactions:
interaction.edit(title=tdef.title) interaction = workflow.newContent(portal_type='Interaction', temp_object=temp)
interaction.setReference(tdef.id) tdef = dc_workflow.interactions.get(tid)
interaction.setActivateScriptName(tdef.activate_script_name) LOG("2.4 Convert interaction '%s' of workflow '%s'"%(tdef.id,workflow.getTitle()),WARNING,' in WorkflowTool.py')
interaction.setAfterScriptName(tdef.after_script_name) interaction.edit(title=tdef.title)
interaction.setBeforeCommitScriptName(tdef.before_commit_script_name) interaction.setReference(tdef.id)
interaction.setBeforeScriptName(tdef.script_name) interaction.setActivateScriptName(tdef.activate_script_name)
interaction.guard = tdef.guard interaction.setAfterScriptName(tdef.after_script_name)
interaction.setPortalTypeFilter(tdef.portal_type_filter) interaction.setBeforeCommitScriptName(tdef.before_commit_script_name)
interaction.setPortalTypeGroupFilter(tdef.portal_type_group_filter) interaction.setBeforeScriptName(tdef.script_name)
interaction.setTemporaryDocumentDisallowed(tdef.temporary_document_disallowed) interaction.guard = tdef.guard
#interaction.setTransitionFormId() # this is not defined in DC interaction? interaction.setPortalTypeFilter(tdef.portal_type_filter)
interaction.setTriggerMethodId(tdef.method_id) interaction.setPortalTypeGroupFilter(tdef.portal_type_group_filter)
interaction.setTriggerOncePerTransaction(tdef.once_per_transaction) interaction.setTemporaryDocumentDisallowed(tdef.temporary_document_disallowed)
interaction.setTriggerType(tdef.trigger_type) #interaction.setTransitionFormId() # this is not defined in DC interaction?
interaction.setTriggerMethodId(tdef.method_id)
# create scripts (portal_type = Workflow Script) interaction.setTriggerOncePerTransaction(tdef.once_per_transaction)
for script_id in dc_workflow.scripts: interaction.setTriggerType(tdef.trigger_type)
script = dc_workflow.scripts.get(script_id)
workflow_script = workflow.newContent(portal_type='Workflow Script', temp_object=temp) # create scripts (portal_type = Workflow Script)
LOG("2.5 Convert workflow script '%s' of workflow '%s'"%(workflow_script.id,workflow.getTitle()),WARNING,' in WorkflowTool.py') for script_id in dc_workflow.scripts:
workflow_script.edit(title=script.title) script = dc_workflow.scripts.get(script_id)
workflow_script.setId(script.id) workflow_script = workflow.newContent(portal_type='Workflow Script', temp_object=temp)
workflow_script.setParameterSignature(script._params) LOG("2.5 Convert workflow script '%s' of workflow '%s'"%(workflow_script.id,workflow.getTitle()),WARNING,' in WorkflowTool.py')
#workflow_script.setCallableType(script.callable_type)# not defined in DC script? workflow_script.edit(title=script.title)
workflow_script.setBody(script._body) workflow_script.id = script.id
workflow_script.setProxyRole(script._proxy_roles) workflow_script.setParameterSignature(script._params)
# create variables (portal_type = Variable) #workflow_script.setCallableType(script.callable_type)# not defined in python script?
for vid in dc_workflow.variables: workflow_script.setBody(script._body)
vdef = dc_workflow.variables.get(vid) workflow_script.setProxyRole(script._proxy_roles)
variable = workflow.newContent(portal_type='Variable', temp_object=temp) # create variables (portal_type = Variable)
LOG("2.6 Convert variable '%s' of workflow '%s'"%(vdef.id,workflow.getTitle()),WARNING,' in WorkflowTool.py') for vid in dc_workflow.variables:
variable.edit(title=vdef.title) vdef = dc_workflow.variables.get(vid)
variable.setReference(vdef.id) variable = workflow.newContent(portal_type='Variable', temp_object=temp)
variable.setAutomaticUpdate(vdef.update_always) LOG("2.6 Convert variable '%s' of workflow '%s'"%(vdef.id,workflow.getTitle()),WARNING,' in WorkflowTool.py')
variable.setDefaultExpr(vdef.default_expr) variable.edit(title=vdef.title)
variable.info_guard = vdef.info_guard variable.setReference(vdef.id)
variable.setForCatalog(vdef.for_catalog) variable.setAutomaticUpdate(vdef.update_always)
variable.setForStatus(vdef.for_status) variable.setDefaultExpr(vdef.default_expr)
variable.setInitialValue(vdef.default_value) variable.info_guard = vdef.info_guard
variable.setForCatalog(vdef.for_catalog)
variable.setForStatus(vdef.for_status)
variable.setInitialValue(vdef.default_value)
return workflow return workflow
def getChainDict(self): def getChainDict(self):
...@@ -535,6 +563,12 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -535,6 +563,12 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
return getattr(self, return getattr(self,
'Base_getWorklistIgnoredSecurityColumnSet', lambda: ())() 'Base_getWorklistIgnoredSecurityColumnSet', lambda: ())()
def getTypeCBT(self, pt):
return self._chains_by_type.get(pt)
def delTypeCBT(self, pt, wf_id):
self._chains_by_type = tuple(list(self._chains_by_type).remove(wf_id))
def listActions(self, info=None, object=None, src__=False): def listActions(self, info=None, object=None, src__=False):
""" """
Returns a list of actions to be displayed to the user. Returns a list of actions to be displayed to the user.
......
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