Skip to content

Commit

Permalink
Add entity PrintQueue, extend receptionist odata service sapmentors#25
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf authored and open-ui5 committed Oct 14, 2016
1 parent d0a4572 commit caa64ba
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 5 deletions.
84 changes: 84 additions & 0 deletions odatareceptionist/procedures/PrintQueueUpdate.hdbprocedure
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
--
-- Copyright 2016 SAP Mentors
--
-- 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.
--
PROCEDURE "SITREG"."com.sap.sapmentors.sitreg.odatareceptionist.procedures::PrintQueueUpdate" (
IN inrow "SITREG"."com.sap.sapmentors.sitreg.data::SITreg.PrintQueue",
IN oldrow "SITREG"."com.sap.sapmentors.sitreg.data::SITreg.PrintQueue",
OUT error "SITREG"."com.sap.sapmentors.sitreg.data::SITreg.error"
)
LANGUAGE SQLSCRIPT
SQL SECURITY DEFINER
DEFAULT SCHEMA SITREG
AS
BEGIN

DECLARE lv_Count INT;

DECLARE lv_ParticipantID STRING;
DECLARE lv_EventID STRING;
DECLARE lv_FirstName STRING;
DECLARE lv_LastName STRING;
DECLARE lv_Twitter STRING;
DECLARE lv_PrintStatus STRING; -- Q = queued, S = sent, P = printed
DECLARE lv_CreatedBy STRING;
DECLARE lv_CreatedAt STRING;
DECLARE lv_ChangedBy STRING;
DECLARE lv_ChangedAt STRING;

DECLARE lv_PrintStatus_tmp STRING;

DECLARE lv_msg STRING;

SELECT * INTO lv_ParticipantID
, lv_EventID
, lv_FirstName
, lv_LastName
, lv_Twitter
, lv_PrintStatus
, lv_CreatedBy
, lv_CreatedAt
, lv_ChangedBy
, lv_ChangedAt
FROM :inrow;

SELECT "PrintStatus"
INTO lv_PrintStatus_tmp
FROM "com.sap.sapmentors.sitreg.data::SITreg.PrintQueue"
WHERE "ParticipantID" = lv_ParticipantID;

IF lv_PrintStatus_tmp <> '' THEN
IF lv_PrintStatus_tmp = 'S' THEN
IF lv_PrintStatus = 'P' THEN
UPDATE "com.sap.sapmentors.sitreg.data::SITreg.PrintQueue"
SET "PrintStatus" = lv_PrintStatus
, "History.ChangedBy" = CURRENT_USER
, "History.ChangedAt" = CURRENT_TIMESTAMP
WHERE "ParticipantID" = lv_ParticipantID;
ELSE
error = select 400 as http_status_code,
'Update failed' error_message,
'Status can only be set to printed' detail from dummy;
END IF;
ELSE
error = select 400 as http_status_code,
'Update failed' error_message,
'Entry is not is status sent' detail from dummy;
END IF;
ELSE
error = select 400 as http_status_code,
'Update failed' error_message,
'Entry does not exist' detail from dummy;
END IF;
END
20 changes: 15 additions & 5 deletions odatareceptionist/service.xsodata
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ service {
"com.sap.sapmentors.sitreg.odataparticipant.procedures::EventsRead" as "Events" key ("ID")
navigates ("Event_Ticket" as "Tickets",
"Event_Participants" as "Participants",
"Event_RegistrationNumbers" as "RegistrationNumbers")
"Event_RegistrationNumbers" as "RegistrationNumbers",
"Event_PrintQueue" as "PrintQueue")
create forbidden
update forbidden
delete forbidden;
Expand All @@ -32,12 +33,18 @@ service {
update forbidden
delete forbidden;

association "Event_Participants" principal "Events"("ID") multiplicity "1"
dependent "Participants"("EventID") multiplicity "*";

// Read RegistrationNumbers from View to restrict fields that can be read
"com.sap.sapmentors.sitreg.odataparticipant.procedures::RegistrationNumbersRead" as "RegistrationNumbers" key ("EventID")
create forbidden
update forbidden
delete forbidden;

association "Event_RegistrationNumbers" principal "Events"("ID") multiplicity "1"
dependent "RegistrationNumbers"("EventID") multiplicity "1";

// Read Ticket from View to restrict fields that can be read
"com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketRead" as "Ticket" key ("ParticipantID")
create forbidden
Expand All @@ -46,10 +53,13 @@ service {

association "Event_Ticket" principal "Events"("ID") multiplicity "1"
dependent "Ticket"("EventID") multiplicity "*";
association "Event_Participants" principal "Events"("ID") multiplicity "1"
dependent "Participants"("EventID") multiplicity "*";
association "Event_RegistrationNumbers" principal "Events"("ID") multiplicity "1"
dependent "RegistrationNumbers"("EventID") multiplicity "1";
association "Participant_Ticket" principal "Participants"("ID") multiplicity "1"
dependent "Ticket"("ParticipantID") multiplicity "1";
// Read PrintQueue
"com.sap.sapmentors.sitreg.data::SITreg.PrintQueue" as "PrintQueue"
create forbidden
update using "com.sap.sapmentors.sitreg.odatareceptionist.procedures::PrintQueueUpdate"
delete forbidden;
association "Event_PrintQueue" principal "Events"("ID") multiplicity "1"
dependent "PrintQueue"("EventID") multiplicity "*";
}
1 change: 1 addition & 0 deletions roles/receptionist.hdbrole
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +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;
}

0 comments on commit caa64ba

Please sign in to comment.