Commit 772e6aae authored by Jérome Perrin's avatar Jérome Perrin

CMFActivity: ActivityRuntimeEnvironment for grouped messages WIP

parent 7d7a5f6c
...@@ -20,6 +20,7 @@ for document in getPath: ...@@ -20,6 +20,7 @@ for document in getPath:
document, document,
activity='SQLDict', activity='SQLDict',
priority=priority, priority=priority,
tag=context.getActivityRuntimeEnvironment().getTagForPath(document),
node='same', node='same',
group_method_id=GROUP_METHOD_ID, group_method_id=GROUP_METHOD_ID,
group_method_cost=group_method_cost, group_method_cost=group_method_cost,
......
...@@ -834,14 +834,17 @@ CREATE TABLE %s ( ...@@ -834,14 +834,17 @@ CREATE TABLE %s (
args = (group_method_id, message_list, self.__class__.__name__, args = (group_method_id, message_list, self.__class__.__name__,
hasattr(self, 'generateMessageUID')) hasattr(self, 'generateMessageUID'))
activity_runtime_environment = ActivityRuntimeEnvironment( activity_runtime_environment = ActivityRuntimeEnvironment(
None, message_list,
priority=min(x.line.priority for x in message_list), is_grouped_activity=True,
) )
else: else:
method = activity_tool.invoke method = activity_tool.invoke
message, = message_list message, = message_list
args = message_list args = message_list
activity_runtime_environment = ActivityRuntimeEnvironment(message) activity_runtime_environment = ActivityRuntimeEnvironment(
message_list,
is_grouped_activity=False,
)
# Commit right before executing messages. # Commit right before executing messages.
# As MySQL transaction does not start exactly at the same time as ZODB # As MySQL transaction does not start exactly at the same time as ZODB
# transactions but a bit later, messages available might be called # transactions but a bit later, messages available might be called
......
...@@ -41,9 +41,10 @@ class BaseMessage: ...@@ -41,9 +41,10 @@ class BaseMessage:
class ActivityRuntimeEnvironment(object): class ActivityRuntimeEnvironment(object):
security = ClassSecurityInfo() security = ClassSecurityInfo()
def __init__(self, message, priority=None): def __init__(self, message_list, is_grouped_activity):
self._message = message self._message_list = message_list
self._priority = priority self._priority = priority
self._is_grouped_activity = is_grouped_activity
def __enter__(self): def __enter__(self):
assert not hasattr(_activity_runtime_environment, 'value') assert not hasattr(_activity_runtime_environment, 'value')
...@@ -55,17 +56,24 @@ class ActivityRuntimeEnvironment(object): ...@@ -55,17 +56,24 @@ class ActivityRuntimeEnvironment(object):
security.declarePublic('getTag') security.declarePublic('getTag')
def getTag(self, default=None): def getTag(self, default=None):
return self._message.activity_kw.get('tag', default) if self._is_grouped_activity:
raise ValueError("Operation not supported on grouped activities")
return self._message_list[0].activity_kw.get('tag', default)
security.declarePublic('getTagForPath')
def getTagForPath(self, path, default=None):
for message in self._message_list:
if message.path == path:
return message.activity_kw.get('tag', default)
return default
security.declarePublic('getPriority') security.declarePublic('getPriority')
def getPriority(self): def getPriority(self):
result = self._priority return min(message.priority for message in self._message_list)
if result is None:
return self._message.line.priority
return result
security.declarePublic('edit') security.declarePublic('edit')
def edit(self, **kw): def edit(self, **kw):
# TODO: supported grouped activities
# There is no point allowing to modify other attributes from a message # There is no point allowing to modify other attributes from a message
for k in kw: for k in kw:
getattr(BaseMessage, k) getattr(BaseMessage, k)
......
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