Commit 9490b306 authored by Aurel's avatar Aurel

move methods on Subscription class to remove useless placeholder

parent 259d38bb
......@@ -168,6 +168,22 @@ class SyncMLSubscription(XMLObject):
**method_kw)
return result_count
security.declarePrivate('generateBaseResponse')
def generateBaseResponse(self, message_id=None):
"""
Return a message containing default headers
"""
if not message_id:
message_id=self.getNextMessageId(),
syncml_response = SyncMLResponse()
syncml_response.addHeader(
session_id=self.getSessionId(),
message_id=message_id,
target=self.getUrlString(),
source=self.getSubscriptionUrlString())
syncml_response.addBody()
return syncml_response
security.declarePrivate('getSearchableSourcePath')
def getSearchableSourcePath(self):
"""
......@@ -183,26 +199,44 @@ class SyncMLSubscription(XMLObject):
"""
# 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()
syncml_response = self.generateBaseResponse(message_id)
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('applySyncCommand')
def applySyncCommand(self, response_message_id, activate_kw, **kw):
"""
This methods is intented to be called by asynchronous engine in activity to
apply sync commands for a subset of data
"""
# Build Message
if response_message_id:
syncml_response = self.generateBaseResponse()
syncml_response.addBody()
else:
syncml_response = None
self._applySyncCommand(syncml_response=syncml_response, **kw)
# Send the message in activity to prevent recomputing data in case of
# transport failure
if syncml_response:
syncml_logger("---- %s sending %s notifications of sync"
% (self.getTitle(),
syncml_response.sync_confirmation_counter))
self.activate(activity="SQLQueue",
# group_method_id=None,
# group_method_cost=.05,
tag=activate_kw).sendMessage(xml=str(syncml_response))
security.declarePrivate('getAndActivate')
def getAndActivate(self, callback, activate_kw, **kw):
......@@ -364,14 +398,14 @@ class SyncMLSubscription(XMLObject):
Browse the list of sync command received, apply them and generate answer
"""
for action in syncml_request.sync_command_list:
self.applySyncCommand(
self._applySyncCommand(
action=action,
request_message_id=syncml_request.header["message_id"],
syncml_response=syncml_response,
simulate=simulate)
security.declarePrivate('applySyncCommand')
def applySyncCommand(self, action, request_message_id, syncml_response,
def _applySyncCommand(self, action, request_message_id, syncml_response,
simulate=False):
"""
Apply a sync command received
......@@ -602,12 +636,7 @@ class SyncMLSubscription(XMLObject):
Send an empty message containing the final tag to notify the end of
the "sending_modification" stage of the synchronization
"""
syncml_response = SyncMLResponse()
syncml_response.addHeader(
session_id=self.getSessionId(),
message_id=self.getNextMessageId(),
target=self.getUrlString(),
source=self.getSubscriptionUrlString())
syncml_response = self.generateBaseResponse()
syncml_response.addBody()
syncml_response.addFinal()
......
......@@ -75,7 +75,7 @@ class SyncMLAsynchronousEngine(EngineMixin):
if subscription.getSyncmlAlertCode() in ("one_way_from_server",
"refresh_from_server_only"):
# We only get data from server
syncml_response = self._generateBaseResponse(subscription)
syncml_response = subscription.generateBaseResponse()
syncml_response.addFinal()
else:
# Make sure it is launched after indexation step
......@@ -102,7 +102,7 @@ class SyncMLAsynchronousEngine(EngineMixin):
% (len(syncml_request.sync_command_list)))
if syncml_request.isFinal:
if not syncml_response:
syncml_response = self._generateBaseResponse(subscription)
syncml_response = subscription.generateBaseResponse()
# We got and process all sync command from server
# notify it that all modifications were applied
syncml_response.addFinal()
......@@ -231,7 +231,7 @@ class SyncMLAsynchronousEngine(EngineMixin):
# Server has no modification to send to client, return final message
syncml_logger.info("X-> Server sending final message")
if not syncml_response:
syncml_response = self._generateBaseResponse(subscriber)
syncml_response = subscriber.generateBaseResponse()
syncml_response.addFinal()
if subscriber.getSynchronizationState() == "finished":
......@@ -280,9 +280,9 @@ class SyncMLAsynchronousEngine(EngineMixin):
response_id_list = [None for x in
xrange(len(syncml_request.sync_command_list))]
split = getSite().portal_preferences.getPreferredSyncActionPerActivityCount()
if not split:
if not split: # We do not use activities
if send_response:
syncml_response = self._generateBaseResponse(subscription)
syncml_response = subscription.generateBaseResponse()
else:
syncml_response = None
subscription.applyActionList(syncml_request, syncml_response)
......@@ -291,10 +291,9 @@ class SyncMLAsynchronousEngine(EngineMixin):
activity="SQLQueue",
priority=ACTIVITY_PRIORITY,
tag=subscription.getRelativeUrl()).sendMessage(xml=str(syncml_response))
else:
# XXX For now always split by one
activate = subscription.getPortalObject().portal_synchronizations.activate
activate = subscription.activate
activate_kw = {
"activity" :"SQLQueue",
"priority" : ACTIVITY_PRIORITY,
......@@ -305,10 +304,9 @@ class SyncMLAsynchronousEngine(EngineMixin):
for action in syncml_request.sync_command_list:
syncml_logger.info("---> launch action in activity %s" %(action,))
activate(**activate_kw).applySyncCommand(
subscription_path=subscription.getRelativeUrl(),
response_message_id=response_id_list.pop(),
activate_kw=activate_kw,
action=action,
request_message_id=syncml_request.header["message_id"],
simulate=False)
# XXX Response is not send here
# Response is sent by the activity
......@@ -46,15 +46,6 @@ class EngineMixin(object):
security = ClassSecurityInfo()
def _generateBaseResponse(self, subscription):
syncml_response = SyncMLResponse()
syncml_response.addHeader(
session_id=subscription.getSessionId(),
message_id=subscription.getNextMessageId(),
target=subscription.getUrlString(),
source=subscription.getSubscriptionUrlString())
syncml_response.addBody()
return syncml_response
security.declarePrivate('_readStatusList')
def _readStatusList(self, syncml_request, domain, syncml_response=None,
......@@ -83,7 +74,7 @@ class EngineMixin(object):
status['authentication_type']))
# XXX Not working To Review !
raise NotImplementedError("Adding credentials")
syncml_response = self._generateBaseResponse(domain)
syncml_response = domain.generateBaseResponse()
syncml_response.addCredentialMessage(domain)
return syncml_response
elif status['status_code'] == \
......
......@@ -29,7 +29,6 @@ from logging import getLogger
from Products.ERP5SyncML.Engine.EngineMixin import EngineMixin
from Products.ERP5SyncML.SyncMLConstant import SynchronizationError
from Products.ERP5.ERP5Site import getSite
syncml_logger = getLogger('ERP5SyncML')
......@@ -55,7 +54,7 @@ class SyncMLSynchronousEngine(EngineMixin):
# Must check what server tell about database synchronization
# and update the mode if required
syncml_response = self._generateBaseResponse(subscription)
syncml_response = subscription.generateBaseResponse()
# Read & apply status about databases & synchronizations
try:
......@@ -150,7 +149,7 @@ class SyncMLSynchronousEngine(EngineMixin):
# Apply command & send modifications
# XXX This can be called on subscription instead
syncml_response = self._generateBaseResponse(subscriber)
syncml_response = subscriber.generateBaseResponse()
# Apply status about object send & synchronized if any
self._readStatusList(syncml_request, subscriber, syncml_response, True)
......
......@@ -402,42 +402,4 @@ class SynchronizationTool(BaseTool):
return str(syncml_response)
# As engines are not zodb objects, the tool acts as a placeholder for methods
# that need to be called in activities
def applySyncCommand(self, subscription_path, response_message_id,
activate_kw, **kw):
"""
This methods is intented to be called by asynchronous engine in activity to
apply 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
if response_message_id:
syncml_response = SyncMLResponse()
syncml_response.addHeader(
session_id=subscription.getSessionId(),
message_id=response_message_id,
target=subscription.getUrlString(),
source=subscription.getSubscriptionUrlString())
syncml_response.addBody()
else:
syncml_response = None
subscription.applySyncCommand(syncml_response=syncml_response, **kw)
# Send the message in activity to prevent recomputing data in case of
# transport failure
if syncml_response:
syncml_logger("---- %s sending %s notifications of sync"
% (subscription.getTitle(),
syncml_response.sync_confirmation_counter))
subscription.activate(activity="SQLQueue",
# group_method_id=None,
# group_method_cost=.05,
tag=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