Commit 5c2697c3 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_maileva_connector: small improvement

1. don't manipulate data base to avoid resend to web service in case of data base conflict
2. use existing property
3. change alarm frequency
parent 7040de85
Pipeline #19627 failed with stage
in 0 seconds
...@@ -50,44 +50,35 @@ class MailevaSOAPConnector(XMLObject): ...@@ -50,44 +50,35 @@ class MailevaSOAPConnector(XMLObject):
, PropertySheet.XMLObject , PropertySheet.XMLObject
, PropertySheet.CategoryCore , PropertySheet.CategoryCore
) )
def submitRequest(self, recipient_url="", sender_url="", document_url="", track_id=""): def processResponse(self, response, maileva_exchange, failed=False):
portal = self.getPortalObject() maileva_exchange.edit(
recipient = portal.restrictedTraverse(recipient_url) response = response
sender = portal.restrictedTraverse(sender_url)
document = portal.restrictedTraverse(document_url)
request_xml = self.generateRequestXML(recipient, sender, document, track_id)
authenticated = HttpAuthenticated(username=self.getUserId(), password=self.getPassword())
maileva_exchange = portal.system_event_module.newContent(
portal_type='Maileva Exchange',
source_value = sender,
destination_value = recipient,
resource_value = self,
follow_up_value = document,
reference=track_id,
request = request_xml
) )
maileva_exchange.confirm()
# change state, no need to wait alarm check
if failed:
maileva_exchange.acknowledge()
maileva_exchange.getFollowUpValue().fail()
def submitRequest(self, maileva_exchange):
authenticated = HttpAuthenticated(username=self.getUserId(), password=self.getPassword())
runtime_environment = self.getActivityRuntimeEnvironment() runtime_environment = self.getActivityRuntimeEnvironment()
if runtime_environment: if runtime_environment:
runtime_environment.edit( runtime_environment.edit(
conflict_retry=False, conflict_retry=False,
max_retry=0) max_retry=0)
try: try:
response = suds.client.Client(url = self.getProperty('submit_url_string'), transport=authenticated).service.submit(__inject={'msg': request_xml}) response = suds.client.Client(url = self.getProperty('submit_url_string'), transport=authenticated).service.submit(__inject={'msg': maileva_exchange.getRequest()})
maileva_exchange.activate().MailevaExchange_processResponse(response)
except socket.error, e: except socket.error, e:
if e.errno == socket.errno.ECONNREFUSED: if e.errno == socket.errno.ECONNREFUSED:
if runtime_environment: if runtime_environment:
runtime_environment.edit(max_retry=None) runtime_environment.edit(max_retry=None)
raise e
except Exception, e: except Exception, e:
maileva_exchange.edit(response = str(e)) maileva_exchange.activate().MailevaExchange_processResponse(str(e), failed = True)
maileva_exchange.confirm()
maileva_exchange.acknowledge()
document.fail()
return maileva_exchange
maileva_exchange.edit(response = response)
maileva_exchange.confirm()
return maileva_exchange
def checkPendingNotifications(self): def checkPendingNotifications(self):
authenticated = HttpAuthenticated(username=self.getUserId(), password=self.getPassword()) authenticated = HttpAuthenticated(username=self.getUserId(), password=self.getPassword())
...@@ -116,7 +107,7 @@ class MailevaSOAPConnector(XMLObject): ...@@ -116,7 +107,7 @@ class MailevaSOAPConnector(XMLObject):
address_line = entity.getDefaultAddressText() address_line = entity.getDefaultAddressText()
portal_type = entity.getPortalType() portal_type = entity.getPortalType()
if portal_type == 'Person': if portal_type == 'Person':
address_line_list.append("%s %s" % (entity.getSocialTitleTitle(), entity.getTitle())) address_line_list.append("%s" % ' '.join([x for x in [entity.getSocialTitleTitle(), entity.getTitle()] if x]))
else: else:
address_line_list.append("%s" % entity.getCorporateName()) address_line_list.append("%s" % entity.getCorporateName())
......
...@@ -37,11 +37,13 @@ ...@@ -37,11 +37,13 @@
<item> <item>
<key> <string>periodicity_minute</string> </key> <key> <string>periodicity_minute</string> </key>
<value> <value>
<tuple> <tuple/>
<int>15</int>
</tuple>
</value> </value>
</item> </item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value> <int>30</int> </value>
</item>
<item> <item>
<key> <string>periodicity_month</string> </key> <key> <string>periodicity_month</string> </key>
<value> <value>
...@@ -66,7 +68,7 @@ ...@@ -66,7 +68,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1640998860.0</float> <float>1640995200.0</float>
<string>GMT</string> <string>GMT</string>
</tuple> </tuple>
</state> </state>
...@@ -149,7 +151,7 @@ ...@@ -149,7 +151,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>997.37156.13400.7065</string> </value> <value> <string>998.1956.58639.53486</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -167,7 +169,7 @@ ...@@ -167,7 +169,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1642410502.25</float> <float>1644230881.1</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<item>Amount</item> <item>Amount</item>
<item>Arrow</item> <item>Arrow</item>
<item>Event</item> <item>Event</item>
<item>HttpExchange</item>
</portal_type> </portal_type>
<portal_type id="Maileva SOAP Connector"> <portal_type id="Maileva SOAP Connector">
<item>Login</item> <item>Login</item>
......
connector = context.getResourceValue()
connector.processResponse(response, context.getObject(), failed)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>response, failed=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MailevaExchange_processResponse</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MailevaExchange_submitMailevaRequest</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -12,12 +12,23 @@ number = str(portal.portal_ids.generateNewId( ...@@ -12,12 +12,23 @@ number = str(portal.portal_ids.generateNewId(
id_generator='uid')).zfill(6) id_generator='uid')).zfill(6)
reference="maileva-%s-%s" % (today, number) reference="maileva-%s-%s" % (today, number)
xml = maileva_connector.generateRequestXML(
recipient = recipient,
sender =sender,
document=context,
track_id=reference
)
maileva_connector.activate().submitRequest( maileva_exchange = context.system_event_module.newContent(
recipient_url = recipient.getRelativeUrl(), portal_type='Maileva Exchange',
sender_url = sender.getRelativeUrl(), source_value = sender,
document_url = context.getRelativeUrl(), destination_value = recipient,
track_id = reference resource_value = maileva_connector,
follow_up_value = context,
reference=reference,
request = xml
) )
maileva_exchange.activate().MailevaExchange_submitMailevaRequest()
context.send() context.send()
...@@ -205,6 +205,9 @@ class testMailevaSOAPConnector(ERP5TypeTestCase): ...@@ -205,6 +205,9 @@ class testMailevaSOAPConnector(ERP5TypeTestCase):
self.sender = sender self.sender = sender
self.recipient = recipient self.recipient = recipient
self.document = document self.document = document
# Reset class varaible to simulate properly web service behavior
ServiceWithSuccess.get_notification_detail = False
ServiceWithFailure.get_notification_detail = False
self.tic() self.tic()
def getTitle(self): def getTitle(self):
...@@ -227,8 +230,8 @@ class testMailevaSOAPConnector(ERP5TypeTestCase): ...@@ -227,8 +230,8 @@ class testMailevaSOAPConnector(ERP5TypeTestCase):
self.assertEqual(event.getDestinationValue(), self.recipient) self.assertEqual(event.getDestinationValue(), self.recipient)
self.assertEqual(event.getFollowUpValue(), self.document) self.assertEqual(event.getFollowUpValue(), self.document)
self.assertEqual(self.document.getSendState(), 'sending') self.assertEqual(self.document.getSendState(), 'sending')
self.assertNotEqual(event.getProperty('request', ''), None) self.assertNotEqual(event.getRequest(), None)
self.assertEqual(event.getProperty('response', ''), 'success') self.assertEqual(event.getResponse(), 'success')
self.tic() self.tic()
# check response # check response
event.setReference('test_tracking_id') event.setReference('test_tracking_id')
...@@ -263,8 +266,8 @@ class testMailevaSOAPConnector(ERP5TypeTestCase): ...@@ -263,8 +266,8 @@ class testMailevaSOAPConnector(ERP5TypeTestCase):
self.assertEqual(event.getDestinationValue(), self.recipient) self.assertEqual(event.getDestinationValue(), self.recipient)
self.assertEqual(event.getFollowUpValue(), self.document) self.assertEqual(event.getFollowUpValue(), self.document)
self.assertEqual(self.document.getSendState(), 'sending') self.assertEqual(self.document.getSendState(), 'sending')
self.assertNotEqual(event.getProperty('request', ''), None) self.assertNotEqual(event.getRequest(), None)
self.assertEqual(event.getProperty('response', ''), 'success') self.assertEqual(event.getResponse(), 'success')
self.tic() self.tic()
# check response # check response
event.setReference('test_tracking_id') event.setReference('test_tracking_id')
...@@ -301,8 +304,8 @@ class testMailevaSOAPConnector(ERP5TypeTestCase): ...@@ -301,8 +304,8 @@ class testMailevaSOAPConnector(ERP5TypeTestCase):
self.assertEqual(event.getDestinationValue(), self.recipient) self.assertEqual(event.getDestinationValue(), self.recipient)
self.assertEqual(event.getFollowUpValue(), self.document) self.assertEqual(event.getFollowUpValue(), self.document)
self.assertEqual(self.document.getSendState(), 'failed') self.assertEqual(self.document.getSendState(), 'failed')
self.assertNotEqual(event.getProperty('request', ''), None) self.assertNotEqual(event.getRequest(), None)
self.assertTrue('exception' in event.getProperty('response', '')) self.assertTrue('exception' in event.getResponse())
self.tic() self.tic()
def test_maileva_xml(self): def test_maileva_xml(self):
......
Maileva Exchange | Amount Maileva Exchange | Amount
Maileva Exchange | Arrow Maileva Exchange | Arrow
Maileva Exchange | Event Maileva Exchange | Event
Maileva Exchange | HttpExchange
Maileva SOAP Connector | Login Maileva SOAP Connector | Login
Maileva SOAP Connector | Reference Maileva SOAP Connector | Reference
Maileva SOAP Connector | Url Maileva SOAP Connector | Url
\ No newline at end of file
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