Commit f1d0f4da authored by Aurel's avatar Aurel

remove useless access to document in _getSyncMLData as data is now retrieved from sql table

parent 76113390
...@@ -704,10 +704,12 @@ class SyncMLSubscription(XMLObject): ...@@ -704,10 +704,12 @@ class SyncMLSubscription(XMLObject):
if portal.portal_preferences.getPreferredCheckDeleteAtEnd() is False: if portal.portal_preferences.getPreferredCheckDeleteAtEnd() is False:
raise NotImplementedError raise NotImplementedError
object_list = [traverse(x.path) for x in self.z_get_syncml_path_list( object_list = self.z_get_syncml_path_list(
min_gid=min_gid, min_gid=min_gid,
max_gid=max_gid, max_gid=max_gid,
path=self.getSearchableSourcePath())] path=self.getSearchableSourcePath())
syncml_logger.info("getSyncMLData, object list is %s" % ([x.path for x in object_list]))
alert_code = self.getSyncmlAlertCode() alert_code = self.getSyncmlAlertCode()
sync_all = alert_code in ("refresh_from_client_only", "slow_sync") sync_all = alert_code in ("refresh_from_client_only", "slow_sync")
...@@ -721,48 +723,34 @@ class SyncMLSubscription(XMLObject): ...@@ -721,48 +723,34 @@ class SyncMLSubscription(XMLObject):
path_list = [] path_list = []
for result in object_list: for result in object_list:
object_path = result.getPath() document_path = result.path
# if loop >= max_range: gid = result.gid
# # For now, maximum object list is always none, so we will never come here ! document_data = result.data
# syncml_logger.warning("...Send too many objects, will split message...")
# finished = False
# break
# Get the GID
document = traverse(object_path)
gid = self.getGidFromObject(document)
if not gid:
raise ValueError("Impossible to compute gid for %s" %(object_path))
if True: # not loop: # or len(syncml_response) < MAX_LEN:
# XXX must find a better way to prevent sending # XXX must find a better way to prevent sending
# no object due to a too small limit # no object due to a too small limit
signature = self.getSignatureFromGid(gid) signature = self.getSignatureFromGid(gid)
more_data = False more_data = False
if signature: if signature:
syncml_logger.debug("signature is %s = %s" %(signature.getRelativeUrl(), syncml_logger.info("signature is %s = %s" %(signature.getRelativeUrl(),
signature.getValidationState())) signature.getValidationState()))
# For the case it was never synchronized, we have to send everything # For the case it was never synchronized, we have to send everything
if not signature or sync_all: if not signature or sync_all:
# Either it is the first time we get this object # Either it is the first time we get this object
# either the synchronization process required # either the synchronization process required
# to send every data again as if it was never done before # to send every data again as if it was never done before
document_data = conduit.getXMLFromObjectWithId(
# XXX To be renamed (getDocumentData) independant from format
document,
xml_mapping=self.getXmlBindingGeneratorMethodId(),
context_document=self.getPath())
if not document_data: if not document_data:
# XXX Which case leads here ?
raise ValueError("No data for %s / %s" %(gid, document_path))
continue continue
if create_signature: if create_signature:
if not signature: if not signature:
signature = self.newContent(portal_type='SyncML Signature', signature = self.newContent(portal_type='SyncML Signature',
id=gid, id=gid,
reference=document.getPath(), reference=document_path,
temporary_data=document_data) temporary_data=document_data)
syncml_logger.debug("Created a signature %s for gid = %s, path %s" syncml_logger.info("Created a signature %s for gid = %s, path %s"
% (signature.getPath(), gid, document.getPath())) % (signature.getPath(), gid, document_path))
if len(document_data) > MAX_LEN: if len(document_data) > MAX_LEN:
syncml_logger.info("data too big, sending multiple message") syncml_logger.info("data too big, sending multiple message")
more_data = True more_data = True
...@@ -777,7 +765,7 @@ class SyncMLSubscription(XMLObject): ...@@ -777,7 +765,7 @@ class SyncMLSubscription(XMLObject):
# confirmation that the document was well synchronized # confirmation that the document was well synchronized
signature.setTemporaryData(document_data) signature.setTemporaryData(document_data)
signature.doSync() signature.doSync()
syncml_logger.debug("signature %s is syncing" syncml_logger.info("signature %s is syncing"
% (signature.getRelativeUrl(),)) % (signature.getRelativeUrl(),))
# Generate the message # Generate the message
...@@ -791,10 +779,6 @@ class SyncMLSubscription(XMLObject): ...@@ -791,10 +779,6 @@ class SyncMLSubscription(XMLObject):
elif signature.getValidationState() in ('not_synchronized', 'synchronized', elif signature.getValidationState() in ('not_synchronized', 'synchronized',
'conflict_resolved_with_merge'): 'conflict_resolved_with_merge'):
# We don't have synchronized this object yet but it has a signature # We don't have synchronized this object yet but it has a signature
xml_object = conduit.getXMLFromObjectWithId(document,
xml_mapping=self.getXmlBindingGeneratorMethodId(),
context_document=self.getPath())
if signature.getValidationState() == 'conflict_resolved_with_merge': if signature.getValidationState() == 'conflict_resolved_with_merge':
# XXX Why putting confirmation message here # XXX Why putting confirmation message here
# Server can get confirmation of sync although it has not yet # Server can get confirmation of sync although it has not yet
...@@ -804,17 +788,17 @@ class SyncMLSubscription(XMLObject): ...@@ -804,17 +788,17 @@ class SyncMLSubscription(XMLObject):
source_ref=signature.getId(), source_ref=signature.getId(),
sync_code='conflict_resolved_with_merge', sync_code='conflict_resolved_with_merge',
command='Replace') command='Replace')
syncml_logger.debug("\tMD5 is %s for %s" %((signature.checkMD5(xml_object)), syncml_logger.info("\tMD5 is %s for %s" %((signature.checkMD5(document_data)),
signature.getReference())) signature.getReference()))
if not signature.checkMD5(xml_object): if not signature.checkMD5(document_data):
# MD5 checksum tell there is a modification of the object # MD5 checksum tell there is a modification of the object
if conduit.getContentType() != 'text/xml': if conduit.getContentType() != 'text/xml':
# If there is no xml, we re-send the whole object # If there is no xml, we re-send the whole object
# XXX this must be managed by conduit ? # XXX this must be managed by conduit ?
data_diff = xml_object data_diff = document_data
else: else:
# Compute the diff # Compute the diff
new_document = conduit.replaceIdFromXML(xml_object, 'gid', gid) new_document = conduit.replaceIdFromXML(document_data, 'gid', gid)
previous_document = conduit.replaceIdFromXML(signature.getData(), previous_document = conduit.replaceIdFromXML(signature.getData(),
'gid', gid) 'gid', gid)
data_diff = conduit.generateDiff(new_data=new_document, data_diff = conduit.generateDiff(new_data=new_document,
...@@ -847,7 +831,7 @@ class SyncMLSubscription(XMLObject): ...@@ -847,7 +831,7 @@ class SyncMLSubscription(XMLObject):
# Store the new representation of the document # Store the new representation of the document
# It will be copy to "data" property once synchronization # It will be copy to "data" property once synchronization
# is confirmed # is confirmed
signature.setTemporaryData(xml_object) signature.setTemporaryData(document_data)
signature.doSync() signature.doSync()
syncml_logger.debug("signature %s is syncing" syncml_logger.debug("signature %s is syncing"
% (signature.getRelativeUrl(),)) % (signature.getRelativeUrl(),))
...@@ -878,7 +862,7 @@ class SyncMLSubscription(XMLObject): ...@@ -878,7 +862,7 @@ class SyncMLSubscription(XMLObject):
previous_xml_with_gid = conduit.replaceIdFromXML(signature.getData(), previous_xml_with_gid = conduit.replaceIdFromXML(signature.getData(),
'gid', gid, 'gid', gid,
as_string=False) as_string=False)
conduit.updateNode(xml=xml_update, object=document, conduit.updateNode(xml=xml_update, object=traverse(document_path),
previous_xml=previous_xml_with_gid, force=True, previous_xml=previous_xml_with_gid, force=True,
gid=gid, gid=gid,
signature=signature, signature=signature,
...@@ -927,9 +911,6 @@ class SyncMLSubscription(XMLObject): ...@@ -927,9 +911,6 @@ class SyncMLSubscription(XMLObject):
else: else:
syncml_logger.info("Splitting document") syncml_logger.info("Splitting document")
break break
else:
syncml_logger.warning("Package is going to be splitted")
break
self.SQLCatalog_indexSyncMLDocumentList(path_list) self.SQLCatalog_indexSyncMLDocumentList(path_list)
syncml_logger.info("_getSyncMLData end with finished %s" syncml_logger.info("_getSyncMLData end with finished %s"
...@@ -969,6 +950,18 @@ class SyncMLSubscription(XMLObject): ...@@ -969,6 +950,18 @@ class SyncMLSubscription(XMLObject):
else: else:
return self._baseGetXmlBindingGeneratorMethodId(default=default) return self._baseGetXmlBindingGeneratorMethodId(default=default)
security.declareProtected(Permissions.AccessContentsInformation,
'getDataFromDocument')
def getDataFromDocument(self, document):
"""
Return the data (xml or other) for a given document
"""
return self.getConduit().getXMLFromObjectWithId(
document,
xml_mapping=self.getXmlBindingGeneratorMethodId(),
context_document=self.getPath())
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getGidFromObject') 'getGidFromObject')
def getGidFromObject(self, object, encoded=True): def getGidFromObject(self, object, encoded=True):
......
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