diff --git a/odatareceptionist/procedures/PrintQueue.xsjslib b/odatareceptionist/procedures/PrintQueue.xsjslib
index d4da330..53c0d77 100644
--- a/odatareceptionist/procedures/PrintQueue.xsjslib
+++ b/odatareceptionist/procedures/PrintQueue.xsjslib
@@ -1,4 +1,83 @@
-function PrintQueueUpdate(param){
+function readParticipant(_ParticipantID) {
+ var conn;
+ var participant = {};
+
+ try {
+ conn = $.db.getConnection();
+ var select = 'SELECT "ID", "EventID", "FirstName", "LastName", "Twitter"'
+ + ' FROM "com.sap.sapmentors.sitreg.data::SITreg.Participant"'
+ + ' WHERE "ID" = ?';
+ var pStmt = conn.prepareStatement(select);
+ pStmt.setInteger(1, _ParticipantID);
+ var rs = pStmt.executeQuery();
+ if (rs.next()) {
+ participant.ParticipantID = rs.getInteger(1);
+ participant.EventID = rs.getInteger(2);
+ participant.FirstName = rs.getNString(3);
+ participant.LastName = rs.getNString(4);
+ participant.Twitter = rs.getNString(5);
+ }
+ rs.close();
+ pStmt.close();
+ conn.close();
+ } catch (e) {
+ participant.error = "Error: exception caught:
" + e.toString();
+ }
+ return participant;
+}
+
+function isParticipantInPrintQueue(_ParticipantID) {
+ var conn;
+ var count;
+ try {
+ conn = $.db.getConnection();
+ var select = 'SELECT COUNT("ParticipantID") AS count '
+ + 'FROM "com.sap.sapmentors.sitreg.data::SITreg.PrintQueue" '
+ + 'WHERE "ParticipantID" = ?';
+ var pStmt = conn.prepareStatement(select);
+ pStmt.setInteger(1, _ParticipantID);
+ var rs = pStmt.executeQuery();
+ if (rs.next()) {
+ count = rs.getInteger(1);
+ }
+ pStmt.close();
+ } catch (e) {
+ $.trace.debug("Error: exception caught:
" + e.toString());
+ }
+ return count;
+}
+
+function addParticipantToPrintQueue(_participant) {
+ var conn;
+ var status = {};
+ try {
+ conn = $.db.getConnection();
+ status.count = isParticipantInPrintQueue(_participant.ParticipantID);
+ if(status.count === 0) {
+ 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();
+ } else {
+ status.error = "Entry does already exist";
+ }
+ conn.close();
+ } catch (e) {
+ status.error = "Error: exception caught:
" + e.toString();
+ }
+ return status;
+}
+
+function PrintQueueUpdateAfterTicketUpdate(param){
$.trace.debug('entered function PrintQueueUpdate');
// let before = param.beforeTableName;
let after = param.afterTableName;
@@ -6,8 +85,12 @@ function PrintQueueUpdate(param){
let pStmt = param.connection.prepareStatement('SELECT * FROM "' + after + '"' );
let rs = pStmt.executeQuery();
if (rs.next()) {
+ var ParticipantID = rs.getNString(1);
var TicketUsed = rs.getNString(4);
}
- $.trace.debug('TicketUsed: ' + TicketUsed);
+ $.trace.debug('ParticipantID:' + ParticipantID + 'TicketUsed: ' + TicketUsed);
+ // var participant = readParticipant(ParticipantID);
+ rs.close();
+ pStmt.close();
$.trace.debug('leave function PrintQueueUpdate');
-}
\ No newline at end of file
+}
diff --git a/odatareceptionist/procedures/PrintQueue.xsunit.xsjslib b/odatareceptionist/procedures/PrintQueue.xsunit.xsjslib
new file mode 100644
index 0000000..55890d9
--- /dev/null
+++ b/odatareceptionist/procedures/PrintQueue.xsunit.xsjslib
@@ -0,0 +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();
});
});
\ No newline at end of file
diff --git a/odatareceptionist/service.xsodata b/odatareceptionist/service.xsodata
index e553110..9be68eb 100644
--- a/odatareceptionist/service.xsodata
+++ b/odatareceptionist/service.xsodata
@@ -49,7 +49,8 @@ service {
"com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketRead" as "Ticket" key ("ParticipantID")
create forbidden
update using "com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketUpdate"
- events ( after "com.sap.sapmentors.sitreg.odatareceptionist.procedures:PrintQueue.xsjslib::PrintQueueUpdate" )
+ events (
+ after "com.sap.sapmentors.sitreg.odatareceptionist.procedures:PrintQueue.xsjslib::PrintQueueUpdateAfterTicketUpdate" )
delete forbidden;
association "Event_Ticket" principal "Events"("ID") multiplicity "1"
diff --git a/roles/admin.hdbrole b/roles/admin.hdbrole
index 72cea14..db2f6ed 100644
--- a/roles/admin.hdbrole
+++ b/roles/admin.hdbrole
@@ -4,6 +4,7 @@ role com.sap.sapmentors.sitreg.roles::admin {
sql object com.sap.sapmentors.sitreg.data::SITreg.Participant: SELECT, INSERT, UPDATE, DELETE;
sql object com.sap.sapmentors.sitreg.data::SITreg.Organizer: SELECT, INSERT, UPDATE, DELETE;
sql object com.sap.sapmentors.sitreg.data::SITreg.Ticket: SELECT, INSERT, UPDATE, DELETE;
+ sql object com.sap.sapmentors.sitreg.data::SITreg.PrintQueue: SELECT, INSERT, UPDATE, DELETE;
sql object com.sap.sapmentors.sitreg.odataparticipant.procedures::TicketCreate: EXECUTE;
sql object com.sap.sapmentors.sitreg.odataadmin.procedures::TicketCreateMissing: EXECUTE;
sql object com.sap.sapmentors.sitreg.odataadmin.procedures::ParticipantUpdateWaitingList: EXECUTE;
diff --git a/roles/receptionist.hdbrole b/roles/receptionist.hdbrole
index da96b36..b1cf364 100644
--- a/roles/receptionist.hdbrole
+++ b/roles/receptionist.hdbrole
@@ -6,5 +6,5 @@ role com.sap.sapmentors.sitreg.roles::receptionist {
sql object com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketRead: SELECT;
sql object com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketCheck: EXECUTE;
sql object com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketUpdate: EXECUTE;
- sql object com.sap.sapmentors.sitreg.data::SITreg.PrintQueue: SELECT, UPDATE;
+ sql object com.sap.sapmentors.sitreg.data::SITreg.PrintQueue: SELECT, INSERT, UPDATE;
}