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):
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
)
def submitRequest(self, recipient_url="", sender_url="", document_url="", track_id=""):
portal = self.getPortalObject()
recipient = portal.restrictedTraverse(recipient_url)
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
def processResponse(self, response, maileva_exchange, failed=False):
maileva_exchange.edit(
response = response
)
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()
if runtime_environment:
runtime_environment.edit(
conflict_retry=False,
max_retry=0)
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:
if e.errno == socket.errno.ECONNREFUSED:
if runtime_environment:
runtime_environment.edit(max_retry=None)
raise e
except Exception, e:
maileva_exchange.edit(response = str(e))
maileva_exchange.confirm()
maileva_exchange.acknowledge()
document.fail()
return maileva_exchange
maileva_exchange.activate().MailevaExchange_processResponse(str(e), failed = True)
maileva_exchange.edit(response = response)
maileva_exchange.confirm()
return maileva_exchange
def checkPendingNotifications(self):
authenticated = HttpAuthenticated(username=self.getUserId(), password=self.getPassword())
......@@ -116,7 +107,7 @@ class MailevaSOAPConnector(XMLObject):
address_line = entity.getDefaultAddressText()
portal_type = entity.getPortalType()
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:
address_line_list.append("%s" % entity.getCorporateName())
......
......@@ -37,11 +37,13 @@
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple>
<int>15</int>
</tuple>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value> <int>30</int> </value>
</item>
<item>
<key> <string>periodicity_month</string> </key>
<value>
......@@ -66,7 +68,7 @@
</tuple>
<state>
<tuple>
<float>1640998860.0</float>
<float>1640995200.0</float>
<string>GMT</string>
</tuple>
</state>
......@@ -149,7 +151,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>997.37156.13400.7065</string> </value>
<value> <string>998.1956.58639.53486</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -167,7 +169,7 @@
</tuple>
<state>
<tuple>
<float>1642410502.25</float>
<float>1644230881.1</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -3,6 +3,7 @@
<item>Amount</item>
<item>Arrow</item>
<item>Event</item>
<item>HttpExchange</item>
</portal_type>
<portal_type id="Maileva SOAP Connector">
<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(
id_generator='uid')).zfill(6)
reference="maileva-%s-%s" % (today, number)
xml = maileva_connector.generateRequestXML(
recipient = recipient,
sender =sender,
document=context,
track_id=reference
)
maileva_connector.activate().submitRequest(
recipient_url = recipient.getRelativeUrl(),
sender_url = sender.getRelativeUrl(),
document_url = context.getRelativeUrl(),
track_id = reference
maileva_exchange = context.system_event_module.newContent(
portal_type='Maileva Exchange',
source_value = sender,
destination_value = recipient,
resource_value = maileva_connector,
follow_up_value = context,
reference=reference,
request = xml
)
maileva_exchange.activate().MailevaExchange_submitMailevaRequest()
context.send()
......@@ -205,6 +205,9 @@ class testMailevaSOAPConnector(ERP5TypeTestCase):
self.sender = sender
self.recipient = recipient
self.document = document
# Reset class varaible to simulate properly web service behavior
ServiceWithSuccess.get_notification_detail = False
ServiceWithFailure.get_notification_detail = False
self.tic()
def getTitle(self):
......@@ -227,8 +230,8 @@ class testMailevaSOAPConnector(ERP5TypeTestCase):
self.assertEqual(event.getDestinationValue(), self.recipient)
self.assertEqual(event.getFollowUpValue(), self.document)
self.assertEqual(self.document.getSendState(), 'sending')
self.assertNotEqual(event.getProperty('request', ''), None)
self.assertEqual(event.getProperty('response', ''), 'success')
self.assertNotEqual(event.getRequest(), None)
self.assertEqual(event.getResponse(), 'success')
self.tic()
# check response
event.setReference('test_tracking_id')
......@@ -263,8 +266,8 @@ class testMailevaSOAPConnector(ERP5TypeTestCase):
self.assertEqual(event.getDestinationValue(), self.recipient)
self.assertEqual(event.getFollowUpValue(), self.document)
self.assertEqual(self.document.getSendState(), 'sending')
self.assertNotEqual(event.getProperty('request', ''), None)
self.assertEqual(event.getProperty('response', ''), 'success')
self.assertNotEqual(event.getRequest(), None)
self.assertEqual(event.getResponse(), 'success')
self.tic()
# check response
event.setReference('test_tracking_id')
......@@ -301,8 +304,8 @@ class testMailevaSOAPConnector(ERP5TypeTestCase):
self.assertEqual(event.getDestinationValue(), self.recipient)
self.assertEqual(event.getFollowUpValue(), self.document)
self.assertEqual(self.document.getSendState(), 'failed')
self.assertNotEqual(event.getProperty('request', ''), None)
self.assertTrue('exception' in event.getProperty('response', ''))
self.assertNotEqual(event.getRequest(), None)
self.assertTrue('exception' in event.getResponse())
self.tic()
def test_maileva_xml(self):
......
Maileva Exchange | Amount
Maileva Exchange | Arrow
Maileva Exchange | Event
Maileva Exchange | HttpExchange
Maileva SOAP Connector | Login
Maileva SOAP Connector | Reference
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