Commit 3b17be37 authored by Julien Muchembled's avatar Julien Muchembled

CMFActivity: implement dummy group method

parent 1521a035
...@@ -98,11 +98,6 @@ class ActiveObject(ExtensionClass.Base): ...@@ -98,11 +98,6 @@ class ActiveObject(ExtensionClass.Base):
new_kw.update(activate_kw) new_kw.update(activate_kw)
new_kw.update(kw) new_kw.update(kw)
if kw.get('group_id', '') is None:
raise ValueError, "Cannot defined a group_id with value None"
elif kw.get('group_method_id') is None and kw.get('group_id') is not None:
raise ValueError, "Cannot defined a group_id without group_method_id"
try: try:
activity_tool = self.getPortalObject().portal_activities activity_tool = self.getPortalObject().portal_activities
except AttributeError: except AttributeError:
......
...@@ -222,7 +222,7 @@ class SQLBase: ...@@ -222,7 +222,7 @@ class SQLBase:
activity_tool.SQLBase_processMessage(table=self.sql_table, uid=[uid]) activity_tool.SQLBase_processMessage(table=self.sql_table, uid=[uid])
uid_to_duplicate_uid_list_dict.setdefault(uid, []) \ uid_to_duplicate_uid_list_dict.setdefault(uid, []) \
.extend(getDuplicateMessageUidList(line)) .extend(getDuplicateMessageUidList(line))
if group_method_id not in (None, '', '\0'): if group_method_id != '\0':
# Count the number of objects to prevent too many objects. # Count the number of objects to prevent too many objects.
cost = m.activity_kw.get('group_method_cost', .01) cost = m.activity_kw.get('group_method_cost', .01)
assert 0 < cost <= 1, (self.sql_table, uid) assert 0 < cost <= 1, (self.sql_table, uid)
......
...@@ -66,8 +66,13 @@ class SQLDict(RAMDict, SQLBase): ...@@ -66,8 +66,13 @@ class SQLDict(RAMDict, SQLBase):
priority_list = [message.activity_kw.get('priority', 1) for message in registered_message_list] priority_list = [message.activity_kw.get('priority', 1) for message in registered_message_list]
dumped_message_list = [self.dumpMessage(message) for message in registered_message_list] dumped_message_list = [self.dumpMessage(message) for message in registered_message_list]
date_list = [message.activity_kw.get('at_date', None) for message in registered_message_list] date_list = [message.activity_kw.get('at_date', None) for message in registered_message_list]
group_method_id_list = ['\0'.join([message.activity_kw.get('group_method_id', ''), message.activity_kw.get('group_id', '')]) group_method_id_list = []
for message in registered_message_list] for m in registered_message_list:
group_method_id = m.activity_kw.get('group_method_id', '')
if group_method_id is None:
group_method_id = 'portal_activities/dummyGroupMethod/' + m.method_id
group_method_id_list.append(group_method_id + '\0' +
m.activity_kw.get('group_id', ''))
tag_list = [message.activity_kw.get('tag', '') for message in registered_message_list] tag_list = [message.activity_kw.get('tag', '') for message in registered_message_list]
serialization_tag_list = [message.activity_kw.get('serialization_tag', '') for message in registered_message_list] serialization_tag_list = [message.activity_kw.get('serialization_tag', '') for message in registered_message_list]
order_validation_text_list = [self.getOrderValidationText(message) for message in registered_message_list] order_validation_text_list = [self.getOrderValidationText(message) for message in registered_message_list]
...@@ -316,11 +321,11 @@ class SQLDict(RAMDict, SQLBase): ...@@ -316,11 +321,11 @@ class SQLDict(RAMDict, SQLBase):
# Sort list of messages to validate the message with highest score # Sort list of messages to validate the message with highest score
message_list.sort(key=sort_message_key) message_list.sort(key=sort_message_key)
distributable_uid_set.add(message_list[0].uid) distributable_uid_set.add(message_list[0].uid)
group_method_id = message_list[0].activity_kw.get('group_method_id') group_method_id = message_list[0].line.group_method_id
if group_method_id is None: if group_method_id == '\0':
continue continue
for message in message_list[1:]: for message in message_list[1:]:
if group_method_id == message.activity_kw.get('group_method_id'): if group_method_id == message.line.group_method_id:
distributable_uid_set.add(message.uid) distributable_uid_set.add(message.uid)
if deletable_uid_list: if deletable_uid_list:
activity_tool.SQLBase_delMessage(table=self.sql_table, activity_tool.SQLBase_delMessage(table=self.sql_table,
......
...@@ -67,8 +67,13 @@ class SQLQueue(RAMQueue, SQLBase): ...@@ -67,8 +67,13 @@ class SQLQueue(RAMQueue, SQLBase):
method_id_list = [m.method_id for m in registered_message_list] method_id_list = [m.method_id for m in registered_message_list]
priority_list = [m.activity_kw.get('priority', 1) for m in registered_message_list] priority_list = [m.activity_kw.get('priority', 1) for m in registered_message_list]
date_list = [m.activity_kw.get('at_date', None) for m in registered_message_list] date_list = [m.activity_kw.get('at_date', None) for m in registered_message_list]
group_method_id_list = ['\0'.join([message.activity_kw.get('group_method_id', ''), message.activity_kw.get('group_id', '')]) group_method_id_list = []
for message in registered_message_list] for m in registered_message_list:
group_method_id = m.activity_kw.get('group_method_id', '')
if group_method_id is None:
group_method_id = 'portal_activities/dummyGroupMethod/' + m.method_id
group_method_id_list.append(group_method_id + '\0' +
m.activity_kw.get('group_id', ''))
tag_list = [m.activity_kw.get('tag', '') for m in registered_message_list] tag_list = [m.activity_kw.get('tag', '') for m in registered_message_list]
serialization_tag_list = [m.activity_kw.get('serialization_tag', '') for m in registered_message_list] serialization_tag_list = [m.activity_kw.get('serialization_tag', '') for m in registered_message_list]
dumped_message_list = [self.dumpMessage(m) for m in registered_message_list] dumped_message_list = [self.dumpMessage(m) for m in registered_message_list]
...@@ -255,11 +260,11 @@ class SQLQueue(RAMQueue, SQLBase): ...@@ -255,11 +260,11 @@ class SQLQueue(RAMQueue, SQLBase):
# Sort list of messages to validate the message with highest score # Sort list of messages to validate the message with highest score
message_list.sort(key=sort_message_key) message_list.sort(key=sort_message_key)
distributable_uid_set.add(message_list[0].uid) distributable_uid_set.add(message_list[0].uid)
group_method_id = message_list[0].activity_kw.get('group_method_id') group_method_id = message_list[0].line.group_method_id
if group_method_id is None: if group_method_id == '\0':
continue continue
for message in message_list[1:]: for message in message_list[1:]:
if group_method_id == message.activity_kw.get('group_method_id'): if group_method_id == message.line.group_method_id:
distributable_uid_set.add(message.uid) distributable_uid_set.add(message.uid)
distributable_count = len(distributable_uid_set) distributable_count = len(distributable_uid_set)
if distributable_count: if distributable_count:
......
...@@ -1289,6 +1289,16 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1289,6 +1289,16 @@ class ActivityTool (Folder, UniqueObject):
if self.activity_tracking: if self.activity_tracking:
activity_tracking_logger.info('invoked group messages') activity_tracking_logger.info('invoked group messages')
security.declarePrivate('dummyGroupMethod')
class dummyGroupMethod(object):
def __bobo_traverse__(self, REQUEST, method_id):
def group_method(message_list):
for m in message_list:
getattr(m[0], method_id)(*m[1], **m[2])
del message_list[:]
return group_method
dummyGroupMethod = dummyGroupMethod()
def newMessage(self, activity, path, active_process, def newMessage(self, activity, path, active_process,
activity_kw, method_id, *args, **kw): activity_kw, method_id, *args, **kw):
# Some Security Cheking should be made here XXX # Some Security Cheking should be made here XXX
......
...@@ -2038,7 +2038,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2038,7 +2038,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message_list=[pickled_message], message_list=[pickled_message],
priority_list=[1], priority_list=[1],
processing_node_list=[-2], processing_node_list=[-2],
group_method_id_list=[''], group_method_id_list=['\0'],
tag_list=[''], tag_list=[''],
order_validation_text_list=[''], order_validation_text_list=[''],
serialization_tag_list=[''], serialization_tag_list=[''],
...@@ -2095,7 +2095,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2095,7 +2095,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message_list=[pickled_message], message_list=[pickled_message],
priority_list=[1], priority_list=[1],
processing_node_list=[-2], processing_node_list=[-2],
group_method_id_list=[''], group_method_id_list=['\0'],
tag_list=[''], tag_list=[''],
order_validation_text_list=[''], order_validation_text_list=[''],
serialization_tag_list=[''] serialization_tag_list=['']
...@@ -2162,7 +2162,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2162,7 +2162,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message_list=[pickled_message], message_list=[pickled_message],
priority_list=[1], priority_list=[1],
processing_node_list=[-2], processing_node_list=[-2],
group_method_id_list=[''], group_method_id_list=['\0'],
tag_list=[''], tag_list=[''],
order_validation_text_list=[''], order_validation_text_list=[''],
serialization_tag_list=[''], serialization_tag_list=[''],
...@@ -2220,7 +2220,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2220,7 +2220,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message_list=[pickled_message], message_list=[pickled_message],
priority_list=[1], priority_list=[1],
processing_node_list=[-2], processing_node_list=[-2],
group_method_id_list=[''], group_method_id_list=['\0'],
tag_list=[''], tag_list=[''],
order_validation_text_list=[''], order_validation_text_list=[''],
serialization_tag_list=[''], serialization_tag_list=[''],
...@@ -2465,7 +2465,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2465,7 +2465,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
message_list=[pickled_message], message_list=[pickled_message],
priority_list=[1], priority_list=[1],
processing_node_list=[-2], processing_node_list=[-2],
group_method_id_list=[''], group_method_id_list=['\0'],
tag_list=[''], tag_list=[''],
order_validation_text_list=[''], order_validation_text_list=[''],
) )
......
...@@ -810,6 +810,8 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -810,6 +810,8 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
security.declarePrivate('uncatalogObjectList') security.declarePrivate('uncatalogObjectList')
def uncatalogObjectList(self, message_list): def uncatalogObjectList(self, message_list):
"""Uncatalog a list of objects""" """Uncatalog a list of objects"""
# XXX: this is currently only a placeholder for further optimization
# (for the moment, it's not faster than the dummy group method)
for obj, args, kw in message_list: for obj, args, kw in message_list:
self.unindexObject(*args, **kw) self.unindexObject(*args, **kw)
del message_list[:] del message_list[:]
......
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