diff --git a/odatareceptionist/procedures/PrintQueueUpdate.hdbprocedure b/odatareceptionist/procedures/PrintQueueUpdate.hdbprocedure new file mode 100644 index 0000000..1829a65 --- /dev/null +++ b/odatareceptionist/procedures/PrintQueueUpdate.hdbprocedure @@ -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 \ No newline at end of file diff --git a/odatareceptionist/service.xsodata b/odatareceptionist/service.xsodata index 690cd93..c2be72c 100644 --- a/odatareceptionist/service.xsodata +++ b/odatareceptionist/service.xsodata @@ -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; @@ -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 @@ -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 "*"; } \ No newline at end of file diff --git a/roles/receptionist.hdbrole b/roles/receptionist.hdbrole index 24ad962..da96b36 100644 --- a/roles/receptionist.hdbrole +++ b/roles/receptionist.hdbrole @@ -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; }