Skip to content

Commit

Permalink
Read devices for event #25
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf committed Oct 6, 2016
1 parent 48daa54 commit 85cf038
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
38 changes: 33 additions & 5 deletions odatareceptionist/procedures/PrintQueue.xsjslib
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,42 @@ function isParticipantInPrintQueue(_ParticipantID) {
pStmt.close();
} catch (e) {
$.trace.debug("Error: exception caught: <br />" + e.toString());
}
return count;
}
if(count === 0) {
return false;
} else {
return true;
}
}

function getDevicesForEvent(_EventID) {
var conn;
var devices = [];
try {
conn = $.db.getConnection();
var select = 'SELECT "DeviceID" '
+ 'FROM "com.sap.sapmentors.sitreg.data::SITreg.Device" '
+ 'WHERE "EventID" = ?';
var pStmt = conn.prepareStatement(select);
pStmt.setInteger(1, _EventID);
var rs = pStmt.executeQuery();
if (rs.next()) {
devices.push(rs.getString(1));
}
pStmt.close();
} catch (e) {
$.trace.debug("Error: exception caught: <br />" + e.toString());
}
return devices;
}

function addParticipantToPrintQueue(_participant) {
var conn;
var status = {};
try {
conn = $.db.getConnection();
status.count = isParticipantInPrintQueue(_participant.ParticipantID);
if(status.count === 0) {
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 )';
Expand All @@ -62,6 +87,9 @@ function addParticipantToPrintQueue(_participant) {
pStmt.setInteger(2, _participant.EventID);
pStmt.setString(3, _participant.FirstName);
pStmt.setString(4, _participant.LastName);
if(!_participant.Twitter) {
_participant.Twitter = "";
}
pStmt.setString(5, _participant.Twitter);
pStmt.setString(6, _participant.PrintStatus);
pStmt.executeUpdate();
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" '; var pStmt = jasmine.dbConnection.prepareStatement(select); var rs = pStmt.executeQuery(); if (rs.next()) { ParticipantID = rs.getInteger(1); EventID = rs.getInteger(1); } pStmt.close(); }); it('should read participant details', function() { participant = cut.readParticipant(ParticipantID); expect(participant.ParticipantID).toBe(ParticipantID); }); it('should fill print queue', function() { participant.PrintStatus = 'P'; var status = cut.addParticipantToPrintQueue(participant); expect(status.error).toBe(undefined); expect(status.count).toBe(0); }); it('check if participant was inserted', function() { var count = cut.isParticipantInPrintQueue(ParticipantID); expect(count).toBe(1); }); 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 fill print queue', function() { participant.PrintStatus = 'P'; var status = cut.addParticipantToPrintQueue(participant); expect(status.error).toBe(undefined); }); it('check if participant was inserted', function() { var count = cut.isParticipantInPrintQueue(ParticipantID); expect(count).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 85cf038

Please sign in to comment.