From 44be86af20d55b506c7dcc5622533dbb1b29f3c3 Mon Sep 17 00:00:00 2001 From: Robin de Silva Jayasinghe Date: Thu, 11 Jan 2024 15:40:53 +0100 Subject: [PATCH 1/3] updated java settings --- .vscode/settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7b016a89..d53ecaf3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "java.compile.nullAnalysis.mode": "automatic" + "java.compile.nullAnalysis.mode": "automatic", + "java.configuration.updateBuildConfiguration": "automatic" } \ No newline at end of file From 6afe368b9ab735767797f96faea3b420c1e42a0d Mon Sep 17 00:00:00 2001 From: Robin de Silva Jayasinghe Date: Thu, 11 Jan 2024 15:41:30 +0100 Subject: [PATCH 2/3] set trigger file for work with devtools and mvn cds:auto-build --- srv/src/main/resources/application.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/srv/src/main/resources/application.yml b/srv/src/main/resources/application.yml index 090f4d17..70aa0e30 100644 --- a/srv/src/main/resources/application.yml +++ b/srv/src/main/resources/application.yml @@ -26,6 +26,7 @@ cds: spring: config.activate.on-profile: default web.resources.static-locations: "file:./app" + devtools.restart.trigger-file: .reloadtrigger server: port: 4004 From cac1050d4cb52cbd2147b5557b9676e581ec7376 Mon Sep 17 00:00:00 2001 From: Robin de Silva Jayasinghe Date: Thu, 18 Jan 2024 13:29:49 +0100 Subject: [PATCH 3/3] intermediate step --- db/master-data.cds | 2 +- .../TravelBookingUpdatedHandler.java | 31 +++++++++++++++++++ srv/travel-service.cds | 10 ++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 srv/src/main/java/com/sap/cap/sflight/processor/TravelBookingUpdatedHandler.java diff --git a/db/master-data.cds b/db/master-data.cds index 950fada3..7482390e 100644 --- a/db/master-data.cds +++ b/db/master-data.cds @@ -30,7 +30,7 @@ entity Supplement : managed, MasterData { CurrencyCode : Currency; }; -entity Flight : MasterData { +entity Flight { // TODO: // when cuid is added, the to_Airline & to_Connection can be made managed association, // furthermore the AirlineID and ConnectionID can be removed, diff --git a/srv/src/main/java/com/sap/cap/sflight/processor/TravelBookingUpdatedHandler.java b/srv/src/main/java/com/sap/cap/sflight/processor/TravelBookingUpdatedHandler.java new file mode 100644 index 00000000..e5bd5991 --- /dev/null +++ b/srv/src/main/java/com/sap/cap/sflight/processor/TravelBookingUpdatedHandler.java @@ -0,0 +1,31 @@ +package com.sap.cap.sflight.processor; + +import org.springframework.stereotype.Component; + +import com.sap.cds.ql.CQL; +import com.sap.cds.ql.Select; +import com.sap.cds.services.cds.CqnService; +import com.sap.cds.services.handler.EventHandler; +import com.sap.cds.services.handler.annotations.Before; +import com.sap.cds.services.handler.annotations.ServiceName; + +import cds.gen.travelservice.Booking_; +import cds.gen.travelservice.Travel; +import cds.gen.travelservice.TravelService_; +import cds.gen.travelservice.Travel_; + +@Component +@ServiceName(TravelService_.CDS_NAME) +public class TravelBookingUpdatedHandler implements EventHandler { + + + @Before(event = {CqnService.EVENT_UPDATE, CqnService.EVENT_CREATE}, entity = Travel_.CDS_NAME) + public void onTravelUpdate(Travel travel) { + + + Select allTravels = Select.from(Booking_.class) + .columns(c -> CQL.count(c.ConnectionID()).as("seats")) + .where(b -> b.to_Travel_TravelUUID().eq(travel.travelUUID())) + .groupBy(g -> g.ConnectionID()); + } +} diff --git a/srv/travel-service.cds b/srv/travel-service.cds index cdb00c57..7ffc1bce 100644 --- a/srv/travel-service.cds +++ b/srv/travel-service.cds @@ -1,7 +1,17 @@ using { sap.fe.cap.travel as my } from '../db/schema'; +using { sap.fe.cap.travel as masterdata} from '../db/master-data.cds'; service TravelService @(path:'/processor') { + @readonly + @cds.autoexpose + entity Flight as projection on masterdata.Flight; + + event BookedSeatsOnFlight { + ConnectionID : String(4); + numberOfSeats : Integer; + } + @(restrict: [ { grant: 'READ', to: 'authenticated-user'}, { grant: ['rejectTravel','acceptTravel','deductDiscount'], to: 'reviewer'},