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,214 +723,193 @@ class SyncMLSubscription(XMLObject): ...@@ -721,214 +723,193 @@ 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...") # XXX must find a better way to prevent sending
# finished = False # no object due to a too small limit
# break signature = self.getSignatureFromGid(gid)
# Get the GID more_data = False
document = traverse(object_path) if signature:
gid = self.getGidFromObject(document) syncml_logger.info("signature is %s = %s" %(signature.getRelativeUrl(),
if not gid: signature.getValidationState()))
raise ValueError("Impossible to compute gid for %s" %(object_path)) # For the case it was never synchronized, we have to send everything
if not signature or sync_all:
if True: # not loop: # or len(syncml_response) < MAX_LEN: # Either it is the first time we get this object
# XXX must find a better way to prevent sending # either the synchronization process required
# no object due to a too small limit # to send every data again as if it was never done before
signature = self.getSignatureFromGid(gid) if not document_data:
more_data = False # XXX Which case leads here ?
if signature: raise ValueError("No data for %s / %s" %(gid, document_path))
syncml_logger.debug("signature is %s = %s" %(signature.getRelativeUrl(), continue
signature.getValidationState()))
# For the case it was never synchronized, we have to send everything if create_signature:
if not signature or sync_all: if not signature:
# Either it is the first time we get this object signature = self.newContent(portal_type='SyncML Signature',
# either the synchronization process required id=gid,
# to send every data again as if it was never done before reference=document_path,
document_data = conduit.getXMLFromObjectWithId( temporary_data=document_data)
# XXX To be renamed (getDocumentData) independant from format syncml_logger.info("Created a signature %s for gid = %s, path %s"
document, % (signature.getPath(), gid, document_path))
xml_mapping=self.getXmlBindingGeneratorMethodId(), if len(document_data) > MAX_LEN:
context_document=self.getPath()) syncml_logger.info("data too big, sending multiple message")
more_data = True
if not document_data: finished = False
continue document_data, rest_string = cutXML(document_data, MAX_LEN)
# Store the remaining data to send it later
if create_signature: signature.setPartialData(rest_string)
if not signature: signature.setPartialAction(ADD_ACTION)
signature = self.newContent(portal_type='SyncML Signature', signature.changeToPartial()
id=gid, else:
reference=document.getPath(), # The data will be copied in 'data' property once we get
temporary_data=document_data) # confirmation that the document was well synchronized
syncml_logger.debug("Created a signature %s for gid = %s, path %s" signature.setTemporaryData(document_data)
% (signature.getPath(), gid, document.getPath())) signature.doSync()
if len(document_data) > MAX_LEN: syncml_logger.info("signature %s is syncing"
syncml_logger.info("data too big, sending multiple message")
more_data = True
finished = False
document_data, rest_string = cutXML(document_data, MAX_LEN)
# Store the remaining data to send it later
signature.setPartialData(rest_string)
signature.setPartialAction(ADD_ACTION)
signature.changeToPartial()
else:
# The data will be copied in 'data' property once we get
# confirmation that the document was well synchronized
signature.setTemporaryData(document_data)
signature.doSync()
syncml_logger.debug("signature %s is syncing"
% (signature.getRelativeUrl(),))
# Generate the message
syncml_response.addSyncCommand(
sync_command=ADD_ACTION,
gid=gid,
data=document_data,
more_data=more_data,
media_type=conduit.getContentType())
elif signature.getValidationState() in ('not_synchronized', 'synchronized',
'conflict_resolved_with_merge'):
# 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':
# XXX Why putting confirmation message here
# Server can get confirmation of sync although it has not yet
# send its data modification to the client
# This must be checked against specifications
syncml_response.addConfirmationMessage(
source_ref=signature.getId(),
sync_code='conflict_resolved_with_merge',
command='Replace')
syncml_logger.debug("\tMD5 is %s for %s" %((signature.checkMD5(xml_object)),
signature.getReference()))
if not signature.checkMD5(xml_object):
# MD5 checksum tell there is a modification of the object
if conduit.getContentType() != 'text/xml':
# If there is no xml, we re-send the whole object
# XXX this must be managed by conduit ?
data_diff = xml_object
else:
# Compute the diff
new_document = conduit.replaceIdFromXML(xml_object, 'gid', gid)
previous_document = conduit.replaceIdFromXML(signature.getData(),
'gid', gid)
data_diff = conduit.generateDiff(new_data=new_document,
former_data=previous_document)
if not data_diff:
# MD5 Checksum can detect changes like <lang/> != <lang></lang>
# but Diff generator will return no diff for it
# in this case, no need to send diff
if signature.getValidationState() != "synchronized":
signature.synchronize()
syncml_logger.debug("signature %s is synchronized"
% (signature.getRelativeUrl(),))
path_list.append(signature.getPath())
continue
# Split data if necessary
if len(data_diff) > MAX_LEN:
syncml_logger.info("data too big, sending multiple messages")
more_data = True
finished = False
data_diff, rest_string = cutXML(data_diff, MAX_LEN)
signature.setPartialData(rest_string)
signature.setPartialAction(REPLACE_ACTION)
if signature.getValidationState() != 'partial':
signature.changeToPartial()
syncml_logger.info("signature %s is partial"
% (signature.getRelativeUrl(),))
else:
# Store the new representation of the document
# It will be copy to "data" property once synchronization
# is confirmed
signature.setTemporaryData(xml_object)
signature.doSync()
syncml_logger.debug("signature %s is syncing"
% (signature.getRelativeUrl(),))
# Generate the command
syncml_logger.debug("will send Replace command with %s"
% (data_diff,))
syncml_response.addSyncCommand(
sync_command=REPLACE_ACTION,
gid=gid,
data=data_diff,
more_data=more_data,
media_type=conduit.getContentType())
elif signature.getValidationState() != 'synchronized':
# We should not have this case when we are in CONFLICT_MERGE
syncml_logger.debug("signature %s is synchronized"
% (signature.getRelativeUrl(),)) % (signature.getRelativeUrl(),))
signature.synchronize()
# Generate the message
elif signature.getValidationState() == \ syncml_response.addSyncCommand(
'conflict_resolved_with_client_command_winning': sync_command=ADD_ACTION,
# We have decided to apply the update gid=gid,
# XXX previous_xml will be geXML instead of getTempXML because data=document_data,
# some modification was already made and the update more_data=more_data,
# may not apply correctly media_type=conduit.getContentType())
xml_update = signature.getPartialData()
previous_xml_with_gid = conduit.replaceIdFromXML(signature.getData(), elif signature.getValidationState() in ('not_synchronized', 'synchronized',
'gid', gid, 'conflict_resolved_with_merge'):
as_string=False) # We don't have synchronized this object yet but it has a signature
conduit.updateNode(xml=xml_update, object=document, if signature.getValidationState() == 'conflict_resolved_with_merge':
previous_xml=previous_xml_with_gid, force=True, # XXX Why putting confirmation message here
gid=gid, # Server can get confirmation of sync although it has not yet
signature=signature, # send its data modification to the client
domain=self) # This must be checked against specifications
syncml_response.addConfirmationMessage( syncml_response.addConfirmationMessage(
target_ref=gid, source_ref=signature.getId(),
sync_code='conflict_resolved_with_client_command_winning', sync_code='conflict_resolved_with_merge',
command='Replace') command='Replace')
signature.synchronize() syncml_logger.info("\tMD5 is %s for %s" %((signature.checkMD5(document_data)),
syncml_logger.debug("signature %s is synchronized" signature.getReference()))
% (signature.getRelativeUrl(),)) if not signature.checkMD5(document_data):
# MD5 checksum tell there is a modification of the object
if conduit.getContentType() != 'text/xml':
# If there is no xml, we re-send the whole object
# XXX this must be managed by conduit ?
data_diff = document_data
else:
# Compute the diff
new_document = conduit.replaceIdFromXML(document_data, 'gid', gid)
previous_document = conduit.replaceIdFromXML(signature.getData(),
'gid', gid)
data_diff = conduit.generateDiff(new_data=new_document,
former_data=previous_document)
if not data_diff:
# MD5 Checksum can detect changes like <lang/> != <lang></lang>
# but Diff generator will return no diff for it
# in this case, no need to send diff
if signature.getValidationState() != "synchronized":
signature.synchronize()
syncml_logger.debug("signature %s is synchronized"
% (signature.getRelativeUrl(),))
path_list.append(signature.getPath())
continue
elif signature.getValidationState() == 'partial': # Split data if necessary
# Case of partially sent data if len(data_diff) > MAX_LEN:
xml_string = signature.getPartialData() syncml_logger.info("data too big, sending multiple messages")
# XXX Cutting must be managed by conduit
# Here it is too specific to XML data
if len(xml_string) > MAX_LEN:
syncml_logger.info("Remaining data too big, splitting it...")
more_data = True more_data = True
finished = False finished = False
xml_string = signature.getFirstPdataChunk(MAX_LEN) data_diff, rest_string = cutXML(data_diff, MAX_LEN)
xml_string = etree.CDATA(xml_string.decode('utf-8')) signature.setPartialData(rest_string)
signature.setPartialAction(REPLACE_ACTION)
if signature.getValidationState() != 'partial':
signature.changeToPartial()
syncml_logger.info("signature %s is partial"
% (signature.getRelativeUrl(),))
else:
# Store the new representation of the document
# It will be copy to "data" property once synchronization
# is confirmed
signature.setTemporaryData(document_data)
signature.doSync()
syncml_logger.debug("signature %s is syncing"
% (signature.getRelativeUrl(),))
# Generate the command
syncml_logger.debug("will send Replace command with %s"
% (data_diff,))
syncml_response.addSyncCommand( syncml_response.addSyncCommand(
sync_command=signature.getPartialAction(), sync_command=REPLACE_ACTION,
gid=gid, gid=gid,
data=xml_string, data=data_diff,
more_data=more_data, more_data=more_data,
media_type=self.getContentType()) media_type=conduit.getContentType())
if not more_data: elif signature.getValidationState() != 'synchronized':
signature.doSync() # We should not have this case when we are in CONFLICT_MERGE
syncml_logger.debug("signature %s is syncing" syncml_logger.debug("signature %s is synchronized"
% (signature.getRelativeUrl(),)) % (signature.getRelativeUrl(),))
elif signature.getValidationState() in ('syncing'): signature.synchronize()
raise ValueError("Must not get signature in %s state here, signature is %s"
% (signature.getValidationState(),
signature.getPath(),))
if signature: elif signature.getValidationState() == \
path_list.append(signature.getPath()) 'conflict_resolved_with_client_command_winning':
# We have decided to apply the update
# XXX previous_xml will be geXML instead of getTempXML because
# some modification was already made and the update
# may not apply correctly
xml_update = signature.getPartialData()
previous_xml_with_gid = conduit.replaceIdFromXML(signature.getData(),
'gid', gid,
as_string=False)
conduit.updateNode(xml=xml_update, object=traverse(document_path),
previous_xml=previous_xml_with_gid, force=True,
gid=gid,
signature=signature,
domain=self)
syncml_response.addConfirmationMessage(
target_ref=gid,
sync_code='conflict_resolved_with_client_command_winning',
command='Replace')
signature.synchronize()
syncml_logger.debug("signature %s is synchronized"
% (signature.getRelativeUrl(),))
elif signature.getValidationState() == 'partial':
# Case of partially sent data
xml_string = signature.getPartialData()
# XXX Cutting must be managed by conduit
# Here it is too specific to XML data
if len(xml_string) > MAX_LEN:
syncml_logger.info("Remaining data too big, splitting it...")
more_data = True
finished = False
xml_string = signature.getFirstPdataChunk(MAX_LEN)
xml_string = etree.CDATA(xml_string.decode('utf-8'))
syncml_response.addSyncCommand(
sync_command=signature.getPartialAction(),
gid=gid,
data=xml_string,
more_data=more_data,
media_type=self.getContentType())
if not more_data: if not more_data:
pass signature.doSync()
else: syncml_logger.debug("signature %s is syncing"
syncml_logger.info("Splitting document") % (signature.getRelativeUrl(),))
break elif signature.getValidationState() in ('syncing'):
raise ValueError("Must not get signature in %s state here, signature is %s"
% (signature.getValidationState(),
signature.getPath(),))
if signature:
path_list.append(signature.getPath())
if not more_data:
pass
else: else:
syncml_logger.warning("Package is going to be splitted") syncml_logger.info("Splitting document")
break break
self.SQLCatalog_indexSyncMLDocumentList(path_list) self.SQLCatalog_indexSyncMLDocumentList(path_list)
...@@ -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