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