Commit 46698e31 authored by Sebastien Robin's avatar Sebastien Robin

put back the use of 4Suite, more use of xpath, add flow type in order to allow...

put back the use of 4Suite, more use of xpath, add flow type in order to allow to synchronise with simple text

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14655 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 64a2b761
This diff is collapsed.
......@@ -153,8 +153,9 @@ class Publication(Subscription):
# Constructor
def __init__(self, id, title, publication_url, destination_path,
query, xml_mapping, conduit, gpg_key, auth_required=False,
authentication_format='', authentication_type=''):
query, xml_mapping, conduit, gpg_key, id_generator, gid_generator,
flow_type, auth_required=False, authentication_format='',
authentication_type=''):
"""
constructor
"""
......@@ -166,8 +167,9 @@ class Publication(Subscription):
#self.list_subscribers = PersistentMapping()
self.domain_type = self.PUB
self.gpg_key = gpg_key
self.setGidGenerator(None)
self.setIdGenerator(None)
self.setGidGenerator(gid_generator)
self.setFlowType(flow_type)
self.setSynchronizationIdGenerator(id_generator)
self.setConduit(conduit)
Folder.__init__(self, id)
self.title = title
......
......@@ -29,8 +29,7 @@
import smtplib # to send emails
from Publication import Publication,Subscriber
from Subscription import Signature
from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml
from xml.dom.minidom import parse, parseString
from Ft.Xml import Parse
from XMLSyncUtils import XMLSyncUtils
from Conduit.ERP5Conduit import ERP5Conduit
from Products.CMFCore.utils import getToolByName
......@@ -142,6 +141,13 @@ class PublicationSynchronization(XMLSyncUtils):
xml(' <SyncBody>\n')
xml(self.SyncMLStatus(cmd_id, subscriber.getSubscriptionUrl(),
publication.getPublicationUrl(), auth_code))
cmd_id += 1
if auth_code == self.AUTH_ACCEPTED:
# alert message
xml(self.SyncMLAlert(cmd_id, sync_type,
subscriber.getSubscriptionUrl(), publication.getPublicationUrl(),
subscriber.getLastAnchor(), subscriber.getNextAnchor()))
cmd_id += 1
xml(' </SyncBody>\n')
xml('</SyncML>\n')
xml_a = ''.join(xml_list)
......@@ -221,7 +227,7 @@ class PublicationSynchronization(XMLSyncUtils):
if xml_client is not None:
if isinstance(xml_client, str) or isinstance(xml_client, unicode):
xml_client = parseString(xml_client)
xml_client = Parse(xml_client)
first_node = xml_client.childNodes[0]
if first_node.nodeName != "SyncML":
......
......@@ -642,8 +642,9 @@ class Subscription(Folder, SyncCode):
)
# Constructor
def __init__(self, id, title, publication_url, subscription_url, destination_path, query, xml_mapping, conduit, gpg_key, login, password,
authentication_format='', authentication_type=''):
def __init__(self, id, title, publication_url, subscription_url,
destination_path, query, xml_mapping, conduit, gpg_key, id_generator,
gid_generator, flow_type, login, password):
"""
We need to create a dictionnary of
signatures of documents which belong to the synchronisation
......@@ -660,14 +661,13 @@ class Subscription(Folder, SyncCode):
#self.signatures = PersistentMapping()
self.last_anchor = '00000000T000000Z'
self.next_anchor = '00000000T000000Z'
self.login=login
self.flow_type = flow_type
self.login = login
self.password=password
self.authentication_format=authentication_format
self.authentication_type=authentication_type
self.domain_type = self.SUB
self.gpg_key = gpg_key
self.setGidGenerator(None)
self.setIdGenerator(None)
self.setGidGenerator(gid_generator)
self.setSynchronizationIdGenerator(id_generator)
self.setConduit(conduit)
Folder.__init__(self, id)
self.title = title
......@@ -715,7 +715,7 @@ class Subscription(Folder, SyncCode):
def setXMLMapping(self, value):
"""
this the name of the method used in order to get the xml
this the name of the method used in order to set the xml
"""
if value == '':
value = None
......@@ -884,6 +884,20 @@ class Subscription(Folder, SyncCode):
"""
return self.gid_generator
def getFlowType(self):
"""
This method return the type of the data within the xml message :
- text for VCard's
- xml for others
"""
return getattr(self, 'flow_type', 'xml')
def setFlowType(self, flow_type):
"""
set the flow type (xml or text)
"""
self.flow_type=flow_type
def getLogin(self):
"""
This method return the login of this subscription
......@@ -954,7 +968,7 @@ class Subscription(Folder, SyncCode):
# It might be a script python
generator = getattr(object,gid_gen)
o_gid = generator() # XXX - used to be o_gid = generator(object=object) which is redundant
# LOG('getGidFromObject',0,'o_gid: %s' % repr(o_gid))
LOG('getGidFromObject',0,'o_gid: %s' % repr(o_gid))
return o_gid
def getObjectFromGid(self, gid):
......@@ -1018,10 +1032,7 @@ class Subscription(Folder, SyncCode):
"""
This tries to generate a new Id
"""
# LOG('generateNewId, object: ',0,object.getPhysicalPath())
id_generator = self.getIdGenerator()
# LOG('generateNewId, id_generator: ',0,id_generator)
# LOG('generateNewId, portal_object: ',0,object.getPortalObject())
id_generator = self.getSynchronizationIdGenerator()
if id_generator is not None:
o_base = aq_base(object)
new_id = None
......@@ -1038,20 +1049,20 @@ class Subscription(Folder, SyncCode):
return new_id
return None
def setIdGenerator(self, method):
def setSynchronizationIdGenerator(self, method):
"""
This set the method name wich allows to generate
a new id
"""
if method in ('','None'):
method = None
self.id_generator = method
self.synchronization_id_generator = method
def getIdGenerator(self):
def getSynchronizationIdGenerator(self):
"""
This get the method name wich allows to generate a new id
"""
return self.id_generator
return getattr(self, 'synchronization_id_generator', None)
def getSubscriptionUrl(self):
"""
......@@ -1185,7 +1196,7 @@ class Subscription(Folder, SyncCode):
"""
if signature.getGid() in self.objectIds():
self._delObject(signature.getGid())
self._setObject( signature.getGid(), aq_base(signature) )
self._setObject(signature.getGid(), aq_base(signature) )
def delSignature(self, gid):
"""
......@@ -1321,7 +1332,7 @@ class Subscription(Folder, SyncCode):
#elif format is .... put here the other formats
else:#if there is no format corresponding with format, raise an error
LOG('encode : unknown or not implemented format :', 0, format)
raise ValueError, "Sorry, the format %s is unknow or not implemented" % format
raise ValueError, "Sorry, the server ask for the format %s but it's unknow or not implemented" % format
def decode(self, format, string_to_decode):
"""
......
......@@ -28,9 +28,7 @@
import smtplib # to send emails
from Subscription import Subscription,Signature
from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml
from xml.dom.minidom import parse, parseString
from xml.dom.ext import PrettyPrint
from Ft.Xml import Parse
from XMLSyncUtils import XMLSyncUtils
import commands
from Conduit.ERP5Conduit import ERP5Conduit
......@@ -99,13 +97,21 @@ class SubscriptionSynchronization(XMLSyncUtils):
else:
xml_client = msg
if isinstance(xml_client, str) or isinstance(xml_client, unicode):
xml_client = parseString(xml_client)
xml_client = Parse(xml_client)
next_status = self.getNextSyncBodyStatus(xml_client, None)
#LOG('readResponse, next status :',0,next_status)
if next_status is not None:
status_code = self.getStatusCode(next_status)
#LOG('readResponse status code :',0,status_code)
if status_code == self.AUTH_REQUIRED:
if self.checkChal(xml_client):
authentication_format, authentication_type = self.getChal(xml_client)
subscription.setAuthenticationFormat(authentication_format)
subscription.setAuthenticationType(authentication_type)
else:
raise ValueError, "Sorry, the server chalenge for an \
authentication, but the authentication format is not find"
#LOG('readResponse', 0, 'Authentication required')
response = self.SubSyncCred(id, xml_client)
elif status_code == self.UNAUTHORIZED:
......
......@@ -40,8 +40,7 @@ from Products.ERP5SyncML import Conduit
from Publication import Publication,Subscriber
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
from Subscription import Subscription,Signature
from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXml
from xml.dom.minidom import parse, parseString
from Ft.Xml import Parse
from Products.ERP5Type import Permissions
from PublicationSynchronization import PublicationSynchronization
from SubscriptionSynchronization import SubscriptionSynchronization
......@@ -50,7 +49,6 @@ from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
from AccessControl.User import UnrestrictedUser
from Acquisition import aq_base
from xml.parsers.expat import ExpatError # parseString error
import urllib
import urllib2
import socket
......@@ -162,9 +160,11 @@ class SynchronizationTool( SubscriptionSynchronization,
security.declareProtected(Permissions.ModifyPortalContent,
'manage_addPublication')
def manage_addPublication(self, title, publication_url, destination_path,
query, xml_mapping, conduit, gpg_key, auth_required=0,
authentication_format='', authentication_type='', RESPONSE=None):
"""
query, xml_mapping, conduit, gpg_key,
synchronization_id_generator=None, gid_generator=None,
flow_type='xml', auth_required=0, authentication_format='',
authentication_type='', RESPONSE=None):
"""
create a new publication
"""
#if not('publications' in self.objectIds()):
......@@ -173,8 +173,9 @@ class SynchronizationTool( SubscriptionSynchronization,
folder = self.getObjectContainer()
new_id = self.getPublicationIdFromTitle(title)
pub = Publication(new_id, title, publication_url, destination_path,
query, xml_mapping, conduit, gpg_key, auth_required,
authentication_format, authentication_type)
query, xml_mapping, conduit, gpg_key,
synchronization_id_generator, gid_generator, flow_type,
auth_required, authentication_format, authentication_type)
folder._setObject( new_id, pub )
#if len(self.list_publications) == 0:
# self.list_publications = PersistentMapping()
......@@ -186,8 +187,9 @@ class SynchronizationTool( SubscriptionSynchronization,
'manage_addSubscription')
def manage_addSubscription(self, title, publication_url, subscription_url,
destination_path, query, xml_mapping, conduit, gpg_key,
login=None, password=None, authentication_format='',
authentication_type='',RESPONSE=None):
synchronization_id_generator=None, gid_generator=None,
flow_type='xml', login=None, password=None,
RESPONSE=None):
"""
XXX should be renamed as addSubscription
create a new subscription
......@@ -199,8 +201,8 @@ class SynchronizationTool( SubscriptionSynchronization,
new_id = self.getSubscriptionIdFromTitle(title)
sub = Subscription(new_id, title, publication_url, subscription_url,
destination_path, query, xml_mapping, conduit, gpg_key,
login, password, authentication_format,
authentication_type)
synchronization_id_generator, gid_generator, flow_type,
login, password)
folder._setObject( new_id, sub )
#if len(self.list_subscriptions) == 0:
# self.list_subscriptions = PersistentMapping()
......@@ -211,9 +213,11 @@ class SynchronizationTool( SubscriptionSynchronization,
security.declareProtected(Permissions.ModifyPortalContent,
'manage_editPublication')
def manage_editPublication(self, title, publication_url, destination_path,
query, xml_mapping, conduit, gpg_key, id_generator,
gid_generator, auth_required=0, authentication_format='',
authentication_type='', RESPONSE=None):
query, xml_mapping, conduit, gpg_key,
synchronization_id_generator, gid_generator,
flow_type='xml', auth_required=0,
authentication_format='', authentication_type='',
RESPONSE=None):
"""
modify a publication
"""
......@@ -225,8 +229,9 @@ class SynchronizationTool( SubscriptionSynchronization,
pub.setConduit(conduit)
pub.setXMLMapping(xml_mapping)
pub.setGPGKey(gpg_key)
pub.setIdGenerator(id_generator)
pub.setSynchronizationIdGenerator(synchronization_id_generator)
pub.setGidGenerator(gid_generator)
pub.setFlowType(flow_type)
pub.setAuthentication(auth_required)
pub.setAuthenticationFormat(authentication_format)
pub.setAuthenticationType(authentication_type)
......@@ -237,9 +242,9 @@ class SynchronizationTool( SubscriptionSynchronization,
security.declareProtected(Permissions.ModifyPortalContent,
'manage_editSubscription')
def manage_editSubscription(self, title, publication_url, subscription_url,
destination_path, query, xml_mapping, conduit, gpg_key, id_generator,
gid_generator,login='', password='', authentication_format='',
authentication_type='', RESPONSE=None):
destination_path, query, xml_mapping, conduit, gpg_key,
synchronization_id_generator, gid_generator, flow_type='xml', login='',
password='', RESPONSE=None):
"""
modify a subscription
"""
......@@ -252,12 +257,11 @@ class SynchronizationTool( SubscriptionSynchronization,
sub.setXMLMapping(xml_mapping)
sub.setGPGKey(gpg_key)
sub.setSubscriptionUrl(subscription_url)
sub.setIdGenerator(id_generator)
sub.setSynchronizationIdGenerator(synchronization_id_generator)
sub.setGidGenerator(gid_generator)
sub.setFlowType(flow_type)
sub.setLogin(login)
sub.setPassword(password)
sub.setAuthenticationFormat(authentication_format)
sub.setAuthenticationType(authentication_type)
if RESPONSE is not None:
RESPONSE.redirect('manageSubscriptions')
......@@ -613,6 +617,7 @@ class SynchronizationTool( SubscriptionSynchronization,
security.declareProtected(Permissions.AccessContentsInformation,
'getSubscriberDocumentPath')
def getSubscriberDocumentPath(self, conflict):
"""
apply the publisher value for all conflict of the given document
......@@ -974,7 +979,7 @@ class SynchronizationTool( SubscriptionSynchronization,
commands.getstatusoutput('rm -f /tmp/%s.gz.gpg' % filename)
# Get the target and then find the corresponding publication or
# Subscription
xml = parseString(text)
xml = Parse(text)
#XXX this function is not very optimized and should be improved
url = self.getTarget(xml)
for publication in self.getPublicationList():
......
This diff is collapsed.
......@@ -114,7 +114,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</label></div>
</td>
<td align="left" valign="top">
<input type="text" name="id_generator" value="<dtml-var getIdGenerator>" size="40" />
<input type="text" name="synchronization_id_generator" value="<dtml-var getSynchronizationIdGenerator>" size="40" />
</td>
</tr>
<tr>
......@@ -127,6 +127,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<input type="text" name="gid_generator" value="<dtml-var getGidGenerator>" size="40" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Flow Type
</label></div>
</td>
<td align="left" valign="top">
<SELECT name="flow_type" size="1">
<dtml-if expr="getFlowType() != 'text'">
<OPTION value="xml" selected>XML</option>
<OPTION value="text">text</option>
<dtml-else>
<OPTION value="xml">XML</option>
<OPTION value="text" selected>text</option>
</dtml-if>
</SELECT>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
......
......@@ -124,7 +124,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</label></div>
</td>
<td align="left" valign="top">
<input type="text" name="id_generator" value="<dtml-var getIdGenerator>" size="40" />
<input type="text" name="synchronization_id_generator" value="<dtml-var getSynchronizationIdGenerator>" size="40" />
</td>
</tr>
<tr>
......@@ -140,41 +140,39 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<tr>
<td align="left" valign="top">
<div class="form-label">
Login
</label></div>
</td>
<td align="left" valign="top">
<input type="text" name="login" value="<dtml-var getLogin>" size="40" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Password
Flow Type
</label></div>
</td>
<td align="left" valign="top">
<input type="password" name="password" value="<dtml-var getPassword>" size="40" />
<SELECT name="flow_type" size="1">
<dtml-if expr="getFlowType() != 'text'">
<OPTION value="xml" selected>XML</option>
<OPTION value="text">text</option>
<dtml-else>
<OPTION value="xml">XML</option>
<OPTION value="text" selected>text</option>
</dtml-if>
</SELECT>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Format authentication
Login
</label></div>
</td>
<td align="left" valign="top">
<input type="text" name="authentication_format" value="<dtml-var getAuthenticationFormat>" size="40" />
<input type="text" name="login" value="<dtml-var getLogin>" size="40" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Type authentication
Password
</label></div>
</td>
<td align="left" valign="top">
<input type="text" name="authentication_type" value="<dtml-var getAuthenticationType>" size="40" />
<input type="password" name="password" value="<dtml-var getPassword>" size="40" />
</td>
</tr>
</table>
......
......@@ -110,7 +110,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</label></div>
</td>
<td align="left" valign="top">
<input type="text" name="id_generator" size="40" />
<input type="text" name="synchronization_id_generator" size="40" />
</td>
</tr>
<tr>
......@@ -123,6 +123,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<input type="text" name="gid_generator" size="40" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Flow Type
</label></div>
</td>
<td align="left" valign="top">
<SELECT name="flow_type" size="1">
<OPTION value="xml" selected>XML</option>
<OPTION value="text">text</option>
</SELECT>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
......
......@@ -120,7 +120,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</label></div>
</td>
<td align="left" valign="top">
<input type="text" name="id_generator" size="40" />
<input type="text" name="synchronization_id_generator" size="40" />
</td>
</tr>
<tr>
......@@ -136,39 +136,33 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<tr>
<td align="left" valign="top">
<div class="form-label">
Login
Flow Type
</label></div>
</td>
<td align="left" valign="top">
<input type="text" name="login" size="40" /> </td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Password
</label></div>
</td>
<td align="left" valign="top">
<input type="password" name="password" size="40" />
<SELECT name="flow_type" size="1">
<OPTION value="xml" selected>XML</option>
<OPTION value="text">text</option>
</SELECT>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Format authentication
Login
</label></div>
</td>
<td align="left" valign="top">
<input type="text" name="authentication_format" size="40" />
</td>
</tr>
<input type="text" name="login" size="40" /> </td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Type authentication
Password
</label></div>
</td>
<td align="left" valign="top">
<input type="text" name="authentication_type" size="40" />
<input type="password" name="password" size="40" />
</td>
</tr>
<tr>
......
This diff is collapsed.
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