Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leo Le Bouter
erp5
Commits
9490b306
Commit
9490b306
authored
Jul 01, 2013
by
Aurel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move methods on Subscription class to remove useless placeholder
parent
259d38bb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
77 deletions
+56
-77
product/ERP5SyncML/Document/SyncMLSubscription.py
product/ERP5SyncML/Document/SyncMLSubscription.py
+46
-17
product/ERP5SyncML/Engine/AsynchronousEngine.py
product/ERP5SyncML/Engine/AsynchronousEngine.py
+7
-9
product/ERP5SyncML/Engine/EngineMixin.py
product/ERP5SyncML/Engine/EngineMixin.py
+1
-10
product/ERP5SyncML/Engine/SynchronousEngine.py
product/ERP5SyncML/Engine/SynchronousEngine.py
+2
-3
product/ERP5SyncML/Tool/SynchronizationTool.py
product/ERP5SyncML/Tool/SynchronizationTool.py
+0
-38
No files found.
product/ERP5SyncML/Document/SyncMLSubscription.py
View file @
9490b306
...
...
@@ -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()
...
...
product/ERP5SyncML/Engine/AsynchronousEngine.py
View file @
9490b306
...
...
@@ -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
=
s
elf
.
_generateBaseResponse
(
subscription
)
syncml_response
=
s
ubscription
.
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
=
s
elf
.
_generateBaseResponse
(
subscription
)
syncml_response
=
s
ubscription
.
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
=
s
elf
.
_generateBaseResponse
(
subscriber
)
syncml_response
=
s
ubscriber
.
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
=
s
elf
.
_generateBaseResponse
(
subscription
)
syncml_response
=
s
ubscription
.
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
product/ERP5SyncML/Engine/EngineMixin.py
View file @
9490b306
...
...
@@ -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'
]
==
\
...
...
product/ERP5SyncML/Engine/SynchronousEngine.py
View file @
9490b306
...
...
@@ -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
=
s
elf
.
_generateBaseResponse
(
subscription
)
syncml_response
=
s
ubscription
.
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
=
s
elf
.
_generateBaseResponse
(
subscriber
)
syncml_response
=
s
ubscriber
.
generateBaseResponse
(
)
# Apply status about object send & synchronized if any
self
.
_readStatusList
(
syncml_request
,
subscriber
,
syncml_response
,
True
)
...
...
product/ERP5SyncML/Tool/SynchronizationTool.py
View file @
9490b306
...
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment