Skip to content

Commit

Permalink
Add fields Event Description & Type to fix #11 and #20, test for #1
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf committed Oct 30, 2016
1 parent 968a74d commit 565243c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
3 changes: 3 additions & 0 deletions data/SITreg.hdbdd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ context SITreg {
type BusinessKey : Integer;
type UserT : String(256);
type RelationToSAPT : String(1);
type EventTypeT : String(1);
type SDate : LocalDate;
type URL : String(256);
type TicketUsedT : String(1) enum{ YES = 'Y'; NO = 'N'; };
Expand Down Expand Up @@ -62,6 +63,8 @@ context SITreg {
MaxParticipants : Integer not null;
HomepageURL : URL;
History : HistoryT;
Description : String(100);
Type : EventTypeT;
};

entity CoOrganizer {
Expand Down
30 changes: 18 additions & 12 deletions odataorganizer/procedures/EventCreate.hdbprocedure
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ BEGIN
DECLARE lv_CreatedAt string;
DECLARE lv_ChangedBy string;
DECLARE lv_ChangedAt string;
DECLARE lv_Description string;
DECLARE lv_Type string;

SELECT * INTO lv_ID
, lv_Location
Expand All @@ -46,7 +48,9 @@ BEGIN
, lv_CreatedBy
, lv_CreatedAt
, lv_ChangedBy
, lv_ChangedAt
, lv_ChangedAt
, lv_Description
, lv_Type
FROM :inrow;

-- Don't trust the provided Username. we read it from the current user
Expand All @@ -59,17 +63,19 @@ BEGIN
FROM dummy;

INSERT INTO "com.sap.sapmentors.sitreg.data::SITreg.Event"
VALUES(lv_ID
, lv_Location
, lv_EventDate
, lv_StartTime
, lv_EndTime
, lv_MaxParticipants
, lv_HomepageURL
, lv_CreatedBy
, CURRENT_TIMESTAMP
, lv_CreatedBy
, CURRENT_TIMESTAMP
VALUES(lv_ID
, lv_Location
, lv_EventDate
, lv_StartTime
, lv_EndTime
, lv_MaxParticipants
, lv_HomepageURL
, lv_CreatedBy
, CURRENT_TIMESTAMP
, lv_CreatedBy
, CURRENT_TIMESTAMP
, lv_Description
, lv_Type
);
-- Procedures for XSODATA are expected to fill the error sturcture
-- TODO: Find a better solution for 1 = 2
Expand Down
20 changes: 17 additions & 3 deletions odataorganizer/procedures/EventUpdate.hdbprocedure
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ BEGIN
DECLARE lv_CreatedAt DATE;
DECLARE lv_ChangedBy string;
DECLARE lv_ChangedAt DATE;
DECLARE lv_Description string;
DECLARE lv_Type string;

DECLARE lv_Location_tmp string;
DECLARE lv_EventDate_tmp DATE;
DECLARE lv_StartTime_tmp TIMESTAMP;
DECLARE lv_EndTime_tmp TIMESTAMP;
DECLARE lv_MaxParticipants_tmp INTEGER;
DECLARE lv_HomepageURL_tmp string;

DECLARE lv_Description_tmp string;
DECLARE lv_Type_tmp string;

SELECT * INTO lv_ID
, lv_Location
Expand All @@ -57,6 +60,8 @@ BEGIN
, lv_CreatedAt
, lv_ChangedBy
, lv_ChangedAt
, lv_Description
, lv_Type
FROM :inrow;
-- Don't trust the provided Username. We read it from the current user
SELECT CURRENT_USER INTO lv_ChangedBy FROM DUMMY;
Expand All @@ -74,13 +79,18 @@ BEGIN
END IF;

IF lv_Count = 1 THEN
SELECT "Location", "EventDate", "StartTime", "EndTime", "MaxParticipants", "HomepageURL"
SELECT "Location", "EventDate",
"StartTime", "EndTime",
"MaxParticipants", "HomepageURL",
"Description", "Type"
INTO lv_Location_tmp
, lv_EventDate_tmp
, lv_StartTime_tmp
, lv_EndTime_tmp
, lv_MaxParticipants_tmp
, lv_HomepageURL_tmp
, lv_HomepageURL_tmp
, lv_Description_tmp
, lv_Type_tmp
FROM "com.sap.sapmentors.sitreg.data::SITreg.Event"
WHERE "ID" = lv_ID;
-- OData call can also contain just single attributes. We have to preserve the data
Expand All @@ -90,6 +100,8 @@ BEGIN
if lv_EndTime = '' then lv_EndTime = lv_EndTime_tmp; END IF;
if lv_MaxParticipants = 0 then lv_MaxParticipants = lv_MaxParticipants_tmp; END IF;
if lv_HomepageURL = '' then lv_HomepageURL = lv_HomepageURL_tmp; END IF;
if lv_Description = '' then lv_Description = lv_Description_tmp; END IF;
if lv_Type = '' then lv_Type = lv_Type_tmp; END IF;

IF lv_MaxParticipants <> lv_MaxParticipants_tmp THEN
-- When MaxParticipants is changed, the Waiting List must be updated
Expand All @@ -108,6 +120,8 @@ BEGIN
, "HomepageURL" = lv_HomepageURL
, "History.ChangedBy" = lv_ChangedBy
, "History.ChangedAt" = CURRENT_TIMESTAMP
, "Description" = lv_Description
, "Type" = lv_Type
WHERE "ID" = lv_ID;

ELSE
Expand Down
1 change: 0 additions & 1 deletion roles/organizer.hdbrole
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
role com.sap.sapmentors.sitreg.roles::organizer {
// catalog schema "SITREG": SELECT;
sql object com.sap.sapmentors.sitreg.data::eventId: SELECT;
sql object com.sap.sapmentors.sitreg.data::SITreg.Event: SELECT, INSERT, UPDATE;
sql object com.sap.sapmentors.sitreg.odataorganizer.procedures::EventCreate: EXECUTE;
Expand Down
8 changes: 6 additions & 2 deletions test/spec/Organizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ describe("Create event", function() {
"München",
"/Date(1475798400000)/",
"/Date(1475910000000)/",
"/Date(1475942400000)/"
"/Date(1475942400000)/",
"SAP Inside Track"
);
expect(xhr.status).toBe(201);
expect(xhr.statusText).toBe("Created");
Expand All @@ -37,7 +38,8 @@ describe("Create event", function() {
"Bern",
"/Date(1472774400000)/",
"/Date(1472889600000)/",
"/Date(1472911200000)/"
"/Date(1472911200000)/",
"早上好"
);
expect(xhr.status).toBe(201);
expect(xhr.statusText).toBe("Created");
Expand All @@ -62,6 +64,8 @@ describe("Read event and change MaxParticipants", function() {
expect(xhr.statusText).toBe("OK");
var body = xhr.responseText ? JSON.parse(xhr.responseText) : "";
expect(body.d.results[0].Location).toBe("München");
expect(body.d.results[0].Description).toBe("SAP Inside Track");
expect(body.d.results[1].Description).toBe("早上好");
// Change MaxParticipants
eventUri = body.d.results[0].__metadata.uri;
eventUri2 = body.d.results[1].__metadata.uri;
Expand Down

0 comments on commit 565243c

Please sign in to comment.