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