Commit 4e77594b authored by iv's avatar iv

ERP5Workflow: replace getTransitionValueDict

add workflow method to get transitions list and by id
  getTransitionValueList
  getTransitionValueById
parent 97daa701
...@@ -28,8 +28,8 @@ def get_obj_and_reference_list(business_field): ...@@ -28,8 +28,8 @@ def get_obj_and_reference_list(business_field):
result.append((wf, wf_id, 'workflow')) result.append((wf, wf_id, 'workflow'))
for state in wf.getStateValueList(): for state in wf.getStateValueList():
result.append((state, state.getReference(), 'state')) result.append((state, state.getReference(), 'state'))
for trans_id, trans in wf.getTransitionValueDict().items(): for trans in wf.getTransitionValueList():
result.append((trans, trans_id, 'transition')) result.append((trans, trans.getReference(), 'transition'))
if trans.trigger_type == 1 and trans.actbox_name: # 1 == TRIGGER_USER_ACTION if trans.trigger_type == 1 and trans.actbox_name: # 1 == TRIGGER_USER_ACTION
result.append((trans, "%s_actbox_name" % trans_id, 'action')) result.append((trans, "%s_actbox_name" % trans_id, 'action'))
return result return result
......
...@@ -26,10 +26,10 @@ def get_obj_and_reference_list(business_field): ...@@ -26,10 +26,10 @@ def get_obj_and_reference_list(business_field):
wf = getattr(portal_workflow, wf_id) wf = getattr(portal_workflow, wf_id)
if getattr(wf, "interactions", marker) is marker: # only way to make sure it is not an interaction workflow ? if getattr(wf, "interactions", marker) is marker: # only way to make sure it is not an interaction workflow ?
result.append((wf, wf_id, 'workflow')) result.append((wf, wf_id, 'workflow'))
for state_id, state in wf.getStateValueDict().items(): for state in wf.getStateValueList():
result.append((state, state_id, 'state')) result.append((state, state.getReference(), 'state'))
for trans_id, trans in wf.getTransitionValueDict().items(): for trans in wf.getTransitionValueList():
result.append((trans, trans_id, 'transition')) result.append((trans, trans.getReference(), 'transition'))
if trans.trigger_type == 1 and trans.actbox_name: # 1 == TRIGGER_USER_ACTION if trans.trigger_type == 1 and trans.actbox_name: # 1 == TRIGGER_USER_ACTION
result.append((trans, "%s_actbox_name" % trans_id, 'action')) result.append((trans, "%s_actbox_name" % trans_id, 'action'))
return result return result
......
...@@ -107,22 +107,21 @@ for i in page_template_list: ...@@ -107,22 +107,21 @@ for i in page_template_list:
s_title_list = [] s_title_list = []
for i in context.portal_workflow.objectValues(): for i in context.portal_workflow.objectValues():
add_message(i.title_or_id(), portal_url.getRelativeContentURL(i)) add_message(i.title_or_id(), portal_url.getRelativeContentURL(i))
state_value_dict = i.getStateValueDict() state_value_list = i.getStateValueList()
if not state_value_dict: if not state_value_list:
continue continue
for s_id, s in state_value_dict.items(): for s in state_value_list:
s_title = s.title if s.title:
if s_title:
# adding a context in msg_id for more precise translation # adding a context in msg_id for more precise translation
msg_id = getMessageIdWithContext(s_title,'state',i.id) msg_id = getMessageIdWithContext(s.title,'state',i.id)
add_message(msg_id, portal_url.getRelativeContentURL(s)) add_message(msg_id, portal_url.getRelativeContentURL(s))
# also use state title as msg_id for compatibility # also use state title as msg_id for compatibility
add_message(s_title, portal_url.getRelativeContentURL(s)) add_message(s.title, portal_url.getRelativeContentURL(s))
transition_value_dict = i.getTransitionValueDict() transition_value_list = i.getTransitionValueList()
if not transition_value_dict: if not transition_value_list:
continue continue
for t in transition_value_dict.values(): for t in transition_value_list:
if t.actbox_name: if t.actbox_name:
#adding a context in msg_id for more precise translation #adding a context in msg_id for more precise translation
msg_id = getMessageIdWithContext(t.actbox_name,'transition',i.id) msg_id = getMessageIdWithContext(t.actbox_name,'transition',i.id)
......
...@@ -310,12 +310,12 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=0): ...@@ -310,12 +310,12 @@ def fixSkinNames(self, REQUEST=None, file=None, dry_run=0):
# Workflows. # Workflows.
for wf in self.portal_workflow.objectValues(): for wf in self.portal_workflow.objectValues():
# Transitions. # Transitions.
for id, transition in wf.getTransitionValueDict().items(): for transition in wf.getTransitionValueList():
text = transition.actbox_url text = transition.actbox_url
for info in info_list: for info in info_list:
if info.regexp.search(text) is not None: if info.regexp.search(text) is not None:
text = info.regexp.sub(info.new_name, text) text = info.regexp.sub(info.new_name, text)
line = 'Transition %s of %s is modified for %s' % (id, 'portal_workflow/' + wf.id, info.name) line = 'Transition %s of %s is modified for %s' % (transition.getReference(), 'portal_workflow/' + wf.id, info.name)
LOG('fixSkinNames', 0, line) LOG('fixSkinNames', 0, line)
msg += '%s\n' % line msg += '%s\n' % line
if not dry_run: if not dry_run:
......
...@@ -33,8 +33,7 @@ from Products.CMFActivity.ActiveObject import ActiveObject ...@@ -33,8 +33,7 @@ from Products.CMFActivity.ActiveObject import ActiveObject
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
# show as xml library # show as xml library
from lxml import etree from lxml.etree import Element, SubElement, tostring
from lxml.etree import Element, SubElement
_MARKER = [] _MARKER = []
...@@ -352,15 +351,20 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject): ...@@ -352,15 +351,20 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject):
def getReference(self): def getReference(self):
return self.id return self.id
def getTransitionValueDict(self): def getTransitionValueById(self, transition_id):
if self.interactions is not None: if self.interactions is not None:
return self.interactions return self.interactions.get(transition_id, None)
return None return None
def getTransitionValueList(self):
if self.interactions is not None:
return self.interactions.values()
return []
def getTransitionIdList(self): def getTransitionIdList(self):
if self.interactions is not None: if self.interactions is not None:
return self.interactions.objectIds() return self.interactions.objectIds()
return None return []
def getPortalType(self): def getPortalType(self):
return self.__class__.__name__ return self.__class__.__name__
...@@ -501,7 +505,7 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject): ...@@ -501,7 +505,7 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject):
# return xml object # return xml object
if return_as_object: if return_as_object:
return root return root
return etree.tostring(root, encoding='utf-8', return tostring(root, encoding='utf-8',
xml_declaration=True, pretty_print=True) xml_declaration=True, pretty_print=True)
Globals.InitializeClass(InteractionWorkflowDefinition) Globals.InitializeClass(InteractionWorkflowDefinition)
......
...@@ -28,13 +28,10 @@ def getActorName(actor): ...@@ -28,13 +28,10 @@ def getActorName(actor):
actor_name_cache[actor] = person.getTitle() actor_name_cache[actor] = person.getTitle()
return actor_name_cache[actor] return actor_name_cache[actor]
# Get history # Get history
# XXX Compatibility # XXX Compatibility
workflow = getattr(portal_workflow, workflow_id) workflow = getattr(portal_workflow, workflow_id)
wf_state_variable = workflow.getStateVariable() wf_state_variable = workflow.getStateVariable()
wf_transitions = workflow.getTransitionValueDict()
next_serial = None next_serial = None
previous_obj = None previous_obj = None
...@@ -68,10 +65,12 @@ for workflow_item in portal_workflow.getInfoFor(ob=context, name='history', ...@@ -68,10 +65,12 @@ for workflow_item in portal_workflow.getInfoFor(ob=context, name='history',
if value != '' and value is not None: if value != '' and value is not None:
if value == "'edit'": if value == "'edit'":
value = "edit" value = "edit"
transition = workflow.getTransitionValueById(value)
if transition:
if display: if display:
value = wf_transitions.get(value, marker) and (wf_transitions[value].title or wf_transitions[value].actbox_name) or value value = transition.title or transition.actbox_name
else: else:
value = wf_transitions.get(value, marker) and (wf_transitions[value].getReference() or wf_transitions[value].actbox_name) or value value = transition.getReference() or transition.actbox_name
if display: if display:
if key == 'error_message': if key == 'error_message':
if same_type(value, ''): if same_type(value, ''):
......
...@@ -116,7 +116,7 @@ class WorkflowSecurityConfiguratorItem(ConfiguratorItemMixin, XMLObject): ...@@ -116,7 +116,7 @@ class WorkflowSecurityConfiguratorItem(ConfiguratorItemMixin, XMLObject):
transition_list = table_dict['transition'] transition_list = table_dict['transition']
for transition_conf in transition_list: for transition_conf in transition_list:
transition_id = transition_conf.pop('transition') transition_id = transition_conf.pop('transition')
transition = workflow.getTransitionValueDict()[transition_id] transition = workflow.getTransitionValueById(transition_id)
guard = transition.getGuard() guard = transition.getGuard()
role_list = [x.capitalize() for x in transition_conf.keys()] role_list = [x.capitalize() for x in transition_conf.keys()]
role_string = ';'.join(role_list) role_string = ';'.join(role_list)
......
...@@ -484,11 +484,11 @@ def getClassPropertyList(klass): ...@@ -484,11 +484,11 @@ def getClassPropertyList(klass):
def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow): def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow):
"""We should now make sure workflow methods are defined """We should now make sure workflow methods are defined
and also make sure simulation state is defined.""" and also make sure simulation state is defined."""
# aq_inner is required to prevent extra name lookups from happening # aq_inner is required to prevent extra name lookups from happening
# infinitely. For instance, if a workflow is missing, and the acquisition # infinitely. For instance, if a workflow is missing, and the acquisition
# wrapper contains an object with _aq_dynamic defined, the workflow id # wrapper contains an object with _aq_dynamic defined, the workflow id
# is looked up with _aq_dynamic, thus causes infinite recursions. # is looked up with _aq_dynamic, thus causes infinite recursions.
portal_workflow = aq_inner(portal_workflow) portal_workflow = aq_inner(portal_workflow)
portal_type = ptype_klass.__name__ portal_type = ptype_klass.__name__
...@@ -517,10 +517,8 @@ def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow): ...@@ -517,10 +517,8 @@ def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow):
Permissions.AccessContentsInformation) Permissions.AccessContentsInformation)
storage = workflow_dict storage = workflow_dict
transitions = wf.getTransitionValueDict()
elif wf_type in ['InteractionWorkflowDefinition', 'Interaction Workflow']: elif wf_type in ['InteractionWorkflowDefinition', 'Interaction Workflow']:
storage = interaction_workflow_dict storage = interaction_workflow_dict
transitions = wf.getTransitionValueDict()
else: else:
continue continue
...@@ -529,7 +527,7 @@ def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow): ...@@ -529,7 +527,7 @@ def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow):
trigger_dict = {} trigger_dict = {}
for tr_id in transition_id_set: for tr_id in transition_id_set:
tdef = transitions[tr_id] tdef = wf.getTransitionValueById(tr_id)
if tdef.trigger_type == TRIGGER_WORKFLOW_METHOD: if tdef.trigger_type == TRIGGER_WORKFLOW_METHOD:
trigger_dict[tr_id] = tdef trigger_dict[tr_id] = tdef
......
...@@ -802,6 +802,10 @@ def DCWorkflowDefinition_getVariableIdList(self): ...@@ -802,6 +802,10 @@ def DCWorkflowDefinition_getVariableIdList(self):
return [] return []
def DCWorkflowDefinition_getStateVariable(self): def DCWorkflowDefinition_getStateVariable(self):
return self.state_var return self.state_var
def DCWorkflowDefinition_getStateValueById(self, state_id):
if self.states is not None:
return self.states.get(state_id, None)
return None
def DCWorkflowDefinition_getStateValueList(self): def DCWorkflowDefinition_getStateValueList(self):
if self.states is not None: if self.states is not None:
return self.states.values() return self.states.values()
...@@ -810,11 +814,15 @@ def DCWorkflowDefinition_getStateIdList(self): ...@@ -810,11 +814,15 @@ def DCWorkflowDefinition_getStateIdList(self):
if self.states is not None: if self.states is not None:
return self.states.objectIds() return self.states.objectIds()
return [] return []
def DCWorkflowDefinition_getTransitionValueDict(self): def DCWorkflowDefinition_getTransitionValueById(self, transition_id):
if self.transitions is not None: if self.transitions is not None:
return self.transitions return self.transitions.get(transition_id, None)
return None
def DCWorkflowDefinition_getTransitionValueList(self):
if self.transitions is not None:
return self.transitions.values()
else: else:
return {} return []
def DCWorkflowDefinition_getTransitionIdList(self): def DCWorkflowDefinition_getTransitionIdList(self):
if self.transitions is not None: if self.transitions is not None:
return self.transitions.objectIds() return self.transitions.objectIds()
...@@ -1085,8 +1093,10 @@ DCWorkflowDefinition.notifyWorkflowMethod = DCWorkflowDefinition_notifyWorkflowM ...@@ -1085,8 +1093,10 @@ DCWorkflowDefinition.notifyWorkflowMethod = DCWorkflowDefinition_notifyWorkflowM
DCWorkflowDefinition.notifyBefore = DCWorkflowDefinition_notifyBefore DCWorkflowDefinition.notifyBefore = DCWorkflowDefinition_notifyBefore
DCWorkflowDefinition.notifySuccess = DCWorkflowDefinition_notifySuccess DCWorkflowDefinition.notifySuccess = DCWorkflowDefinition_notifySuccess
DCWorkflowDefinition.getVariableValueDict = DCWorkflowDefinition_getVariableValueDict DCWorkflowDefinition.getVariableValueDict = DCWorkflowDefinition_getVariableValueDict
DCWorkflowDefinition.getStateValueById = DCWorkflowDefinition_getStateValueById
DCWorkflowDefinition.getStateValueList = DCWorkflowDefinition_getStateValueList DCWorkflowDefinition.getStateValueList = DCWorkflowDefinition_getStateValueList
DCWorkflowDefinition.getTransitionValueDict = DCWorkflowDefinition_getTransitionValueDict DCWorkflowDefinition.getTransitionValueById = DCWorkflowDefinition_getTransitionValueById
DCWorkflowDefinition.getTransitionValueList = DCWorkflowDefinition_getTransitionValueList
DCWorkflowDefinition.getWorklistValueDict = DCWorkflowDefinition_getWorklistValueDict DCWorkflowDefinition.getWorklistValueDict = DCWorkflowDefinition_getWorklistValueDict
DCWorkflowDefinition.getScriptValueDict = DCWorkflowDefinition_getScriptValueDict DCWorkflowDefinition.getScriptValueDict = DCWorkflowDefinition_getScriptValueDict
DCWorkflowDefinition.getVariableIdList = DCWorkflowDefinition_getVariableIdList DCWorkflowDefinition.getVariableIdList = DCWorkflowDefinition_getVariableIdList
......
...@@ -1013,13 +1013,18 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin): ...@@ -1013,13 +1013,18 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
continue continue
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)
new_workflow = workflow_tool.dc_workflow_asERP5Object(workflow_tool, workflow, temp=0) new_workflow = workflow_tool.dc_workflow_asERP5Object(workflow_tool, workflow, temp=0)
workflow_tool.reassignWorkflow(workflow_id) workflow_tool.reassignWorkflow(workflow_id)
self.commit()
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(workflow_tool, edit_workflow, temp=0)
workflow_tool.reassignWorkflow('edit_workflow') workflow_tool.reassignWorkflow('edit_workflow')
LOG("### edit workflow" , 0, "after reassignment")
self.commit()
# Reset the original workflows assignement order. # Reset the original workflows assignement order.
for type_value in sorted(type_tool.objectValues()): for type_value in sorted(type_tool.objectValues()):
type_value.workflow_list = tuple(reversed(type_value.workflow_list)) type_value.workflow_list = tuple(reversed(type_value.workflow_list))
......
...@@ -219,7 +219,7 @@ class SecurityTestCase(ERP5TypeTestCase): ...@@ -219,7 +219,7 @@ class SecurityTestCase(ERP5TypeTestCase):
continue continue
for wf_transition_id in wf._getWorkflowStateOf( for wf_transition_id in wf._getWorkflowStateOf(
document).getTransitions(): document).getTransitions():
wf_transition = wf.getTransitionValueDict()[wf_transition_id] wf_transition = wf.getTransitionValueById(wf_transition_id)
if wf_transition.trigger_type == TRIGGER_USER_ACTION: if wf_transition.trigger_type == TRIGGER_USER_ACTION:
workflow_transitions_description.append( workflow_transitions_description.append(
"%s%s[%s]: %s" % ( "%s%s[%s]: %s" % (
......
...@@ -194,12 +194,21 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -194,12 +194,21 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
scripts[script.getReference()] = script scripts[script.getReference()] = script
return scripts return scripts
security.declarePrivate('getTransitionValueDict') security.declarePrivate('getTransitionValueById')
def getTransitionValueDict(self): def getTransitionValueById(self, transition_id):
interaction_dict = {} return self._getOb('interaction_' + transition_id, default=None)
for tdef in self.objectValues(portal_type="Interaction"):
interaction_dict[tdef.getReference()] = tdef security.declarePrivate('getTransitionValueList')
return interaction_dict def getTransitionValueList(self):
return self.objectValues(portal_type="Interaction")
security.declarePrivate('getTransitionValueById')
def getTransitionValueById(self, transition_id):
return self._getOb('interaction_' + transition_id, default=None)
security.declarePrivate('getTransitionValueList')
def getTransitionValueList(self):
return self.objectValues(portal_type="Interaction")
security.declarePrivate('getTransitionIdList') security.declarePrivate('getTransitionIdList')
def getTransitionIdList(self): def getTransitionIdList(self):
......
...@@ -491,19 +491,14 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -491,19 +491,14 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
return id_list return id_list
def getStateValueById(self, stated_id): def getStateValueById(self, stated_id):
# TODO: returns state value for given id or None return self._getOb('state_' + stated_id, default=None)
try:
state_value = self._getOb('state_' + stated_id)
except AttributeError:
state_value = None
return state_value
def getStateValueList(self): def getStateValueList(self):
return self.objectValues(portal_type="State") return self.objectValues(portal_type="State")
def getStateIdList(self): def getStateIdList(self):
id_list = [] id_list = []
for ob in self.ValueobjectValues(portal_type="State"): for ob in self.objectValues(portal_type="State"):
id_list.append(ob.getReference()) id_list.append(ob.getReference())
return id_list return id_list
...@@ -519,11 +514,12 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -519,11 +514,12 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
id_list.append(ob.getReference()) id_list.append(ob.getReference())
return id_list return id_list
def getTransitionValueDict(self): def getTransitionValueById(self, transition_reference):
transition_dict = {} LOG ("### getTransitionValueById", 0, transition_reference)
for tdef in self.objectValues(portal_type="Transition"): return self._getOb('transition_' + transition_reference, None)
transition_dict[tdef.getReference()] = tdef
return transition_dict def getTransitionValueList(self):
return self.objectValues(portal_type="Transition")
def getTransitionIdList(self): def getTransitionIdList(self):
id_list = [] id_list = []
...@@ -746,7 +742,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -746,7 +742,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
raise WorkflowException, 'Object is in an undefined state' raise WorkflowException, 'Object is in an undefined state'
if method_id not in sdef.getTransitionIdList(): if method_id not in sdef.getTransitionIdList():
raise Unauthorized(method_id) raise Unauthorized(method_id)
tdef = self.getTransitionValueDict().get(method_id, None) tdef = self.getTransitionValueById(method_id)
if tdef is None or tdef.getTriggerType() != TRIGGER_WORKFLOW_METHOD: if tdef is None or tdef.getTriggerType() != TRIGGER_WORKFLOW_METHOD:
raise WorkflowException, ( raise WorkflowException, (
'Transition %s is not triggered by a workflow method' 'Transition %s is not triggered by a workflow method'
......
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