Skip to content

Commit

Permalink
Add missing files from last check in #25
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf committed Oct 7, 2016
1 parent a72e54c commit daa90b5
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 25 deletions.
135 changes: 111 additions & 24 deletions odatareceptionist/procedures/PrintQueue.xsjslib
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ function readParticipant(_ParticipantID) {
try {
conn = $.db.getConnection();
var select = 'SELECT "ID", "EventID", "FirstName", "LastName", "Twitter"'
+ ' FROM "com.sap.sapmentors.sitreg.data::SITreg.Participant"'
+ ' FROM "com.sap.sapmentors.sitreg.odataparticipant.procedures::ParticipantsRead"'
+ ' WHERE "ID" = ?';
var pStmt = conn.prepareStatement(select);
pStmt.setInteger(1, _ParticipantID);
pStmt.setInteger(1, parseInt(_ParticipantID));
var rs = pStmt.executeQuery();
if (rs.next()) {
participant.ParticipantID = rs.getInteger(1);
Expand All @@ -17,6 +17,9 @@ function readParticipant(_ParticipantID) {
participant.LastName = rs.getNString(4);
participant.Twitter = rs.getNString(5);
}
if(!participant.Twitter) {
participant.Twitter = "";
}
rs.close();
pStmt.close();
conn.close();
Expand Down Expand Up @@ -69,36 +72,113 @@ function getDevicesForEvent(_EventID) {
} catch (e) {
$.trace.debug("Error: exception caught: <br />" + e.toString());
}
$.trace.debug("Devices: " + JSON.stringify(devices));
return devices;
}

function hasPrintQueueElementInSentStatusForEvent(_EventID) {
var conn;
var count;
try {
conn = $.db.getConnection();
var select = 'SELECT COUNT("ParticipantID") AS count '
+ 'FROM "com.sap.sapmentors.sitreg.data::SITreg.PrintQueue" '
+ 'WHERE "EventID" = ? AND "PrintStatus" = ' + "'S'";
var pStmt = conn.prepareStatement(select);
pStmt.setInteger(1, _EventID);
var rs = pStmt.executeQuery();
if (rs.next()) {
count = rs.getInteger(1);
}
pStmt.close();
} catch (e) {
$.trace.debug("Error: exception caught: <br />" + e.toString());
}
if(count > 0) {
return true;
} else {
return false;
}
}

function sendParticipantToDevice(_participant, _devices) {
var destination_package = "com.sap.sapmentors.sitreg.odatareceptionist.procedures";
var destination_name = "hcpiotmms";
var status = {};

var dest = $.net.http.readDestination(destination_package, destination_name);
var client = new $.net.http.Client();
for (var i = 0; i < _devices.length; i++) {
try {
var req = new $.web.WebRequest($.net.http.POST, _devices[i]);
req.headers.set('Content-Type', encodeURIComponent("application/json"));
var bodyJSON = {
"messageType":"e831c7faaf5cd1091161",
"messages":[
{
"timestamp": Math.round(new Date().getTime()/1000),
"ID": _participant.ParticipantID,
"EventID": _participant.EventID,
"FirstName": _participant.FirstName,
"LastName": _participant.LastName,
"Twitter": _participant.Twitter
}
],
"method":"ws","sender":"IoT App"
};
req.setBody(JSON.stringify(bodyJSON));

client.request(req, dest);
var response = client.getResponse();
status.status = response.status;
status.body = response.body.asString();
// status.DeviceID = _devices[i];
} catch (e) {
status.error = e.message;
}
}
return status;
}

function addParticipantToPrintQueue(_participant) {
var conn;
var status = {};
try {
var devices = getDevicesForEvent(_participant.EventID);
if(!isParticipantInPrintQueue(_participant.EventID)) {
conn = $.db.getConnection();
var select = 'INSERT INTO "com.sap.sapmentors.sitreg.data::SITreg.PrintQueue" '
+ 'VALUES(?, ?, ?, ?, ?, ?, '
+ 'CURRENT_USER, CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP )';
var pStmt = conn.prepareStatement(select);
pStmt.setInteger(1, _participant.ParticipantID);
pStmt.setInteger(2, _participant.EventID);
pStmt.setString(3, _participant.FirstName);
pStmt.setString(4, _participant.LastName);
if(!_participant.Twitter) {
_participant.Twitter = "";
if(devices.length > 0) {
$.trace.debug('addParticipantToPrintQueue: Devices are available');
if(!isParticipantInPrintQueue(_participant.EventID)) {
if (hasPrintQueueElementInSentStatusForEvent(_participant.EventID)) {
_participant.PrintStatus = 'Q';
} else {
_participant.PrintStatus = 'S';
}
$.trace.debug('PrintStatus: ' + _participant.PrintStatus);
conn = $.db.getConnection();
var select = 'INSERT INTO "com.sap.sapmentors.sitreg.data::SITreg.PrintQueue" '
+ 'VALUES(?, ?, ?, ?, ?, ?, '
+ 'CURRENT_USER, CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP )';
var pStmt = conn.prepareStatement(select);
pStmt.setInteger(1, _participant.ParticipantID);
pStmt.setInteger(2, _participant.EventID);
pStmt.setString(3, _participant.FirstName);
pStmt.setString(4, _participant.LastName);
pStmt.setString(5, _participant.Twitter);
pStmt.setString(6, _participant.PrintStatus);
pStmt.executeUpdate();
conn.commit();
pStmt.close();
status.toDevice = sendParticipantToDevice(_participant,devices);
if (_participant.PrintStatus === 'S') {
// Use Queueing later
}
} else {
status.error = "Entry does already exist";
}
pStmt.setString(5, _participant.Twitter);
pStmt.setString(6, _participant.PrintStatus);
pStmt.executeUpdate();
conn.commit();
pStmt.close();
conn.close();
} else {
status.error = "Entry does already exist";
status.error = "No Devices found for Event";
}
conn.close();
} catch (e) {
status.error = "Error: exception caught: <br />" + e.toString();
}
Expand All @@ -114,10 +194,17 @@ function PrintQueueUpdateAfterTicketUpdate(param){
let rs = pStmt.executeQuery();
if (rs.next()) {
var ParticipantID = rs.getNString(1);
var TicketUsed = rs.getNString(4);
var TicketUsed = rs.getNString(3);
}
$.trace.debug('ParticipantID:' + ParticipantID + 'TicketUsed: ' + TicketUsed);
if(TicketUsed === 'N' || TicketUsed === 'M') {
$.trace.debug('Call of readParticipant');
var participant = readParticipant(ParticipantID);
$.trace.debug('Participant: ' + JSON.stringify(participant));
$.trace.debug('Call of addParticipantToPrintQueue');
var status = addParticipantToPrintQueue(participant);
$.trace.debug('Status: ' + JSON.stringify(status));
}
$.trace.debug('ParticipantID:' + ParticipantID + 'TicketUsed: ' + TicketUsed);
// var participant = readParticipant(ParticipantID);
rs.close();
pStmt.close();
$.trace.debug('leave function PrintQueueUpdate');
Expand Down
2 changes: 1 addition & 1 deletion odatareceptionist/procedures/PrintQueue.xsunit.xsjslib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
describe("Print Queue Tests", function() { var cut = $.import("com.sap.sapmentors.sitreg.odatareceptionist.procedures", "PrintQueue"); var participant; var ParticipantID; var EventID; beforeOnce(function() { var select = 'SELECT TOP 1 "ID", "Participant"."EventID" ' + 'FROM "com.sap.sapmentors.sitreg.data::SITreg.Participant" AS "Participant" ' + 'LEFT JOIN "com.sap.sapmentors.sitreg.data::SITreg.Device" AS "Device" ' + 'ON "Device"."EventID" = "Participant"."EventID" ' + 'WHERE "Device"."DeviceID" IS NOT NULL'; var pStmt = jasmine.dbConnection.prepareStatement(select); var rs = pStmt.executeQuery(); if (rs.next()) { ParticipantID = rs.getInteger(1); EventID = rs.getInteger(2); } pStmt.close(); }); it('should read participant details', function() { participant = cut.readParticipant(ParticipantID); expect(participant.ParticipantID).toBe(ParticipantID); expect(participant.EventID).toBe(EventID); }); it('should read devices for event', function() { var devices = cut.getDevicesForEvent(EventID); expect(devices.length).toBe(1); }); it('should check that there is no entry in Print Queue with sent status', function() { var boolean = cut.hasPrintQueueElementInSentStatusForEvent(EventID); expect(boolean).toBe(false); }); it('should fill print queue', function() { var status = cut.addParticipantToPrintQueue(participant); expect(status.error).toBe(undefined); }); it('should check that there is an entry in Print Queue with sent status', function() { var boolean = cut.hasPrintQueueElementInSentStatusForEvent(EventID); expect(boolean).toBe(true); }); it('check if participant was inserted', function() { var boolean = cut.isParticipantInPrintQueue(ParticipantID); expect(boolean).toBe(true); }); afterOnce(function() { var select = 'DELETE FROM "com.sap.sapmentors.sitreg.data::SITreg.PrintQueue" ' + 'WHERE "ParticipantID" = ?'; var pStmt = jasmine.dbConnection.prepareStatement(select); pStmt.setInteger(1, participant.ParticipantID); pStmt.execute(); jasmine.dbConnection.commit(); pStmt.close(); });});
describe("Print Queue Tests", function() { var cut = $.import("com.sap.sapmentors.sitreg.odatareceptionist.procedures", "PrintQueue"); var participant; var ParticipantID; var EventID; beforeOnce(function() { var select = 'SELECT TOP 1 "ID", "Participant"."EventID" ' + 'FROM "com.sap.sapmentors.sitreg.data::SITreg.Participant" AS "Participant" ' + 'LEFT JOIN "com.sap.sapmentors.sitreg.data::SITreg.Device" AS "Device" ' + 'ON "Device"."EventID" = "Participant"."EventID" ' + 'WHERE "Device"."DeviceID" IS NOT NULL'; var pStmt = jasmine.dbConnection.prepareStatement(select); var rs = pStmt.executeQuery(); if (rs.next()) { ParticipantID = rs.getInteger(1); EventID = rs.getInteger(2); } pStmt.close(); }); it('should read participant details', function() { participant = cut.readParticipant(ParticipantID); expect(participant.ParticipantID).toBe(ParticipantID); expect(participant.EventID).toBe(EventID); }); it('should read devices for event', function() { var devices = cut.getDevicesForEvent(EventID); expect(devices.length).toBe(1); }); it('should check that there is no entry in Print Queue with sent status', function() { var boolean = cut.hasPrintQueueElementInSentStatusForEvent(EventID); expect(boolean).toBe(false); }); it('should fill print queue', function() { var status = cut.addParticipantToPrintQueue(participant); expect(status.error).toBe(undefined); expect(status.toDevice.status).toBe(200); // expect(status.toDevice.body).toBe(200); }); it('should check that there is an entry in Print Queue with sent status', function() { var boolean = cut.hasPrintQueueElementInSentStatusForEvent(EventID); expect(boolean).toBe(true); }); it('check if participant was inserted', function() { var boolean = cut.isParticipantInPrintQueue(ParticipantID); expect(boolean).toBe(true); }); afterOnce(function() { var select = 'DELETE FROM "com.sap.sapmentors.sitreg.data::SITreg.PrintQueue"' // + ' WHERE "ParticipantID" = ?' ; var pStmt = jasmine.dbConnection.prepareStatement(select); pStmt.setInteger(1, participant.ParticipantID); pStmt.execute(); jasmine.dbConnection.commit(); pStmt.close(); });});
Expand Down

0 comments on commit daa90b5

Please sign in to comment.