Commit 738c0a08 authored by Vincent Pelletier's avatar Vincent Pelletier

Implement ActiveProcess.hasActivity . It was present, but required data was...

Implement ActiveProcess.hasActivity . It was present, but required data was never present in the table. Now that SQL{Dict|Queue}.hasActivity don't use "**kw" any more, it causes errors.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25274 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent fb15aaa0
...@@ -138,7 +138,7 @@ class ActiveProcess(Base): ...@@ -138,7 +138,7 @@ class ActiveProcess(Base):
""" """
activity_tool = getattr(self, 'portal_activities', None) activity_tool = getattr(self, 'portal_activities', None)
if activity_tool is None: return 0 # Do nothing if no portal_activities if activity_tool is None: return 0 # Do nothing if no portal_activities
return activity_tool.hasActivity(None, active_process = self, **kw) return activity_tool.hasActivity(None, active_process_uid = self.getUid(), **kw)
security.declareProtected( CMFCorePermissions.View, 'hasErrorActivity' ) security.declareProtected( CMFCorePermissions.View, 'hasErrorActivity' )
def hasErrorActivity(self, **kw): def hasErrorActivity(self, **kw):
......
...@@ -71,6 +71,7 @@ class SQLDict(RAMDict, SQLBase): ...@@ -71,6 +71,7 @@ class SQLDict(RAMDict, SQLBase):
if len(registered_message_list) > 0: if len(registered_message_list) > 0:
#LOG('SQLDict prepareQueueMessageList', 0, 'registered_message_list = %r' % (registered_message_list,)) #LOG('SQLDict prepareQueueMessageList', 0, 'registered_message_list = %r' % (registered_message_list,))
path_list = ['/'.join(message.object_path) for message in registered_message_list] path_list = ['/'.join(message.object_path) for message in registered_message_list]
active_process_uid_list = [message.active_process_uid for message in registered_message_list]
method_id_list = [message.method_id for message in registered_message_list] method_id_list = [message.method_id for message in registered_message_list]
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]
...@@ -84,6 +85,7 @@ class SQLDict(RAMDict, SQLBase): ...@@ -84,6 +85,7 @@ class SQLDict(RAMDict, SQLBase):
id_count=len(registered_message_list), store=0) id_count=len(registered_message_list), store=0)
activity_tool.SQLDict_writeMessageList( uid_list = uid_list, activity_tool.SQLDict_writeMessageList( uid_list = uid_list,
path_list = path_list, path_list = path_list,
active_process_uid_list=active_process_uid_list,
method_id_list = method_id_list, method_id_list = method_id_list,
priority_list = priority_list, priority_list = priority_list,
message_list = dumped_message_list, message_list = dumped_message_list,
...@@ -509,16 +511,13 @@ class SQLDict(RAMDict, SQLBase): ...@@ -509,16 +511,13 @@ class SQLDict(RAMDict, SQLBase):
get_transaction().commit() get_transaction().commit()
return not len(message_uid_priority_list) return not len(message_uid_priority_list)
def hasActivity(self, activity_tool, object, method_id=None, only_valid=None): def hasActivity(self, activity_tool, object, method_id=None, only_valid=None, active_process_uid=None):
hasMessage = getattr(activity_tool, 'SQLDict_hasMessage', None) hasMessage = getattr(activity_tool, 'SQLDict_hasMessage', None)
if hasMessage is not None: if hasMessage is not None:
if object is not None: my_object_path = '/'.join(object.getPhysicalPath())
my_object_path = '/'.join(object.getPhysicalPath()) result = hasMessage(path=my_object_path, method_id=method_id, only_valid=only_valid, active_process_uid=active_process_uid)
result = hasMessage(path=my_object_path, method_id=method_id, only_valid=only_valid) if len(result) > 0:
if len(result) > 0: return result[0].message_count > 0
return result[0].message_count > 0
else:
return 1 # Default behaviour if no object specified is to return 1 until active_process implemented
return 0 return 0
def flush(self, activity_tool, object_path, invoke=0, method_id=None, commit=0, **kw): def flush(self, activity_tool, object_path, invoke=0, method_id=None, commit=0, **kw):
......
...@@ -70,6 +70,7 @@ class SQLQueue(RAMQueue, SQLBase): ...@@ -70,6 +70,7 @@ class SQLQueue(RAMQueue, SQLBase):
id_group='portal_activity_queue', id_count=len(registered_message_list), id_group='portal_activity_queue', id_count=len(registered_message_list),
store=0) store=0)
path_list = ['/'.join(m.object_path) for m in registered_message_list] path_list = ['/'.join(m.object_path) for m in registered_message_list]
active_process_uid_list = [m.active_process_uid for m in registered_message_list]
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]
...@@ -78,6 +79,7 @@ class SQLQueue(RAMQueue, SQLBase): ...@@ -78,6 +79,7 @@ class SQLQueue(RAMQueue, SQLBase):
message_list = [self.dumpMessage(m) for m in registered_message_list] message_list = [self.dumpMessage(m) for m in registered_message_list]
activity_tool.SQLQueue_writeMessageList(uid_list=uid_list, activity_tool.SQLQueue_writeMessageList(uid_list=uid_list,
path_list=path_list, path_list=path_list,
active_process_uid_list=active_process_uid_list,
method_id_list=method_id_list, method_id_list=method_id_list,
priority_list=priority_list, priority_list=priority_list,
message_list=message_list, message_list=message_list,
...@@ -346,16 +348,13 @@ class SQLQueue(RAMQueue, SQLBase): ...@@ -346,16 +348,13 @@ class SQLQueue(RAMQueue, SQLBase):
return not len(message_uid_priority_list) return not len(message_uid_priority_list)
def hasActivity(self, activity_tool, object, method_id=None, only_valid=None): def hasActivity(self, activity_tool, object, method_id=None, only_valid=None, active_process_uid=None):
hasMessage = getattr(activity_tool, 'SQLQueue_hasMessage', None) hasMessage = getattr(activity_tool, 'SQLQueue_hasMessage', None)
if hasMessage is not None: if hasMessage is not None:
if object is not None: my_object_path = '/'.join(object.getPhysicalPath())
my_object_path = '/'.join(object.getPhysicalPath()) result = hasMessage(path=my_object_path, method_id=method_id, only_valid=only_valid, active_process_uid=active_process_uid)
result = hasMessage(path=my_object_path, method_id=method_id, only_valid=only_valid) if len(result) > 0:
if len(result) > 0: return result[0].message_count > 0
return result[0].message_count > 0
else:
return 1 # Default behaviour if no object specified is to return 1 until active_process implemented
return 0 return 0
def flush(self, activity_tool, object_path, invoke=0, method_id=None, commit=0, **kw): def flush(self, activity_tool, object_path, invoke=0, method_id=None, commit=0, **kw):
......
...@@ -146,6 +146,9 @@ class Message: ...@@ -146,6 +146,9 @@ class Message:
Message instances are stored in an activity queue, inside the Activity Tool. Message instances are stored in an activity queue, inside the Activity Tool.
""" """
active_process_uid = None
def __init__(self, obj, active_process, activity_kw, method_id, args, kw): def __init__(self, obj, active_process, activity_kw, method_id, args, kw):
if isinstance(obj, str): if isinstance(obj, str):
self.object_path = tuple(obj.split('/')) self.object_path = tuple(obj.split('/'))
...@@ -491,6 +494,11 @@ class ActivityTool (Folder, UniqueObject): ...@@ -491,6 +494,11 @@ class ActivityTool (Folder, UniqueObject):
activity_tracking = False activity_tracking = False
activity_timing_log = False activity_timing_log = False
def SQLDict_setPriority(self, **kw):
real_SQLDict_setPriority = getattr(self.aq_parent, 'SQLDict_setPriority')
LOG('ActivityTool', 0, real_SQLDict_setPriority(src__=1, **kw))
return real_SQLDict_setPriority(**kw)
def __init__(self): def __init__(self):
return Folder.__init__(self, ActivityTool.id) return Folder.__init__(self, ActivityTool.id)
......
...@@ -12,6 +12,7 @@ CREATE TABLE `message` ( ...@@ -12,6 +12,7 @@ CREATE TABLE `message` (
`uid` INT UNSIGNED NOT NULL, `uid` INT UNSIGNED NOT NULL,
`date` DATETIME NOT NULL, `date` DATETIME NOT NULL,
`path` VARCHAR(255) NOT NULL, `path` VARCHAR(255) NOT NULL,
`active_process_uid` INT UNSIGNED NULL,
`method_id` VARCHAR(255) NOT NULL, `method_id` VARCHAR(255) NOT NULL,
`processing_node` SMALLINT NOT NULL DEFAULT -1, `processing_node` SMALLINT NOT NULL DEFAULT -1,
`processing` TINYINT NOT NULL DEFAULT 0, `processing` TINYINT NOT NULL DEFAULT 0,
...@@ -25,6 +26,7 @@ CREATE TABLE `message` ( ...@@ -25,6 +26,7 @@ CREATE TABLE `message` (
`message` LONGBLOB NOT NULL, `message` LONGBLOB NOT NULL,
PRIMARY KEY (`uid`), PRIMARY KEY (`uid`),
KEY (`path`), KEY (`path`),
KEY (`active_process_uid`),
KEY (`method_id`), KEY (`method_id`),
KEY `processing_node_processing` (`processing_node`, `processing`), KEY `processing_node_processing` (`processing_node`, `processing`),
KEY `processing_node_date` (`processing_node`, `date`), KEY `processing_node_date` (`processing_node`, `date`),
......
...@@ -9,6 +9,7 @@ class_file: ...@@ -9,6 +9,7 @@ class_file:
</dtml-comment> </dtml-comment>
<params>path <params>path
method_id method_id
active_process_uid
only_valid</params> only_valid</params>
SELECT count(path) as message_count FROM SELECT count(path) as message_count FROM
message message
...@@ -16,4 +17,4 @@ WHERE ...@@ -16,4 +17,4 @@ WHERE
path = <dtml-sqlvar path type="string"> path = <dtml-sqlvar path type="string">
<dtml-if expr="method_id is not None">AND method_id = <dtml-sqlvar method_id type="string"></dtml-if> <dtml-if expr="method_id is not None">AND method_id = <dtml-sqlvar method_id type="string"></dtml-if>
<dtml-if expr="only_valid">AND processing_node > -2</dtml-if> <dtml-if expr="only_valid">AND processing_node > -2</dtml-if>
<dtml-if expr="active_process_uid is not None"> AND active_process_uid = <dtml-sqlvar active_process_uid type="int"> </dtml-if>
...@@ -9,6 +9,7 @@ class_file: ...@@ -9,6 +9,7 @@ class_file:
</dtml-comment> </dtml-comment>
<params>uid_list <params>uid_list
path_list path_list
active_process_uid_list
method_id_list method_id_list
message_list message_list
priority_list priority_list
...@@ -19,13 +20,14 @@ tag_list ...@@ -19,13 +20,14 @@ tag_list
serialization_tag_list serialization_tag_list
order_validation_text_list</params> order_validation_text_list</params>
INSERT INTO message INSERT INTO message
(uid, path, date, method_id, processing_node, processing, priority, group_method_id, tag, serialization_tag, order_validation_text, message) (uid, path, active_process_uid, date, method_id, processing_node, processing, priority, group_method_id, tag, serialization_tag, order_validation_text, message)
VALUES VALUES
<dtml-in prefix="loop" expr="_.range(_.len(path_list))"> <dtml-in prefix="loop" expr="_.range(_.len(path_list))">
<dtml-if sequence-start><dtml-else>,</dtml-if> <dtml-if sequence-start><dtml-else>,</dtml-if>
( (
<dtml-sqlvar expr="uid_list[loop_item]" type="int">, <dtml-sqlvar expr="uid_list[loop_item]" type="int">,
<dtml-sqlvar expr="path_list[loop_item]" type="string">, <dtml-sqlvar expr="path_list[loop_item]" type="string">,
<dtml-sqlvar expr="active_process_uid_list[loop_item]" type="int" optional>,
<dtml-if expr="date_list is not None"><dtml-if expr="date_list[loop_item] is not None"><dtml-sqlvar expr="date_list[loop_item]" type="datetime"><dtml-else>UTC_TIMESTAMP()</dtml-if><dtml-else>UTC_TIMESTAMP()</dtml-if>, <dtml-if expr="date_list is not None"><dtml-if expr="date_list[loop_item] is not None"><dtml-sqlvar expr="date_list[loop_item]" type="datetime"><dtml-else>UTC_TIMESTAMP()</dtml-if><dtml-else>UTC_TIMESTAMP()</dtml-if>,
<dtml-sqlvar expr="method_id_list[loop_item]" type="string">, <dtml-sqlvar expr="method_id_list[loop_item]" type="string">,
<dtml-if expr="processing_node_list is not None"><dtml-sqlvar expr="processing_node_list[loop_item]" type="int"><dtml-else>-1</dtml-if>, <dtml-if expr="processing_node_list is not None"><dtml-sqlvar expr="processing_node_list[loop_item]" type="int"><dtml-else>-1</dtml-if>,
......
...@@ -12,6 +12,7 @@ CREATE TABLE `message_queue` ( ...@@ -12,6 +12,7 @@ CREATE TABLE `message_queue` (
`uid` INT UNSIGNED NOT NULL, `uid` INT UNSIGNED NOT NULL,
`date` DATETIME NOT NULL, `date` DATETIME NOT NULL,
`path` VARCHAR(255) NOT NULL, `path` VARCHAR(255) NOT NULL,
`active_process_uid` INT UNSIGNED NULL,
`method_id` VARCHAR(255) NOT NULL, `method_id` VARCHAR(255) NOT NULL,
`processing_node` SMALLINT NOT NULL DEFAULT -1, `processing_node` SMALLINT NOT NULL DEFAULT -1,
`processing` TINYINT NOT NULL DEFAULT 0, `processing` TINYINT NOT NULL DEFAULT 0,
...@@ -22,6 +23,7 @@ CREATE TABLE `message_queue` ( ...@@ -22,6 +23,7 @@ CREATE TABLE `message_queue` (
`message` LONGBLOB NOT NULL, `message` LONGBLOB NOT NULL,
PRIMARY KEY (`uid`), PRIMARY KEY (`uid`),
KEY (`path`), KEY (`path`),
KEY (`active_process_uid`),
KEY (`method_id`), KEY (`method_id`),
KEY `processing_node_processing` (`processing_node`, `processing`), KEY `processing_node_processing` (`processing_node`, `processing`),
KEY `processing_node_date` (`processing_node`, `date`), KEY `processing_node_date` (`processing_node`, `date`),
......
...@@ -9,11 +9,12 @@ class_file: ...@@ -9,11 +9,12 @@ class_file:
</dtml-comment> </dtml-comment>
<params>path <params>path
method_id method_id
active_process_uid
only_valid</params> only_valid</params>
SELECT count(path) as message_count FROM SELECT count(path) as message_count FROM
message_queue message_queue
WHERE WHERE
path = <dtml-sqlvar path type="string"> path = <dtml-sqlvar path type="string">
<dtml-if expr="method_id is not None">AND method_id = <dtml-sqlvar method_id type="string"></dtml-if> <dtml-if expr="method_id is not None"> AND method_id = <dtml-sqlvar method_id type="string"> </dtml-if>
<dtml-if expr="only_valid">AND processing_node > -2</dtml-if> <dtml-if expr="only_valid"> AND processing_node > -2 </dtml-if>
<dtml-if expr="active_process_uid is not None"> AND active_process_uid = <dtml-sqlvar active_process_uid type="int"> </dtml-if>
...@@ -19,7 +19,7 @@ SELECT * FROM ...@@ -19,7 +19,7 @@ SELECT * FROM
message_queue message_queue
WHERE WHERE
1 = 1 1 = 1
<dtml-if expr="not(include_processing)"> AND processing = 0 </dtml-if> AND processing = 0
<dtml-if expr="processing_node is not None"> AND processing_node = <dtml-sqlvar processing_node type="int"> </dtml-if> <dtml-if expr="processing_node is not None"> AND processing_node = <dtml-sqlvar processing_node type="int"> </dtml-if>
<dtml-if expr="path is not None">AND path = <dtml-sqlvar path type="string"></dtml-if> <dtml-if expr="path is not None">AND path = <dtml-sqlvar path type="string"></dtml-if>
<dtml-if expr="method_id is not None">AND method_id = <dtml-sqlvar method_id type="string"></dtml-if> <dtml-if expr="method_id is not None">AND method_id = <dtml-sqlvar method_id type="string"></dtml-if>
......
...@@ -9,6 +9,7 @@ class_file: ...@@ -9,6 +9,7 @@ class_file:
</dtml-comment> </dtml-comment>
<params>uid_list <params>uid_list
path_list path_list
active_process_uid_list
method_id_list method_id_list
message_list message_list
priority_list priority_list
...@@ -18,13 +19,14 @@ tag_list ...@@ -18,13 +19,14 @@ tag_list
serialization_tag_list serialization_tag_list
</params> </params>
INSERT INTO message_queue INSERT INTO message_queue
(uid, path, date, method_id, processing_node, processing, priority, tag, serialization_tag, message) (uid, path, active_process_uid, date, method_id, processing_node, processing, priority, tag, serialization_tag, message)
VALUES VALUES
<dtml-in prefix="loop" expr="_.range(_.len(path_list))"> <dtml-in prefix="loop" expr="_.range(_.len(path_list))">
<dtml-if sequence-start><dtml-else>,</dtml-if> <dtml-if sequence-start><dtml-else>,</dtml-if>
( (
<dtml-sqlvar expr="uid_list[loop_item]" type="int">, <dtml-sqlvar expr="uid_list[loop_item]" type="int">,
<dtml-sqlvar expr="path_list[loop_item]" type="string">, <dtml-sqlvar expr="path_list[loop_item]" type="string">,
<dtml-sqlvar expr="active_process_uid_list[loop_item]" type="int" optional>,
<dtml-if expr="date_list is not None"><dtml-if expr="date_list[loop_item] is not None"><dtml-sqlvar expr="date_list[loop_item]" type="datetime"><dtml-else>UTC_TIMESTAMP()</dtml-if><dtml-else>UTC_TIMESTAMP()</dtml-if>, <dtml-if expr="date_list is not None"><dtml-if expr="date_list[loop_item] is not None"><dtml-sqlvar expr="date_list[loop_item]" type="datetime"><dtml-else>UTC_TIMESTAMP()</dtml-if><dtml-else>UTC_TIMESTAMP()</dtml-if>,
<dtml-sqlvar expr="method_id_list[loop_item]" type="string">, <dtml-sqlvar expr="method_id_list[loop_item]" type="string">,
<dtml-if expr="processing_node_list is not None"><dtml-sqlvar expr="processing_node_list[loop_item]" type="int"><dtml-else>-1</dtml-if>, <dtml-if expr="processing_node_list is not None"><dtml-sqlvar expr="processing_node_list[loop_item]" type="int"><dtml-else>-1</dtml-if>,
......
...@@ -1949,6 +1949,7 @@ class TestCMFActivity(ERP5TypeTestCase): ...@@ -1949,6 +1949,7 @@ class TestCMFActivity(ERP5TypeTestCase):
uid_list=[0], # This uid is never automaticaly assigned (starts at 1) uid_list=[0], # This uid is never automaticaly assigned (starts at 1)
date_list=[DateTime().Date()], date_list=[DateTime().Date()],
path_list=[path], path_list=[path],
active_process_uid=[None],
method_id_list=[method_id], method_id_list=[method_id],
message_list=[pickled_message], message_list=[pickled_message],
priority_list=[1], priority_list=[1],
......
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