Skip to content

Commit

Permalink
Fix formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Shan1024 committed Nov 16, 2019
1 parent 2dce7ab commit 43328e0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
12 changes: 6 additions & 6 deletions subscriber/src/subscriber/genhtml.bal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ballerina/time;
import ballerina/math;
import ballerina/lang.'string;
import ballerina/math;
import ballerina/time;

map<string> electionCode2Name = {
"2019PRE": "PRESIDENTIAL ELECTION - 16/11/2019",
Expand All @@ -22,7 +22,7 @@ map<string> electionCode2Name = {
"2015-PRE-REPLAY-015": "PRESIDENTIAL ELECTION - 08/01/2015 RESULT REPLAY"
};

function generateHtml (string electionCode, map<json> result, boolean sorted) returns string|error {
function generateHtml(string electionCode, map<json> result, boolean sorted) returns string|error {
string electionName = electionCode2Name[electionCode] ?: "Presidential Election - TEST";
string timeNow = check time:format(time:currentTime(), "yyyy-MM-dd'T'HH:mm:ss.SSSZ");
string head = "<head>";
Expand Down Expand Up @@ -71,15 +71,15 @@ function generateHtml (string electionCode, map<json> result, boolean sorted) re
return "<html>" + head + body + "</html>";
}

function sortPartyResults (json[] unsorted) returns json[] {
function sortPartyResults(json[] unsorted) returns json[] {
return unsorted.sort(function (json r1, json r2) returns int {
int n1 = <int>r1.votes;
int n2 = <int>r2.votes;
return (n1 < n2) ? 1 : (n1 == n2 ? 0 : -1);
});
}

function commaFormatInt (int n) returns string {
function commaFormatInt(int n) returns string {
string minus = n < 0 ? "-" : "";
int num = math:absInt(n);
string numStr = num.toString();
Expand All @@ -92,6 +92,6 @@ function commaFormatInt (int n) returns string {
if numStr.length() > 0 {
parts.unshift(numStr);
}
string res = 'string:'join(",", ... parts);
string res = 'string:'join(",", ...parts);
return minus + res;
}
2 changes: 1 addition & 1 deletion subscriber/src/subscriber/save.bal
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ballerina/http;
import ballerina/io;
import ballerina/log;
import ballerina/xmlutils;
import ballerina/stringutils as su;
import ballerina/xmlutils;

const PRESIDENTIAL_RESULT = "PRESIDENTIAL-FIRST";
const LEVEL_PD = "POLLING-DIVISION";
Expand Down
39 changes: 19 additions & 20 deletions subscriber/src/subscriber/subscriber.bal
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,38 @@ http:OutboundAuthConfig? auth = ();
http:Client? imageClient = ();

// what formats does the user want results saved in?
public function main (string secret, // secret to send to the hub
string? username = (), // my username
string? password = (), // my password
boolean await = false, // do I want the await results notification?
boolean 'json = false, // do I want json?
boolean 'xml = false, // do I want xml?
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
public function main(string secret, // secret to send to the hub
string? username = (), // my username
string? password = (), // my password
boolean await = false, // do I want the await results notification?
boolean 'json = false, // do I want json?
boolean 'xml = false, // do I want xml?
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
) returns error? {
subscriberSecret = <@untainted> secret;
subscriberPublicUrl = <@untainted> (myURL == "" ? string `http://localhost:${port}` : myURL);
subscriberPort = <@untainted> port;
hub = <@untainted> homeURL + "/websub/hub";

// check what format the user wants results in
wantJson = <@untainted>'json;
wantXml = <@untainted>'xml;
wantHtml = <@untainted>html;
wantJson = <@untainted> 'json;
wantXml = <@untainted> 'xml;
wantHtml = <@untainted> html;
if !(wantJson || wantXml || wantHtml) {
// default to giving json
wantJson = true;
}
sortedHtml = <@untainted>sorted;
sortedHtml = <@untainted> sorted;

// set up auth
if (username is string && password is string) {
auth:OutboundBasicAuthProvider outboundBasicAuthProvider = new ({
auth:OutboundBasicAuthProvider outboundBasicAuthProvider = new({
username: <@untainted> username,
password: <@untainted> password
});
Expand Down Expand Up @@ -154,7 +154,6 @@ public function main (string secret, // secret to send to the hub
error? pingStatus = ping:ping();
if !(pingStatus is ()) {
log:printError("Error pinging on await notification", pingStatus);

}
} else {
log:printError("Expected text payload, received:" + textPayload.toString());
Expand All @@ -165,7 +164,7 @@ public function main (string secret, // secret to send to the hub
}

if image {
imageClient = <@untainted> new (homeURL, {auth: auth});
imageClient = <@untainted> new(homeURL, {auth: auth});

// attach the image subscriber
service imageSubscriberService = @websub:SubscriberServiceConfig {
Expand Down

0 comments on commit 43328e0

Please sign in to comment.