Skip to content

Commit

Permalink
Implementation and tests for #5
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf committed Aug 15, 2017
1 parent 69f13a6 commit f809609
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 29 deletions.
11 changes: 0 additions & 11 deletions data/SITreg.hdbdd
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,4 @@ context SITreg {
PrintStatus : String(1) not null; // Q = queued, S = sent, P = printed
History : HistoryT;
};

entity RegisterAsOrganizerQueue {
key EventID : BusinessKey not null default 0;
key UserName : UserT;
Organizer : association to SITreg.Organizer {UserName};
Status : String(1); // See enum RegisterAsOrganizerStatus // A = Accepted / R = Rejected / P = Pending
RequestTimeStamp : UTCTimestamp;
StatusSetTimeStamp : UTCTimestamp;
History : HistoryT;
};

};
58 changes: 58 additions & 0 deletions odataorganizer/confirmOrganizer.xsjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2016 Gregor Wolf
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

var XSDS = $.import("sap.hana.xs.libs.dbutils", "xsds");

function confirmOrganizer() {
var body;
var conn;
$.response.status = $.net.http.OK;
$.response.contentType = "application/json";
try {
var UserName = "";
if($.request.method === $.net.http.GET) {
UserName = decodeURIComponent($.request.parameters.get("UserName"));
} else {
var content = $.request.body.asString();
var postData = JSON.parse(content);
UserName = postData.UserName;
}
var Organizer = XSDS.$importEntity("com.sap.sapmentors.sitreg.data", "SITreg.Organizer", {}, { $schemaName: "SITREG" });
var existingOrganizer = Organizer.$get({ UserName: UserName });
existingOrganizer.Status = 'A';
existingOrganizer.History.ChangedBy = $.session.getUsername();
existingOrganizer.History.ChangedAt = new Date();
existingOrganizer.$save();
XSDS.Transaction.$commit();

conn = $.hdb.getConnection();
var grantOrganizerRoleToUser = conn.loadProcedure("SITREG", "com.sap.sapmentors.sitreg.odataorganizer.procedures::GrantOrganizerRoleToUser");
var grantOrganizerRoleToUserResult = grantOrganizerRoleToUser(UserName);
body = JSON.stringify(grantOrganizerRoleToUserResult);
} catch (e) {
$.response.contentType = "text/json";
body = '{ "error": "' + e.toString() + '"}';
$.response.status = $.net.http.BAD_REQUEST;
}
if (conn) {
conn.close();
}
$.response.setBody( body );
}

confirmOrganizer();
5 changes: 5 additions & 0 deletions odataorganizer/service.xsodata
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ service {

association "Participant_Ticket" principal "Participants"("ID") multiplicity "1"
dependent "Ticket"("ParticipantID") multiplicity "1";

"com.sap.sapmentors.sitreg.data::SITreg.Organizer" as "Organizer"
create forbidden
update forbidden
delete forbidden;
}
19 changes: 8 additions & 11 deletions odataparticipant/procedures/RegisterAsOrganizerCreate.hdbprocedure
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ BEGIN
DECLARE lv_CreatedAt string;
DECLARE lv_ChangedBy string;
DECLARE lv_ChangedAt string;
DECLARE lv_now string;

SELECT * INTO
lv_UserName,
Expand Down Expand Up @@ -66,22 +65,20 @@ BEGIN
lv_CreatedBy = lv_UserName;
lv_ChangedBy = lv_UserName;

lv_now = CURRENT_TIMESTAMP;

