Commit 83b39fea authored by Sebastien Robin's avatar Sebastien Robin

added getSubscriberDocument, getPublisherDocument


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@828 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b18d8da1
...@@ -114,6 +114,7 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -114,6 +114,7 @@ class PublicationSynchronization(XMLSyncUtils):
xml_client = self.readResponse(from_url='file://tmp/sync_server') xml_client = self.readResponse(from_url='file://tmp/sync_server')
LOG('PubSync',0,'Starting... msg: %s' % str(xml_client)) LOG('PubSync',0,'Starting... msg: %s' % str(xml_client))
result = None result = None
publication = self.getPublication(id)
if xml_client is not None: if xml_client is not None:
if type(xml_client) in (type('a'),type(u'a')): if type(xml_client) in (type('a'),type(u'a')):
...@@ -137,16 +138,17 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -137,16 +138,17 @@ class PublicationSynchronization(XMLSyncUtils):
subscriber = self.getPublication(id).getSubscriber(subscription_url) subscriber = self.getPublication(id).getSubscriber(subscription_url)
if subscriber == None: if subscriber == None:
subscriber = Subscriber(subscription_url) subscriber = Subscriber(subscription_url)
subscriber.setXMLMapping(publication.getXMLMapping())
self.getPublication(id).addSubscriber(subscriber) self.getPublication(id).addSubscriber(subscriber)
# first synchronization # first synchronization
result = self.PubSyncInit(self.getPublication(id),xml_client,subscriber=subscriber,sync_type=self.SLOW_SYNC) result = self.PubSyncInit(publication,xml_client,subscriber=subscriber,sync_type=self.SLOW_SYNC)
elif self.checkAlert(xml_client) and alert_code in (self.TWO_WAY,self.SLOW_SYNC): elif self.checkAlert(xml_client) and alert_code in (self.TWO_WAY,self.SLOW_SYNC):
result = self.PubSyncInit(publication=self.getPublication(id), result = self.PubSyncInit(publication=publication,
xml_client=xml_client, subscriber=subscriber,sync_type=alert_code) xml_client=xml_client, subscriber=subscriber,sync_type=alert_code)
else: else:
result = self.PubSyncModif(self.getPublication(id), xml_client) result = self.PubSyncModif(publication, xml_client)
elif subscriber is not None: elif subscriber is not None:
# This looks like we are starting a synchronization after # This looks like we are starting a synchronization after
# a conflict resolution by the user # a conflict resolution by the user
......
...@@ -54,7 +54,7 @@ class Conflict(SyncCode, Implicit): ...@@ -54,7 +54,7 @@ class Conflict(SyncCode, Implicit):
def getObjectPath(self): def getObjectPath(self):
""" """
get the domain get the object path
""" """
return self.object_path return self.object_path
...@@ -135,7 +135,39 @@ class Conflict(SyncCode, Implicit): ...@@ -135,7 +135,39 @@ class Conflict(SyncCode, Implicit):
p_sync = getToolByName(self,'portal_synchronizations') p_sync = getToolByName(self,'portal_synchronizations')
p_sync.applyPublisherDocument(self) p_sync.applyPublisherDocument(self)
def applySubscriberDocument(self): def getPublisherDocument(self):
"""
after a conflict resolution, we have decided
to keep the local version of this object
"""
p_sync = getToolByName(self,'portal_synchronizations')
return p_sync.getPublisherDocument(self)
def getPublisherDocumentPath(self):
"""
after a conflict resolution, we have decided
to keep the local version of this object
"""
p_sync = getToolByName(self,'portal_synchronizations')
return p_sync.getPublisherDocumentPath(self)
def getSubscriberDocument(self):
"""
after a conflict resolution, we have decided
to keep the local version of this object
"""
p_sync = getToolByName(self,'portal_synchronizations')
return p_sync.getSubscriberDocument(self)
def getSubscriberDocumentPath(self):
"""
after a conflict resolution, we have decided
to keep the local version of this object
"""
p_sync = getToolByName(self,'portal_synchronizations')
return p_sync.getSubscriberDocument(self)
def applySubscriberDocumentPath(self):
""" """
after a conflict resolution, we have decided after a conflict resolution, we have decided
to keep the local version of this object to keep the local version of this object
...@@ -143,12 +175,12 @@ class Conflict(SyncCode, Implicit): ...@@ -143,12 +175,12 @@ class Conflict(SyncCode, Implicit):
p_sync = getToolByName(self,'portal_synchronizations') p_sync = getToolByName(self,'portal_synchronizations')
p_sync.applySubscriberDocument(self) p_sync.applySubscriberDocument(self)
def applySubscriberValue(self): def applySubscriberValue(self,object=None):
""" """
get the domain get the domain
""" """
p_sync = getToolByName(self,'portal_synchronizations') p_sync = getToolByName(self,'portal_synchronizations')
p_sync.applySubscriberValue(self) p_sync.applySubscriberValue(self,object=object)
def setSubscriber(self, subscriber): def setSubscriber(self, subscriber):
""" """
......
...@@ -38,7 +38,6 @@ from Products.ERP5SyncML import _dtmldir ...@@ -38,7 +38,6 @@ from Products.ERP5SyncML import _dtmldir
from Publication import Publication,Subscriber from Publication import Publication,Subscriber
from Subscription import Subscription,Signature from Subscription import Subscription,Signature
from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml
from XMLSyncUtils import *
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from PublicationSynchronization import PublicationSynchronization from PublicationSynchronization import PublicationSynchronization
from SubscriptionSynchronization import SubscriptionSynchronization from SubscriptionSynchronization import SubscriptionSynchronization
...@@ -53,7 +52,7 @@ import os ...@@ -53,7 +52,7 @@ import os
import string import string
import commands import commands
import random import random
from zLOG import * from zLOG import LOG
from Conduit.ERP5Conduit import ERP5Conduit from Conduit.ERP5Conduit import ERP5Conduit
...@@ -429,6 +428,55 @@ class SynchronizationTool( UniqueObject, SimpleItem, ...@@ -429,6 +428,55 @@ class SynchronizationTool( UniqueObject, SimpleItem,
LOG('applyPublisherDocument, applying on conflict: ',0,conflict) LOG('applyPublisherDocument, applying on conflict: ',0,conflict)
c.applyPublisherValue() c.applyPublisherValue()
security.declareProtected(Permissions.ModifyPortalContent, 'getPublisherDocumentPath')
def getPublisherDocumentPath(self, conflict):
"""
apply the publisher value for all conflict of the given document
"""
subscriber = conflict.getSubscriber()
return conflict.getObjectPath()
security.declareProtected(Permissions.ModifyPortalContent, 'getPublisherDocument')
def getPublisherDocument(self, conflict):
"""
apply the publisher value for all conflict of the given document
"""
publisher_object_path = self.getPublisherDocumentPath(conflict)
LOG('getPublisherDocument publisher_object_path',0,publisher_object_path)
publisher_object = self.unrestrictedTraverse(publisher_object_path)
LOG('getPublisherDocument publisher_object',0,publisher_object)
return publisher_object
security.declareProtected(Permissions.ModifyPortalContent, 'getSubscriberDocumentPath')
def getSubscriberDocumentPath(self, conflict):
"""
apply the publisher value for all conflict of the given document
"""
subscriber = conflict.getSubscriber()
publisher_object_path = conflict.getObjectPath()
publisher_object = self.unrestrictedTraverse(publisher_object_path)
publisher_xml = self.getXMLObject(object=publisher_object,xml_mapping = subscriber.getXMLMapping())
directory = publisher_object.aq_parent
object_id = publisher_object.id + '_conflict_copy'
if object_id in directory.objectIds():
directory._delObject(object_id)
conduit = ERP5Conduit()
conduit.addNode(xml=publisher_xml,object=directory,object_id=object_id)
subscriber_document = directory._getOb(object_id)
for c in self.getConflictList(conflict.getObjectPath()):
if c.getSubscriber() == subscriber:
c.applySubscriberValue(object=subscriber_document)
return subscriber_document.getPhysicalPath()
security.declareProtected(Permissions.ModifyPortalContent, 'getSubscriberDocument')
def getSubscriberDocument(self, conflict):
"""
apply the publisher value for all conflict of the given document
"""
subscriber_object_path = self.getSubscriberDocumentPath(conflict)
subscriber_object = self.unrestrictedTraverse(subscriber_object_path)
return subscriber_object
security.declareProtected(Permissions.ModifyPortalContent, 'applySubscriberDocument') security.declareProtected(Permissions.ModifyPortalContent, 'applySubscriberDocument')
def applySubscriberDocument(self, conflict): def applySubscriberDocument(self, conflict):
""" """
...@@ -440,12 +488,18 @@ class SynchronizationTool( UniqueObject, SimpleItem, ...@@ -440,12 +488,18 @@ class SynchronizationTool( UniqueObject, SimpleItem,
c.applySubscriberValue() c.applySubscriberValue()
security.declareProtected(Permissions.ModifyPortalContent, 'applySubscriberValue') security.declareProtected(Permissions.ModifyPortalContent, 'applySubscriberValue')
def applySubscriberValue(self, conflict): def applySubscriberValue(self, conflict,object=None):
""" """
after a conflict resolution, we have decided after a conflict resolution, we have decided
to keep the local version of an object to keep the local version of an object
""" """
solve_conflict = 1
if object is None:
object = self.unrestrictedTraverse(conflict.getObjectPath()) object = self.unrestrictedTraverse(conflict.getObjectPath())
else:
# This means an object was given, this is used in order
# to see change on a copy, so don't solve conflict
solve_conflict=0
subscriber = conflict.getSubscriber() subscriber = conflict.getSubscriber()
# get the signature: # get the signature:
LOG('p_sync.setRemoteObject, subscriber: ',0,subscriber) LOG('p_sync.setRemoteObject, subscriber: ',0,subscriber)
...@@ -453,6 +507,7 @@ class SynchronizationTool( UniqueObject, SimpleItem, ...@@ -453,6 +507,7 @@ class SynchronizationTool( UniqueObject, SimpleItem,
conduit = ERP5Conduit() conduit = ERP5Conduit()
for xupdate in conflict.getXupdateList(): for xupdate in conflict.getXupdateList():
conduit.updateNode(xml=xupdate,object=object,force=1) conduit.updateNode(xml=xupdate,object=object,force=1)
if solve_conflict:
signature.delConflict(conflict) signature.delConflict(conflict)
if signature.getConflictList() == []: if signature.getConflictList() == []:
signature.setStatus(self.PUB_CONFLICT_MERGE) signature.setStatus(self.PUB_CONFLICT_MERGE)
......
...@@ -52,7 +52,7 @@ import time ...@@ -52,7 +52,7 @@ import time
class TestERP5SyncML(ERP5TypeTestCase): class TestERP5SyncML(ERP5TypeTestCase):
# Different variables used for this test # Different variables used for this test
run_all_test = 1 run_all_test = 0
workflow_id = 'edit_workflow' workflow_id = 'edit_workflow'
first_name1 = 'Sebastien' first_name1 = 'Sebastien'
last_name1 = 'Robin' last_name1 = 'Robin'
...@@ -412,8 +412,6 @@ class TestERP5SyncML(ERP5TypeTestCase): ...@@ -412,8 +412,6 @@ class TestERP5SyncML(ERP5TypeTestCase):
if person.getId()==self.id1: if person.getId()==self.id1:
state_list = portal_sync.getSynchronizationState(person) state_list = portal_sync.getSynchronizationState(person)
for state in state_list: for state in state_list:
LOG('checkSynchronizationStateIsConflict... ',0,state[1])
LOG('checkSynchronizationStateIsConflict... ',0,state[0])
self.failUnless(state[1]==state[0].CONFLICT) self.failUnless(state[1]==state[0].CONFLICT)
person_client1 = self.getPersonClient1() person_client1 = self.getPersonClient1()
for person in person_client1.objectValues(): for person in person_client1.objectValues():
...@@ -426,7 +424,6 @@ class TestERP5SyncML(ERP5TypeTestCase): ...@@ -426,7 +424,6 @@ class TestERP5SyncML(ERP5TypeTestCase):
if person.getId()==self.id1: if person.getId()==self.id1:
state_list = portal_sync.getSynchronizationState(person) state_list = portal_sync.getSynchronizationState(person)
for state in state_list: for state in state_list:
LOG('checkSynchronizationStateIsConflict2... ',0,state[1])
self.failUnless(state[1]==state[0].CONFLICT) self.failUnless(state[1]==state[0].CONFLICT)
# make sure sub object are also in a conflict mode # make sure sub object are also in a conflict mode
person = person_client1._getOb(self.id1) person = person_client1._getOb(self.id1)
...@@ -507,6 +504,27 @@ class TestERP5SyncML(ERP5TypeTestCase): ...@@ -507,6 +504,27 @@ class TestERP5SyncML(ERP5TypeTestCase):
subscriber = conflict.getSubscriber() subscriber = conflict.getSubscriber()
self.failUnless(subscriber.getSubscriptionUrl()==self.subscription_url1) self.failUnless(subscriber.getSubscriptionUrl()==self.subscription_url1)
def testGetPublisherAndSubscriberDocument(self, quiet=0, run=1):
# We will try to generate a conflict and then to get it
# We will also make sure it contains what we want
if not run: return
if not quiet:
ZopeTestCase._print('\nTest Get Publisher And Subscriber Document ')
LOG('Testing... ',0,'testGetPublisherAndSubscriberDocument')
self.testGetConflictList(quiet=1,run=1)
# First we do only modification on server
portal_sync = self.getSynchronizationTool()
person_server = self.getPersonServer()
person1_s = person_server._getOb(self.id1)
person_client1 = self.getPersonClient1()
person1_c = person_client1._getOb(self.id1)
conflict_list = portal_sync.getConflictList()
conflict = conflict_list[0]
publisher_document = conflict.getPublisherDocument()
self.failUnless(publisher_document.getDescription()==self.description2)
subscriber_document = conflict.getSubscriberDocument()
self.failUnless(subscriber_document.getDescription()==self.description3)
def testApplyPublisherValue(self, quiet=0, run=run_all_test): def testApplyPublisherValue(self, quiet=0, run=run_all_test):
# We will try to generate a conflict and then to get it # We will try to generate a conflict and then to get it
# We will also make sure it contains what we want # We will also make sure it contains what we want
......
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