Skip to content

Commit

Permalink
Merge pull request #69 from sanjiva/master
Browse files Browse the repository at this point in the history
Make test driver self service for media folks
  • Loading branch information
sanjiva committed Nov 2, 2019
2 parents 9a77f55 + e131779 commit edc2b35
Show file tree
Hide file tree
Showing 7 changed files with 20,789 additions and 185 deletions.
8 changes: 6 additions & 2 deletions distributor/src/distributor/results.bal
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ function publishResultData(Result result) {
worker jsonWorker returns error? {
websub:WebSubHub wh = <websub:WebSubHub> hub; // safe .. working around type guard limitation

// push it out
var r = wh.publishUpdate(JSON_RESULTS_TOPIC, result.jsonResult, mime:APPLICATION_JSON);
// push it out with the election code and the json result as the message
json resultAll = {
election_code : result.election,
result : result.jsonResult
};
var r = wh.publishUpdate(JSON_RESULTS_TOPIC, resultAll, mime:APPLICATION_JSON);
if r is error {
log:printError("Error publishing update: ", r);
}
Expand Down
3 changes: 1 addition & 2 deletions distributor/src/distributor/website.bal
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ballerina/mime;
import ballerina/time;
import ballerina/xmlutils;
import ballerina/file;
import ballerina/io;

const LEVEL_PD = "POLLING-DIVISION";
const LEVEL_ED = "ELECTORAL-DISTRICT";
Expand Down Expand Up @@ -72,6 +71,7 @@ service mediaWebsite on mediaListener {
body = body + "<p/>";
body = body + "<p>All results released so far as single JSON value: "
+ "<a href='/allresults'>All Results</a>";
body = body + "<p>Another test run? <a href='http://resultstest.ecdev.opensource.lk:9999/start'>Start</a></p>";
body = body + "<p>Read subscriber startup message: <a href='info'>Here</a></p>";
body = body + "</body>";
string doc = "<html>" + head + body + "</html>";
Expand Down Expand Up @@ -173,7 +173,6 @@ service mediaWebsite on mediaListener {
methods: ["GET"]
}
resource function isactive(http:Caller caller, http:Request request, string versionNo) returns error? {
io:println("looking for :web/active-" + <@untainted> versionNo + ": = ", file:exists("web/active-" + <@untainted> versionNo));
if file:exists("web/active-" + <@untainted> versionNo) {
return caller->ok("Still good");
} else {
Expand Down
11 changes: 7 additions & 4 deletions subscriber/src/subscriber/save.bal
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ const LEVEL_NI = "NATIONAL-INCREMENTAL";
const LEVEL_NF = "NATIONAL-FINAL";


function saveResult(map<json> result) {
string fileBase = getFileNameBase(result);
function saveResult(map<json> resultAll) {
string electionCode = resultAll.election_code.toString();
map<json> result = <map<json>> resultAll?.result;

string fileBase = getFileNameBase(electionCode, result);
if wantJson {
string jsonfile = fileBase + ".json";
error? e = writeJson(jsonfile, result);
Expand Down Expand Up @@ -54,9 +57,9 @@ function saveResult(map<json> result) {
# {ext} Either “json” or “xml” depending on the format of the file.
#
# + return - returns the base name for the file
function getFileNameBase(map<json> result) returns string {
function getFileNameBase(string electionCode, map<json> result) returns string {
// start with sequence # and type code
string name = result.sequence_number.toString() + "-" +
string name = electionCode + "-" + result.sequence_number.toString() + "-" +
(result.'type.toString() == PRESIDENTIAL_RESULT ? "PE1" : "PE2") + "-";

string resultLevel = result.level.toString();
Expand Down
Loading

0 comments on commit edc2b35

Please sign in to comment.