INSERT INTO "com.sap.sapmentors.sitreg.data::SITreg.Organizer"
VALUES(
UCASE( lv_UserName ),
lv_FirstName,
lv_LastName,
lv_Email,
lv_MobilePhone,
UCASE( lv_Status ),
CURRENT_TIMESTAMP,
UCASE( lv_UserName ),
lv_FirstName,
lv_LastName,
lv_Email,
lv_MobilePhone,
UCASE( lv_Status ),
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
lv_CreatedBy,
CURRENT_TIMESTAMP,
lv_ChangedBy,
lv_now
CURRENT_TIMESTAMP
);
IF 1 = 2 THEN
error = SELECT 400 AS http_status_code,
Expand Down
1 change: 0 additions & 1 deletion roles/admin.hdbrole
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ role com.sap.sapmentors.sitreg.roles::admin {
sql object com.sap.sapmentors.sitreg.data::SITreg.Ticket: 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.PrintQueue: SELECT, INSERT, UPDATE, DELETE;
sql object com.sap.sapmentors.sitreg.data::SITreg.RegisterAsOrganizerQueue: 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;
Expand Down
2 changes: 2 additions & 0 deletions roles/organizer.hdbrole
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ role com.sap.sapmentors.sitreg.roles::organizer {
sql object com.sap.sapmentors.sitreg.odataorganizer.procedures::ParticipantsRead: SELECT;
sql object com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketRead: SELECT;
sql object com.sap.sapmentors.sitreg.odataorganizer.procedures::UpdateWaitingList: EXECUTE;
// Organizer
sql object com.sap.sapmentors.sitreg.data::SITreg.Organizer: SELECT, UPDATE;

application privilege: "com.sap.sapmentors.sitreg.odataorganizer::organizer";
}
1 change: 0 additions & 1 deletion roles/participant.hdbrole
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ role com.sap.sapmentors.sitreg.roles::participant {

sql object com.sap.sapmentors.sitreg.odataparticipant.procedures::RegisterAsOrganizerCreate: EXECUTE;
sql object com.sap.sapmentors.sitreg.odataparticipant.procedures::RegisterAsOrganizerRead: SELECT;
sql object com.sap.sapmentors.sitreg.data::SITreg.RegisterAsOrganizerQueue: INSERT, UPDATE;
sql object com.sap.sapmentors.sitreg.data::SITreg.Organizer: INSERT, UPDATE;

application privilege: "com.sap.sapmentors.sitreg.odataparticipant::participant";
Expand Down
33 changes: 33 additions & 0 deletions test/060_CoOrganizerReadParticipantsTest.xsjslib
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var loginResult;
var header;
var eventUri;
var eventID;
var UserName;

describe("Co-Organizer", function() {

Expand Down Expand Up @@ -43,6 +44,38 @@ describe("Co-Organizer", function() {
expect(body.d.RSVP).toBe("N");
});

it("should read participants that requested the organizer role", function() {
var url = parameters.odataOrganizer + "Organizer?$filter=Status eq 'P'";
var response = jasmine.callHTTPService(
encodeURI(url),
$.net.http.GET,
undefined,
header,
loginResult.cookies
);
var body = helper.getResponseBody(response);
// jasmine.log(JSON.stringify(body));
expect(response.status).toBe(200);
UserName = body.d.results[0].UserName;
expect(UserName).not.toBe(null);
});

it("should confirm the participant that sent an organizer request", function() {
var check = {
"UserName": UserName
};
var response = jasmine.callHTTPService(
"/com/sap/sapmentors/sitreg/odataorganizer/confirmOrganizer.xsjs",
$.net.http.POST,
JSON.stringify(check),
header,
loginResult.cookies
);
expect(response.status).toBe($.net.http.OK);
var body = helper.getResponseBody(response);
// jasmine.log(JSON.stringify(body));
});

it("should logout", function() {
helper.logout(loginResult.csrf, loginResult.cookies);
helper.checkSession();
Expand Down
15 changes: 14 additions & 1 deletion test/070_ParticipantConfirmedForSmallEventTest.xsjslib
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("Participant", function() {
loginResult = helper.getCSRFtokenAndLogin(username, helper.newpwd);
header = helper.prepareRequestHeader(loginResult.csrf);
});

it("should read Small-Event and check for waiting status", function() {
var response = jasmine.callHTTPService(
parameters.readEventsServiceParticipant,
Expand Down Expand Up @@ -64,6 +64,19 @@ describe("Participant", function() {
expect(body.d.RSVP).toBe("Y");
});

it("should try to read organizer OData service as he is now also an organizer", function() {
var eventUriOrganizer = eventUri.replace("odataparticipant", "odataorganizer");

var response = jasmine.callHTTPService(
eventUriOrganizer,
$.net.http.GET,
undefined,
header,
loginResult.cookies
);
expect(response.status).toBe(200);
});

it("should logout PARTICIPANT", function() {
helper.logout(loginResult.csrf, loginResult.cookies);
helper.checkSession();
Expand Down
8 changes: 7 additions & 1 deletion test/090_ReceptionistTest.xsjslib
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ describe("Participant", function() {
});

it("should read the event ID", function() {
var response = jasmine.callHTTPService(parameters.readEventsServiceParticipant, $.net.http.GET, undefined, header, loginResult.cookies);
var response = jasmine.callHTTPService(
parameters.readEventsServiceParticipant,
$.net.http.GET,
undefined,
header,
loginResult.cookies
);
expect(response.status).toBe($.net.http.OK);
var body = helper.getResponseBody(response);
var smallEventIndex = body.d.results.length - 1;
Expand Down
3 changes: 2 additions & 1 deletion test/parameters.xsjslib
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
var readEventsService = encodeURI("/com/sap/sapmentors/sitreg/odataorganizer/service.xsodata/Events?$filter=History.CreatedBy eq 'ORGANIZER'");
var readEventsServiceParticipant = encodeURI("/com/sap/sapmentors/sitreg/odataparticipant/service.xsodata/Events");
var readEventsServiceParticipant = encodeURI("/com/sap/sapmentors/sitreg/odataparticipant/service.xsodata/Events");
var odataOrganizer = "/com/sap/sapmentors/sitreg/odataorganizer/service.xsodata/";
2 changes: 0 additions & 2 deletions test/procedures/setup.hdbprocedure
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ BEGIN
DELETE FROM "com.sap.sapmentors.sitreg.data::SITreg.Device"
WHERE "History.CreatedBy" = 'ORGANIZER'
OR "History.CreatedBy" = 'COORGANIZER';
DELETE FROM "com.sap.sapmentors.sitreg.data::SITreg.RegisterAsOrganizerQueue"
WHERE "History.CreatedBy" = 'PARTICIPANT';
DELETE FROM "com.sap.sapmentors.sitreg.data::SITreg.Organizer"
WHERE "History.CreatedBy" = 'PARTICIPANT';

Expand Down

0 comments on commit f809609

Please # to comment.