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