Commit 1b905d2c authored by Julien Muchembled's avatar Julien Muchembled

Fix ActiveProcess.hasActivity. On active processes, hasActivity tests...

Fix ActiveProcess.hasActivity. On active processes, hasActivity tests active_process_uid instead of path:
* hasActivity must handle the case when no document is provided (bug #1142)
* Fix initialisation of active_process_uid property on Message objects.
Add unit test.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27329 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d65e6a5b
...@@ -128,8 +128,12 @@ class ActiveObject(ExtensionClass.Base): ...@@ -128,8 +128,12 @@ class ActiveObject(ExtensionClass.Base):
raise ValueError, "Cannot defined a group_id with value 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: 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" raise ValueError, "Cannot defined a group_id without group_method_id"
activity_tool = getToolByName(self, 'portal_activities', None) portal = self.getPortalObject()
if isinstance(active_process, basestring):
active_process = portal.unrestrictedTraverse(active_process)
activity_tool = getattr(portal, 'portal_activities', None)
if activity_tool is None: return self # Do nothing if no portal_activities if activity_tool is None: return self # Do nothing if no portal_activities
# activate returns an ActiveWrapper # activate returns an ActiveWrapper
# a queue can be provided as well as extra parameters # a queue can be provided as well as extra parameters
......
...@@ -514,7 +514,10 @@ class SQLDict(RAMDict, SQLBase): ...@@ -514,7 +514,10 @@ class SQLDict(RAMDict, SQLBase):
def hasActivity(self, activity_tool, object, method_id=None, only_valid=None, active_process_uid=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:
my_object_path = '/'.join(object.getPhysicalPath()) if object is None:
my_object_path = None
else:
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, active_process_uid=active_process_uid)
if len(result) > 0: if len(result) > 0:
return result[0].message_count > 0 return result[0].message_count > 0
......
...@@ -360,7 +360,10 @@ class SQLQueue(RAMQueue, SQLBase): ...@@ -360,7 +360,10 @@ class SQLQueue(RAMQueue, SQLBase):
def hasActivity(self, activity_tool, object, method_id=None, only_valid=None, active_process_uid=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:
my_object_path = '/'.join(object.getPhysicalPath()) if object is None:
my_object_path = None
else:
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, active_process_uid=active_process_uid)
if len(result) > 0: if len(result) > 0:
return result[0].message_count > 0 return result[0].message_count > 0
......
...@@ -159,6 +159,7 @@ class Message: ...@@ -159,6 +159,7 @@ 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 = None
active_process_uid = None 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):
...@@ -168,11 +169,7 @@ class Message: ...@@ -168,11 +169,7 @@ class Message:
else: else:
self.object_path = obj.getPhysicalPath() self.object_path = obj.getPhysicalPath()
activity_creation_trace = obj.getPortalObject().portal_activities.activity_creation_trace activity_creation_trace = obj.getPortalObject().portal_activities.activity_creation_trace
if type(active_process) is StringType: if active_process is not None:
self.active_process = active_process.split('/')
elif active_process is None:
self.active_process = None
else:
self.active_process = active_process.getPhysicalPath() self.active_process = active_process.getPhysicalPath()
self.active_process_uid = active_process.getUid() self.active_process_uid = active_process.getUid()
if activity_kw.get('serialization_tag', False) is None: if activity_kw.get('serialization_tag', False) is None:
......
...@@ -13,8 +13,8 @@ active_process_uid ...@@ -13,8 +13,8 @@ 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
WHERE WHERE 1 = 1
path = <dtml-sqlvar path type="string"> <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>
<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> <dtml-if expr="active_process_uid is not None"> AND active_process_uid = <dtml-sqlvar active_process_uid type="int"> </dtml-if>
...@@ -13,8 +13,8 @@ active_process_uid ...@@ -13,8 +13,8 @@ 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 1 = 1
path = <dtml-sqlvar path type="string"> <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>
<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> <dtml-if expr="active_process_uid is not None"> AND active_process_uid = <dtml-sqlvar active_process_uid type="int"> </dtml-if>
...@@ -3251,19 +3251,28 @@ class TestCMFActivity(ERP5TypeTestCase): ...@@ -3251,19 +3251,28 @@ class TestCMFActivity(ERP5TypeTestCase):
finally: finally:
delattr(Organisation, 'waitingActivity') delattr(Organisation, 'waitingActivity')
Queue.tic = original_queue_tic Queue.tic = original_queue_tic
def test_active_object_hasActivity(self): def test_hasActivity(self):
active_object = self.portal.organisation_module.newContent( active_object = self.portal.organisation_module.newContent(
portal_type='Organisation') portal_type='Organisation')
active_process = self.portal.portal_activities.newActiveProcess()
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
self.assertFalse(active_object.hasActivity()) self.assertFalse(active_object.hasActivity())
for activity in ('SQLDict', 'SQLQueue'): self.assertFalse(active_process.hasActivity())
active_object.activate(activity=activity).getTitle()
get_transaction().commit() def test(obj, **kw):
self.assertTrue(active_object.hasActivity(), activity) for activity in ('SQLDict', 'SQLQueue'):
self.tic() active_object.activate(activity=activity, **kw).getTitle()
self.assertFalse(active_object.hasActivity(), activity) get_transaction().commit()
self.assertTrue(obj.hasActivity(), activity)
self.tic()
self.assertFalse(obj.hasActivity(), activity)
test(active_object)
test(active_process, active_process=active_process)
test(active_process, active_process=active_process.getPath())
def test_active_object_hasActivity_does_not_catch_exceptions(self): def test_active_object_hasActivity_does_not_catch_exceptions(self):
""" """
......
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