Commit c65c3901 authored by Sebastien Robin's avatar Sebastien Robin

added method countMessage

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11369 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fd7504f7
...@@ -158,6 +158,7 @@ class Queue: ...@@ -158,6 +158,7 @@ class Queue:
'Validation of Object %s raised exception' % '/'.join(message.object_path), 'Validation of Object %s raised exception' % '/'.join(message.object_path),
error=sys.exc_info()) error=sys.exc_info())
# Do not try to call methods on objects which cause errors # Do not try to call methods on objects which cause errors
import pdb;pdb.set_trace()
return EXCEPTION return EXCEPTION
return VALID return VALID
...@@ -189,6 +190,12 @@ class Queue: ...@@ -189,6 +190,12 @@ class Queue:
def getMessageList(self, activity_tool, processing_node=None,**kw): def getMessageList(self, activity_tool, processing_node=None,**kw):
return [] return []
def countMessage(self, activity_tool,**kw):
return 0
def countMessageWithTag(self, activity_tool,value):
return 0
# Transaction Management # Transaction Management
def prepareQueueMessage(self, activity_tool, m): def prepareQueueMessage(self, activity_tool, m):
# Called to prepare transaction commit for queued messages # Called to prepare transaction commit for queued messages
......
...@@ -564,14 +564,30 @@ class SQLDict(RAMDict): ...@@ -564,14 +564,30 @@ class SQLDict(RAMDict):
return INVALID_ORDER return INVALID_ORDER
return VALID return VALID
def countMessage(self, activity_tool, tag=None,path=None,
method_id=None,message_uid=None,**kw):
"""
Return the number of message which match the given parameter.
"""
if isinstance(tag, StringType):
tag = [tag]
if isinstance(path, StringType):
path = [path]
if isinstance(message_uid, (int,long)):
message_uid = [message_uid]
if isinstance(method_id, StringType):
method_id = [method_id]
result = activity_tool.SQLDict_validateMessageList(method_id=method_id,
path=path,
message_uid=message_uid,
tag=tag)
return result[0].uid_count
def countMessageWithTag(self, activity_tool, value): def countMessageWithTag(self, activity_tool, value):
""" """
Return the number of message which match the given tag. Return the number of message which match the given tag.
""" """
if isinstance(value, StringType): return self.countMessage(activity_tool,tag=value)
value = [value]
result = activity_tool.SQLDict_validateMessageList(method_id=None, message_uid=None, tag=value)
return result[0].uid_count
def _validate_after_tag_and_method_id(self, activity_tool, message, value): def _validate_after_tag_and_method_id(self, activity_tool, message, value):
# Count number of occurances of tag and method_id # Count number of occurances of tag and method_id
......
...@@ -33,6 +33,7 @@ from DateTime import DateTime ...@@ -33,6 +33,7 @@ from DateTime import DateTime
from Queue import VALID, INVALID_ORDER, INVALID_PATH, EXCEPTION, MAX_PROCESSING_TIME, VALIDATION_ERROR_DELAY from Queue import VALID, INVALID_ORDER, INVALID_PATH, EXCEPTION, MAX_PROCESSING_TIME, VALIDATION_ERROR_DELAY
from Products.CMFActivity.ActiveObject import DISTRIBUTABLE_STATE, INVOKE_ERROR_STATE, VALIDATE_ERROR_STATE from Products.CMFActivity.ActiveObject import DISTRIBUTABLE_STATE, INVOKE_ERROR_STATE, VALIDATE_ERROR_STATE
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from types import StringType
try: try:
from transaction import get as get_transaction from transaction import get as get_transaction
...@@ -237,6 +238,32 @@ class SQLQueue(RAMQueue): ...@@ -237,6 +238,32 @@ class SQLQueue(RAMQueue):
message_list.append(m) message_list.append(m)
return message_list return message_list
def countMessage(self, activity_tool, tag=None,path=None,
method_id=None,message_uid=None,**kw):
"""
Return the number of message which match the given parameter.
"""
if isinstance(tag, StringType):
tag = [tag]
if isinstance(path, StringType):
path = [path]
if isinstance(message_uid, (int,long)):
message_uid = [message_uid]
if isinstance(method_id, StringType):
method_id = [method_id]
result = activity_tool.SQLQueue_validateMessageList(method_id=method_id,
path=path,
message_uid=message_uid,
tag=tag)
return result[0].uid_count
def countMessageWithTag(self, activity_tool, value):
"""
Return the number of message which match the given tag.
"""
return self.countMessage(activity_tool,tag=value)
def dumpMessageList(self, activity_tool): def dumpMessageList(self, activity_tool):
# Dump all messages in the table. # Dump all messages in the table.
message_list = [] message_list = []
......
...@@ -883,10 +883,24 @@ class ActivityTool (Folder, UniqueObject): ...@@ -883,10 +883,24 @@ class ActivityTool (Folder, UniqueObject):
""" """
message_count = 0 message_count = 0
for activity in activity_list: for activity in activity_list:
try:
message_count += activity.countMessageWithTag(self, value) message_count += activity.countMessageWithTag(self, value)
except AttributeError: return message_count
LOG('getMessageList, could not get count message from Activity:', 0, activity)
security.declarePublic('countMessage')
def countMessage(self, **kw):
"""
Return the number of messages which match the given parameter.
Parameters allowed:
method_id : the id of the method
path : for activities on an particular object
tag : activities with a particular tag
message_uid : activities with a particular uid
"""
message_count = 0
for activity in activity_list:
message_count += activity.countMessage(self, **kw)
return message_count return message_count
security.declareProtected( CMFCorePermissions.ManagePortal , 'newActiveProcess' ) security.declareProtected( CMFCorePermissions.ManagePortal , 'newActiveProcess' )
......
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