Commit 6a8a8fb3 authored by Sebastien Robin's avatar Sebastien Robin

Workflow cleanup: put back code changes made on ERP5Type.patches.WorkflowTool

parent c28a1402
...@@ -887,8 +887,8 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -887,8 +887,8 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
sql_catalog.getSQLCatalogSecurityUidGroupsColumnsDict() sql_catalog.getSQLCatalogSecurityUidGroupsColumnsDict()
getSecurityUidDictAndRoleColumnDict = \ getSecurityUidDictAndRoleColumnDict = \
portal_catalog.getSecurityUidDictAndRoleColumnDict portal_catalog.getSecurityUidDictAndRoleColumnDict
search_result = getattr(self, "Base_getCountFromWorklistTable", None) search_result_ = getattr(self, "Base_getCountFromWorklistTable", None)
use_cache = search_result is not None use_cache = search_result_ is not None
if use_cache: if use_cache:
ignored_security_column_id_set = self._getWorklistIgnoredSecurityColumnSet() ignored_security_column_id_set = self._getWorklistIgnoredSecurityColumnSet()
ignored_security_uid_parameter_set = {x ignored_security_uid_parameter_set = {x
...@@ -906,12 +906,26 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -906,12 +906,26 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
ignored_security_uid_parameter_set: ignored_security_uid_parameter_set:
security_uid_dict.pop(ignored_security_uid_parameter) security_uid_dict.pop(ignored_security_uid_parameter)
return security_uid_dict, role_column_dict, local_role_column_dict return security_uid_dict, role_column_dict, local_role_column_dict
select_expression_prefix = 'sum(`%s`) as %s' % (COUNT_COLUMN_TITLE, COUNT_COLUMN_TITLE) count_column_expression = 'sum(`%s`)' % (COUNT_COLUMN_TITLE, )
# Prevent catalog from trying to join # Prevent catalog from trying to join
getQuery = SimpleQuery getQuery = SimpleQuery
# BBB
def search_result(select_dict, group_by, query, limit, src__):
select_item_list = []
for alias, expression in select_dict.iteritems():
if expression is None:
expression = alias
select_item_list.append('%s AS %s' % (expression, alias))
return search_result_(
select_expression=','.join(select_item_list),
group_by_expression=','.join(group_by),
query=query,
limit=limit,
src__=src__,
)
else: else:
search_result = portal_catalog.unrestrictedSearchResults search_result = portal_catalog.unrestrictedSearchResults
select_expression_prefix = 'count(*) as %s' % (COUNT_COLUMN_TITLE, ) count_column_expression = 'count(*)'
# Let catalog join as needed # Let catalog join as needed
getQuery = lambda comparison_operator=None, **kw: AutoQuery( getQuery = lambda comparison_operator=None, **kw: AutoQuery(
operator=comparison_operator, operator=comparison_operator,
...@@ -920,7 +934,6 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -920,7 +934,6 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
worklist_result_dict = {} worklist_result_dict = {}
# Get a list of dict of WorklistVariableMatchDict grouped by compatible # Get a list of dict of WorklistVariableMatchDict grouped by compatible
# conditions # conditions
(worklist_list_grouped_by_condition, worklist_metadata) = \ (worklist_list_grouped_by_condition, worklist_metadata) = \
groupWorklistListByCondition( groupWorklistListByCondition(
worklist_dict=worklist_dict, worklist_dict=worklist_dict,
...@@ -939,18 +952,15 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -939,18 +952,15 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
getQuery=getQuery, getQuery=getQuery,
grouped_worklist_dict=grouped_worklist_dict, grouped_worklist_dict=grouped_worklist_dict,
) )
group_by_expression = ', '.join(total_criterion_id_list) group_by = total_criterion_id_list
assert COUNT_COLUMN_TITLE not in total_criterion_id_list assert COUNT_COLUMN_TITLE not in total_criterion_id_list
# If required mapping method is not present on the query, assume it select_dict = dict.fromkeys(total_criterion_id_list)
# handles column mapping properly, and build a bare select select_dict[COUNT_COLUMN_TITLE] = count_column_expression
# expression.
select_expression = select_expression_prefix + ', ' \
+ group_by_expression
catalog_brain_result = [] catalog_brain_result = []
try: try:
catalog_brain_result = search_result( catalog_brain_result = search_result(
select_expression=select_expression, select_dict=select_dict,
group_by_expression=group_by_expression, group_by=group_by,
query=query, query=query,
limit=None, limit=None,
src__=src__) src__=src__)
...@@ -989,7 +999,6 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -989,7 +999,6 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
key=lambda x: '/'.join((x['workflow_id'], x['worklist_id'])), key=lambda x: '/'.join((x['workflow_id'], x['worklist_id'])),
) )
return action_list return action_list
user = _getAuthenticatedUser(self).getIdOrUserName() user = _getAuthenticatedUser(self).getIdOrUserName()
if src__: if src__:
actions = _getWorklistActionList() actions = _getWorklistActionList()
...@@ -1054,13 +1063,12 @@ from Products.CMFCore import WorkflowCore ...@@ -1054,13 +1063,12 @@ from Products.CMFCore import WorkflowCore
# BBB: WorkflowMethod has been removed from CMFCore 2 # BBB: WorkflowMethod has been removed from CMFCore 2
WorkflowCore.WorkflowAction = WorkflowMethod WorkflowCore.WorkflowAction = WorkflowMethod
def getValidCriterionDict(worklist_match_dict, sql_catalog, workflow_worklist_key): def getValidCriterionDict(worklist_match_dict, sql_catalog,
workflow_worklist_key):
valid_criterion_dict = {} valid_criterion_dict = {}
metadata = None metadata = None
isValidColumn = sql_catalog.isValidColumn isValidColumn = sql_catalog.isValidColumn
for criterion_id, criterion_value in worklist_match_dict.iteritems(): for criterion_id, criterion_value in worklist_match_dict.iteritems():
if criterion_id.startswith('variable_'):
criterion_id = '_'.join(criterion_id.split('_')[1:])
if isValidColumn(criterion_id): if isValidColumn(criterion_id):
if isinstance(criterion_value, tuple): if isinstance(criterion_value, tuple):
criterion_value = list(criterion_value) criterion_value = list(criterion_value)
...@@ -1089,7 +1097,10 @@ def updateWorklistSetDict(worklist_set_dict, workflow_worklist_key, valid_criter ...@@ -1089,7 +1097,10 @@ def updateWorklistSetDict(worklist_set_dict, workflow_worklist_key, valid_criter
worklist_set_dict[worklist_set_dict_key]\ worklist_set_dict[worklist_set_dict_key]\
[workflow_worklist_key] = valid_criterion_dict [workflow_worklist_key] = valid_criterion_dict
def groupWorklistListByCondition(worklist_dict, sql_catalog, getSecurityUidDictAndRoleColumnDict=None, catalog_security_uid_groups_columns_dict=None,): def groupWorklistListByCondition(worklist_dict, sql_catalog,
getSecurityUidDictAndRoleColumnDict=None,
catalog_security_uid_groups_columns_dict=None,
):
""" """
Get a list of dict of WorklistVariableMatchDict grouped by compatible Get a list of dict of WorklistVariableMatchDict grouped by compatible
conditions. conditions.
...@@ -1126,10 +1137,8 @@ def groupWorklistListByCondition(worklist_dict, sql_catalog, getSecurityUidDictA ...@@ -1126,10 +1137,8 @@ def groupWorklistListByCondition(worklist_dict, sql_catalog, getSecurityUidDictA
# One entry per worklist group, based on filter criterions. # One entry per worklist group, based on filter criterions.
worklist_set_dict = {} worklist_set_dict = {}
metadata_dict = {} metadata_dict = {}
for workflow_id, worklist in worklist_dict.iteritems(): for workflow_id, worklist in worklist_dict.iteritems():
for worklist_id, worklist_match_dict in worklist.iteritems(): for worklist_id, worklist_match_dict in worklist.iteritems():
# creates keys for new 'metadata' dict
workflow_worklist_key = '/'.join((workflow_id, worklist_id)) workflow_worklist_key = '/'.join((workflow_id, worklist_id))
if getSecurityUidDictAndRoleColumnDict is None: if getSecurityUidDictAndRoleColumnDict is None:
valid_criterion_dict, metadata = getValidCriterionDict( valid_criterion_dict, metadata = getValidCriterionDict(
...@@ -1184,10 +1193,12 @@ def groupWorklistListByCondition(worklist_dict, sql_catalog, getSecurityUidDictA ...@@ -1184,10 +1193,12 @@ def groupWorklistListByCondition(worklist_dict, sql_catalog, getSecurityUidDictA
worklist_set_dict=worklist_set_dict, worklist_set_dict=worklist_set_dict,
workflow_worklist_key=workflow_worklist_key, workflow_worklist_key=workflow_worklist_key,
valid_criterion_dict=valid_criterion_dict) valid_criterion_dict=valid_criterion_dict)
return worklist_set_dict.values(), metadata_dict return worklist_set_dict.values(), metadata_dict
def generateNestedQuery(getQuery, priority_list, criterion_dict, possible_worklist_id_dict=None): def generateNestedQuery(getQuery, priority_list, criterion_dict,
possible_worklist_id_dict=None):
"""
"""
assert possible_worklist_id_dict is None \ assert possible_worklist_id_dict is None \
or len(possible_worklist_id_dict) != 0 or len(possible_worklist_id_dict) != 0
my_priority_list = priority_list[:] my_priority_list = priority_list[:]
...@@ -1217,9 +1228,9 @@ def generateNestedQuery(getQuery, priority_list, criterion_dict, possible_workli ...@@ -1217,9 +1228,9 @@ def generateNestedQuery(getQuery, priority_list, criterion_dict, possible_workli
**{my_criterion_id: criterion_value}) **{my_criterion_id: criterion_value})
if isinstance(criterion_value, ExclusionTuple): if isinstance(criterion_value, ExclusionTuple):
query = NegatedQuery(query) query = NegatedQuery(query)
query = ComplexQuery(operator='OR', query = ComplexQuery(logical_operator='OR',
*(query, getQuery(**{my_criterion_id: None}))) *(query, getQuery(**{my_criterion_id: None})))
append(ComplexQuery(query, subcriterion_query, operator='AND')) append(ComplexQuery(query, subcriterion_query, logical_operator='AND'))
else: else:
possible_value_list = tuple() possible_value_list = tuple()
impossible_value_list = tuple() impossible_value_list = tuple()
...@@ -1250,21 +1261,18 @@ def generateNestedQuery(getQuery, priority_list, criterion_dict, possible_workli ...@@ -1250,21 +1261,18 @@ def generateNestedQuery(getQuery, priority_list, criterion_dict, possible_workli
**{my_criterion_id: impossible_value_list} **{my_criterion_id: impossible_value_list}
) )
query = NegatedQuery(query) query = NegatedQuery(query)
query = ComplexQuery(operator='OR', query = ComplexQuery(logical_operator='OR',
*(query, getQuery(**{my_criterion_id: None}))) *(query, getQuery(**{my_criterion_id: None})))
value_query_list.append(query) value_query_list.append(query)
append(ComplexQuery(operator='AND', *value_query_list)) append(ComplexQuery(logical_operator='AND', *value_query_list))
if len(query_list): if len(query_list):
return ComplexQuery(operator='OR', *query_list) return ComplexQuery(logical_operator='OR', *query_list)
return None return None
def getWorklistListQuery(getQuery, grouped_worklist_dict): def getWorklistListQuery(getQuery, grouped_worklist_dict):
""" """
Return a tuple of 3 value: Return a tuple of 2 values:
- a select_expression with a count(*) and all columns used in - a list of columns to select or to group by.
goup_by_expression
- a group_by_expression with all columns required for provided
grouped_worklist_dict
- a query applying all criterions contained in provided - a query applying all criterions contained in provided
grouped_worklist_dict grouped_worklist_dict
""" """
......
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