Commit 264111e7 authored by Aurel's avatar Aurel

sendSyncCommand can be defined directly on subscription

parent 566f0498
......@@ -176,14 +176,41 @@ class SyncMLSubscription(XMLObject):
"""
return "%s%%" % (self.getSourceValue().getPath().replace("_","\_"),)
def sendSyncCommand(self, min_gid, max_gid, message_id, activate_kw):
"""
This methods is intented to be called by asynchronous engine in activity to
send sync commands for a subset of data
"""
# Build Message
syncml_response = SyncMLResponse()
# XXX Make a generic method that already exists in engines
syncml_response.addHeader(
session_id=self.getSessionId(),
message_id=message_id,
target=self.getUrlString(),
source=self.getSubscriptionUrlString())
syncml_response.addBody()
self._getSyncMLData(
syncml_response=syncml_response,
min_gid=min_gid,
max_gid=max_gid,
)
# Send the message in activity to prevent recomputation of data in case of
# transport failure
# activate_kw["group_method_id"] = None
# activate_kw["group_method_cost"] = .05
self.activate(**activate_kw).sendMessage(xml=str(syncml_response))
security.declarePrivate('getAndActivate')
def getAndActivate(self, callback, method_kw, activate_kw, **kw):
def getAndActivate(self, callback, activate_kw, **kw):
"""
This methods is called by the asynchronous engine to split activity
generation into activities.
callback : method to call in activity
method_kw : callback's parameters
activate_kw : activity parameters to pass to activate call
kw : any parameter getAndActivate can required if it calls itself
......@@ -223,13 +250,13 @@ class SyncMLSubscription(XMLObject):
syncml_logger.info("--> calling getAndActivate in activity, min = %s" %
(kw["min_gid"],))
self.activate(**next_kw).getAndActivate(
callback, method_kw, activate_kw, **kw)
callback, activate_kw, **kw)
generated_other_activity = True
message_id_list = self.getNextMessageIdList(id_count=result_count)
# XXX maybe (result_count / packet_size) + 1 instead of result_count
message_id_list.reverse() # We pop each id in the following loop
activate = self.getPortalObject().portal_synchronizations.activate
activate = self.activate
callback_method = getattr(activate(**activate_kw), callback)
if generated_other_activity:
# XXX Can be factorized with following code
......@@ -496,8 +523,8 @@ class SyncMLSubscription(XMLObject):
elif action['command'] == 'Delete':
status_code="success"
document = self.getDocumentFromGid(signature.getId())
syncml_logger.info("Deleting signature %s & doc %s" %(signature.getPath(),
document.getPath()))
# syncml_logger.info("Deleting signature %s & doc %s" %(signature.getPath(),
# document.getPath()))
path_list.remove(signature.getPath())
if document is not None:
# XXX Can't we get conflict ?
......
......@@ -149,6 +149,7 @@ class SyncMLSynchronousEngine(EngineMixin):
raise ValueError("Authentication failed, impossible to sync data")
# Apply command & send modifications
# XXX This can be called on subscription instead
syncml_response = self._generateBaseResponse(subscriber)
# Apply status about object send & synchronized if any
......
......@@ -440,37 +440,4 @@ class SynchronizationTool(BaseTool):
tag=activate_kw).sendMessage(xml=str(syncml_response))
def sendSyncCommand(self, gid_list, message_id, subscription_path,
activate_kw, first_call=False, last_call=False):
"""
This methods is intented to be called by asynchronous engine in activity to
send sync commands for a subset of data
"""
subscription = self.restrictedTraverse(subscription_path)
assert subscription is not None, "Impossible to find subscription %s" \
% (subscription_path)
# Build Message
syncml_response = SyncMLResponse()
syncml_response.addHeader(
session_id=subscription.getSessionId(),
message_id=message_id,
target=subscription.getUrlString(),
source=subscription.getSubscriptionUrlString())
syncml_response.addBody()
subscription._getSyncMLData(
syncml_response=syncml_response,
gid_list=gid_list,
first_call=first_call,
last_call=last_call,
)
# Send the message in activity to prevent recomputation of data in case of
# transport failure
# activate_kw["group_method_id"] = None
# activate_kw["group_method_cost"] = .05
subscription.activate(**activate_kw).sendMessage(xml=str(syncml_response))
InitializeClass(SynchronizationTool)
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