Skip to content

Commit 736964a

Browse files
authored
feat: status-transition flows (#15)
### summary makes use of new status-transition flows feature of cds-services^4.5 and cds^9.5: - check entry state(s) for action → previously unchecked → TODO: true? - set to exit state for action → remove custom handlers - automatically add ui artifacts → remove unnecessary annotations ### `CDS_ENV=flow mvn cds:watch` extends to a more complex flow incl. usage of `@to: $flow.previous`. for that, status `InReview` and `Blocked` as well as actions `reviewTravel`, `reopenTravel`, `blockTravel`, and `unblockTravel` were added in order to create a scenario where the previous state of `Blocked` can be either `Open` or `InReview`. visualization of the flow: <img width="913" height="444" alt="image" src="https://github.com/user-attachments/assets/8dd98cdf-7a01-4e55-85bc-a2a7d69fdd16" /> --- ### related - capire/xtravels#12
1 parent f35ce81 commit 736964a

16 files changed

+4522
-177
lines changed

.cdsrc.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"features": {
3-
"compile_for_flows": true
2+
"[flow]": {
3+
"folders": {
4+
"flow": "xmpls/flow/"
5+
}
46
}
57
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ Alternatively start the application on the command line by executing:
114114
mvn spring-boot:run -Dspring-boot.run.profiles=default,hybrid
115115
```
116116

117+
## Additional Examples
118+
119+
For more (extensive) examples, have a look at the [readme file in the xmpls folder](./xmpls/readme.md).
120+
117121
## License
118122

119123
Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSE) file.

_i18n/i18n_en.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Agency=Agency
33
AgencyName=Agency Name
44
AvgPrice=Average Price
55
BeginDate=Starting Date
6+
BlockTravel=Block Travel
67
Booking=Booking
78
BookingDate=Booking Date
89
BookingDetails=Booking Details
@@ -36,6 +37,8 @@ Prices=Prices
3637
ProductID=Product
3738
ProductPrice=Product Price
3839
RejectTravel=Reject Travel
40+
ReopenTravel=Reopen Travel
41+
ReviewTravel=Review Travel
3942
Status=Status
4043
Street=Street
4144
Title=Title
@@ -45,4 +48,5 @@ Travel=Travel
4548
TravelAgency=Travel Agency
4649
Travels=Travels
4750
TravelStatus=Travel Status
51+
UnblockTravel=Unblock Travel
4852
WebAddress=Web Address

app/labels.cds

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ annotate schema.Passengers with @title: '{i18n>Passenger}' {
7474
}
7575

7676

77+
using { TravelService } from '../srv/travel-service';
78+
79+
annotate TravelService.Travels with actions {
80+
rejectTravel @title: '{i18n>RejectTravel}';
81+
acceptTravel @title: '{i18n>AcceptTravel}';
82+
reopenTravel @title: '{i18n>ReopenTravel}';
83+
deductDiscount @title: '{i18n>DeductDiscount}';
84+
};
85+
86+
7787
using sap.capire.flights.data;
7888

7989
annotate data.Airlines with @title: '{i18n>Airline}' {

app/travels/field-control.cds

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@ annotate TravelService.Travels with @(Common : {
1414
EndDate @readonly: (Status.code = #Accepted) @mandatory: (Status.code != #Accepted);
1515
Agency @readonly: (Status.code = #Accepted) @mandatory: (Status.code != #Accepted);
1616
Customer @readonly: (Status.code = #Accepted) @mandatory: (Status.code != #Accepted);
17-
1817
} actions {
19-
rejectTravel @from: [#Open, #Accepted];
20-
acceptTravel @from: [#Open, #Canceled];
2118
deductDiscount @(
22-
from: #Open,
2319
Common.SideEffects.TargetProperties : ['in/TotalPrice', 'in/BookingFee'],
2420
);
25-
draftEdit @from: [#Open, #Accepted]
2621
}
2722

2823
annotate TravelService.Travels @Common.SideEffects#ReactonItemCreationOrDeletion : {

app/travels/layouts.cds

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ using { TravelService } from '../../srv/travel-service';
77
annotate TravelService.Travels with @UI : {
88

99
Identification : [
10-
{ $Type : 'UI.DataFieldForAction', Action : 'TravelService.acceptTravel', Label : '{i18n>AcceptTravel}' },
11-
{ $Type : 'UI.DataFieldForAction', Action : 'TravelService.rejectTravel', Label : '{i18n>RejectTravel}' },
12-
{ $Type : 'UI.DataFieldForAction', Action : 'TravelService.deductDiscount', Label : '{i18n>DeductDiscount}' }
10+
{ $Type : 'UI.DataFieldForAction', Action : 'TravelService.deductDiscount', Label : '{i18n>DeductDiscount}' },
1311
],
1412

1513
HeaderInfo : {
@@ -35,8 +33,6 @@ annotate TravelService.Travels with @UI : {
3533

3634
LineItem : [
3735

38-
{ $Type : 'UI.DataFieldForAction', Action : 'TravelService.acceptTravel', Label : '{i18n>AcceptTravel}' },
39-
{ $Type : 'UI.DataFieldForAction', Action : 'TravelService.rejectTravel', Label : '{i18n>RejectTravel}' },
4036
{ $Type : 'UI.DataFieldForAction', Action : 'TravelService.deductDiscount', Label : '{i18n>DeductDiscount}' },
4137

4238
{ Value : ID, @UI.Importance : #High },
@@ -50,8 +46,8 @@ annotate TravelService.Travels with @UI : {
5046
{ Value : (Status.code),
5147
Criticality : (
5248
Status.code == #Accepted ? 3 :
53-
Status.code == #Open ? 2 :
54-
Status.code == #Canceled ? 1 : 0
49+
Status.code == #Open OR Status.code == #InReview ? 2 :
50+
Status.code == #Canceled OR Status.code == #Blocked ? 1 : 0
5551
),
5652
@UI.Importance : #High,
5753
@HTML5.CssDefaults: {width:'10em'}
@@ -74,8 +70,8 @@ annotate TravelService.Travels with @UI : {
7470
{ Value : (Status.code),
7571
Criticality : (
7672
Status.code == #Accepted ? 3 :
77-
Status.code == #Open ? 2 :
78-
Status.code == #Canceled ? 1 : 0
73+
Status.code == #Open OR Status.code == #InReview ? 2 :
74+
Status.code == #Canceled OR Status.code == #Blocked ? 1 : 0
7975
),
8076
},
8177
{ Value : BeginDate },
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
code;name
22
O;Open
3+
R;InReview
4+
B;Blocked
35
A;Accepted
46
X;Canceled

0 commit comments

Comments
 (0)