From f1208adf302222455a423f41433bd58142b8c2df Mon Sep 17 00:00:00 2001 From: Sanjiva Weerawarana Date: Fri, 15 Nov 2019 15:43:31 +0530 Subject: [PATCH 1/2] Made prepending electionCode to filenames optional --- subscriber/src/subscriber/save.bal | 2 +- subscriber/src/subscriber/subscriber.bal | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/subscriber/src/subscriber/save.bal b/subscriber/src/subscriber/save.bal index 30b346d..43ed571 100644 --- a/subscriber/src/subscriber/save.bal +++ b/subscriber/src/subscriber/save.bal @@ -105,7 +105,7 @@ function saveImagePdf(map imageJson) { # + return - returns the base name for the file function getFileNameBase(string electionCode, map result) returns string { // start with sequence # and type code - string name = electionCode + "-" + result.sequence_number.toString() + "-" + + string name = (wantCode ? electionCode + "-" : "") + result.sequence_number.toString() + "-" + (result.'type.toString() == PRESIDENTIAL_RESULT ? "PE1" : "PE2") + "-"; string resultLevel = result.level.toString(); diff --git a/subscriber/src/subscriber/subscriber.bal b/subscriber/src/subscriber/subscriber.bal index 38ddb80..5ba83d2 100644 --- a/subscriber/src/subscriber/subscriber.bal +++ b/subscriber/src/subscriber/subscriber.bal @@ -39,6 +39,8 @@ boolean wantXml = false; boolean wantHtml = false; boolean sortedHtml = false; +boolean wantCode = false; + http:OutboundAuthConfig? auth = (); http:Client? imageClient = (); @@ -52,6 +54,7 @@ public function main (string secret, // secret to send to the hub boolean image = false, // do I want the image? boolean html = false, // do I want HTML? boolean sorted = true, // do I want HTML results sorted highest to lowest + boolean wantCode = false, // do I want electionCode in the filename string homeURL = "https://resultstest.ecdev.opensource.lk", // where do I subscribe at int port = 1111, // port I'm going to open string myURL = "" // how to reach me over the internet From f29856fb114054bec79a29511efd6bc2f597d1f2 Mon Sep 17 00:00:00 2001 From: Sanjiva Weerawarana Date: Sat, 16 Nov 2019 08:53:04 +0530 Subject: [PATCH 2/2] Added log for SMS sending (distributor) and also corrected test driver notification call --- distributor/src/distributor/messenger.bal | 1 + testdriver/src/testdriver/sendresults.bal | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/distributor/src/distributor/messenger.bal b/distributor/src/distributor/messenger.bal index 0d3c802..b0e43e1 100644 --- a/distributor/src/distributor/messenger.bal +++ b/distributor/src/distributor/messenger.bal @@ -53,6 +53,7 @@ function sendSMS(string message, string resultId) { log:printInfo("Sending SMS for " + resultId); } foreach string targetMobile in currentMobileSubscribers { + log:printInfo("Sending SMS for " + resultId + " to " + targetMobile); var response = twilioClient->sendSms(sourceMobile, targetMobile, message); if response is error { log:printError("Message sending failed for \'" + targetMobile + "\' due to error:" + diff --git a/testdriver/src/testdriver/sendresults.bal b/testdriver/src/testdriver/sendresults.bal index 2a45904..0045a76 100644 --- a/testdriver/src/testdriver/sendresults.bal +++ b/testdriver/src/testdriver/sendresults.bal @@ -302,16 +302,16 @@ function sendResult (http:Client hc, string electionCode, string resType, string http:Response hr; // sent alert - string params = "?level=" + result.level; + string params = "/?level=" + result.level; if result.ed_name is string { params += "&ed_name=" + check encoding:encodeUriComponent(result.ed_name, "UTF-8"); if result.pd_name is string { params += "&pd_name=" + check encoding:encodeUriComponent(result.pd_name, "UTF-8"); } } - hr = check hc->post ("/result/notification/" + electionCode + "/" + resType + "/" + resCode + "/?level=" + result.level, {}); + hr = check hc->post ("/result/notification/" + electionCode + "/" + resType + "/" + resCode + params, {}); if hr.statusCode != http:STATUS_ACCEPTED { - io:println("Error while posting result notification to: /result/notification/" + electionCode + "/" + resType + "/" + resCode); + io:println("Error while posting result notification to: /result/notification/" + electionCode + "/" + resType + "/" + resCode + params); io:println("\tstatus=", hr.statusCode, ", contentType=", hr.getContentType(), " payload=", hr.getTextPayload()); return error ("Unable to post notification for " + resCode); }