Skip to content

Commit a2acd8b

Browse files
authored
Use annotation expressions (#1477)
1 parent 686f55c commit a2acd8b

7 files changed

Lines changed: 1278 additions & 2900 deletions

File tree

app/labels.cds

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ annotate schema.Travel with @title: '{i18n>Travel}' {
1010
BeginDate @title: '{i18n>BeginDate}';
1111
EndDate @title: '{i18n>EndDate}';
1212
Description @title: '{i18n>Description}';
13-
BookingFee @title: '{i18n>BookingFee}' @Measures.ISOCurrency: CurrencyCode_code;
14-
TotalPrice @title: '{i18n>TotalPrice}' @Measures.ISOCurrency: CurrencyCode_code;
13+
BookingFee @title: '{i18n>BookingFee}' @Measures.ISOCurrency: (CurrencyCode.code);
14+
TotalPrice @title: '{i18n>TotalPrice}' @Measures.ISOCurrency: (CurrencyCode.code);
1515
GoGreen @title: '{i18n>GoGreen}';
16-
GreenFee @title: '{i18n>GreenFee}' @Measures.ISOCurrency: CurrencyCode_code;
16+
GreenFee @title: '{i18n>GreenFee}' @Measures.ISOCurrency: (CurrencyCode.code);
1717
TreesPlanted @title: '{i18n>TreesPlanted}';
1818
TravelStatus @title: '{i18n>TravelStatus}' @Common.Text: TravelStatus.name @Common.TextArrangement: #TextOnly;
1919
to_Customer @title: '{i18n>CustomerID}' @Common.Text: to_Customer.LastName;
@@ -32,7 +32,7 @@ annotate schema.Booking with @title: '{i18n>Booking}' {
3232
ConnectionID @title: '{i18n>ConnectionID}';
3333
CurrencyCode @title: '{i18n>CurrencyCode}';
3434
FlightDate @title: '{i18n>FlightDate}';
35-
FlightPrice @title: '{i18n>FlightPrice}' @Measures.ISOCurrency: CurrencyCode_code;
35+
FlightPrice @title: '{i18n>FlightPrice}' @Measures.ISOCurrency: (CurrencyCode.code);
3636
BookingStatus @title: '{i18n>BookingStatus}' @Common.Text: BookingStatus.name @Common.TextArrangement: #TextOnly;
3737
to_Carrier @title: '{i18n>AirlineID}' @Common.Text: to_Carrier.Name;
3838
to_Customer @title: '{i18n>CustomerID}' @Common.Text: to_Customer.LastName;
@@ -47,7 +47,7 @@ annotate schema.BookingSupplement with @title: '{i18n>BookingSupplement}' {
4747
to_Booking @UI.Hidden;
4848
to_Travel @UI.Hidden;
4949
to_Supplement @title: '{i18n>SupplementID}' @Common.Text: to_Supplement.Description;
50-
Price @title: '{i18n>Price}' @Measures.ISOCurrency: CurrencyCode_code;
50+
Price @title: '{i18n>Price}' @Measures.ISOCurrency: (CurrencyCode.code);
5151
BookingSupplementID @title: '{i18n>BookingSupplementID}';
5252
CurrencyCode @title: '{i18n>CurrencyCode}';
5353
}
@@ -88,15 +88,15 @@ annotate schema.Flight with @title: '{i18n>Flight}' {
8888
FlightDate @title: '{i18n>FlightDate}';
8989
ConnectionID @title: '{i18n>ConnectionID}';
9090
CurrencyCode @title: '{i18n>CurrencyCode}';
91-
Price @title: '{i18n>Price}' @Measures.ISOCurrency: CurrencyCode_code;
91+
Price @title: '{i18n>Price}' @Measures.ISOCurrency: (CurrencyCode.code);
9292
PlaneType @title: '{i18n>PlaneType}';
9393
MaximumSeats @title: '{i18n>MaximumSeats}';
9494
OccupiedSeats @title: '{i18n>OccupiedSeats}';
9595
}
9696

9797
annotate schema.Supplement with @title: '{i18n>Supplement}' {
9898
SupplementID @title: '{i18n>SupplementID}' @Common.Text: Description;
99-
Price @title: '{i18n>Price}' @Measures.ISOCurrency: CurrencyCode_code;
99+
Price @title: '{i18n>Price}' @Measures.ISOCurrency: (CurrencyCode.code);
100100
CurrencyCode @title: '{i18n>CurrencyCode}';
101101
Description @title: '{i18n>Description}';
102102
}

app/travel_processor/field-control.cds

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ using TravelService from '../../srv/travel-service';
44
// annotations that control the behavior of fields and actions
55
//
66

7+
8+
using { sap.fe.cap.travel.TravelStatus } from '../../db/schema';
9+
10+
// As we use field control based on travel status for many elements, we do the computation in a calculated element
11+
// right here instead of repeating the same expression in multiple annotations
12+
extend TravelStatus with {
13+
// can't use UInt8 (which would automatically be mapped to Edm.Byte) because it's not supported on H2
14+
fieldControl: Int16 @odata.Type:'Edm.Byte' enum {Inapplicable = 0; ReadOnly = 1; Optional = 3; Mandatory = 7;}
15+
= (code = #Accepted ? #ReadOnly : #Mandatory );
16+
}
17+
18+
719
annotate TravelService.Travel with @(Common : {
820
SideEffects: {
921
SourceProperties: [BookingFee],
@@ -22,15 +34,15 @@ annotate TravelService.Travel with @(Common : {
2234

2335
} actions {
2436
rejectTravel @(
25-
Core.OperationAvailable : { $edmJson: { $Ne: [{ $Path: 'in/TravelStatus_code'}, 'X']}},
37+
Core.OperationAvailable : ($self.TravelStatus.code != #Canceled),
2638
Common.SideEffects.TargetProperties : ['in/TravelStatus_code'],
2739
);
2840
acceptTravel @(
29-
Core.OperationAvailable : { $edmJson: { $Ne: [{ $Path: 'in/TravelStatus_code'}, 'A']}},
41+
Core.OperationAvailable : ($self.TravelStatus.code != #Accepted),
3042
Common.SideEffects.TargetProperties : ['in/TravelStatus_code'],
3143
);
3244
deductDiscount @(
33-
Core.OperationAvailable : { $edmJson: { $Eq: [{ $Path: 'in/TravelStatus_code'}, 'O']}},
45+
Core.OperationAvailable : ($self.TravelStatus.code = #Open),
3446
Common.SideEffects.TargetProperties : ['in/TotalPrice', 'in/BookingFee'],
3547
);
3648
}
@@ -45,8 +57,8 @@ annotate TravelService.Travel @(
4557
}
4658
);
4759

48-
annotate TravelService.Booking with @UI.CreateHidden : to_Travel.TravelStatus.createDeleteHidden;
49-
annotate TravelService.Booking with @UI.DeleteHidden : to_Travel.TravelStatus.createDeleteHidden;
60+
annotate TravelService.Booking with @UI.CreateHidden : (to_Travel.TravelStatus.code != #Open);
61+
annotate TravelService.Booking with @UI.DeleteHidden : (to_Travel.TravelStatus.code != #Open);
5062

5163
annotate TravelService.Booking {
5264
BookingDate @Core.Computed;
@@ -64,10 +76,10 @@ annotate TravelService.Booking with @(
6476
{
6577
NavigationProperty : to_BookSupplement,
6678
InsertRestrictions : {
67-
Insertable : to_Travel.TravelStatus.insertDeleteRestriction
79+
Insertable : (to_Travel.TravelStatus.code = #Open)
6880
},
6981
DeleteRestrictions : {
70-
Deletable : to_Travel.TravelStatus.insertDeleteRestriction
82+
Deletable : (to_Travel.TravelStatus.code = #Open)
7183
}
7284
}
7385
]
@@ -80,5 +92,4 @@ annotate TravelService.BookingSupplement {
8092
to_Supplement @Common.FieldControl : to_Travel.TravelStatus.fieldControl;
8193
to_Booking @Common.FieldControl : to_Travel.TravelStatus.fieldControl;
8294
to_Travel @Common.FieldControl : to_Travel.TravelStatus.fieldControl;
83-
8495
};

app/travel_processor/layouts.cds

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ annotate TravelService.Travel with @UI : {
4646
@UI.Importance : #High
4747
},
4848
{
49-
Value : to_Agency_AgencyID,
49+
Value : (to_Agency.AgencyID),
5050
@HTML5.CssDefaults: {width:'16em'}
5151
},
5252
{
53-
Value : to_Customer_CustomerID,
53+
Value : (to_Customer.CustomerID),
5454
@UI.Importance : #High,
5555
@HTML5.CssDefaults: {width:'14em'}
5656
},
@@ -59,9 +59,8 @@ annotate TravelService.Travel with @UI : {
5959
{ Value : BookingFee, @HTML5.CssDefaults: {width:'10em'} },
6060
{ Value : TotalPrice, @HTML5.CssDefaults: {width:'12em'} },
6161
{
62-
Value : TravelStatus_code,
63-
Criticality : { $edmJson: { $If: [{$Eq: [{ $Path: 'TravelStatus_code'}, 'O']}, 2,
64-
{ $If: [{$Eq: [{ $Path: 'TravelStatus_code'}, 'A']}, 3, 0] }] } },
62+
Value : (TravelStatus.code),
63+
Criticality : (TravelStatus.code = #Open ? 2 : (TravelStatus.code = #Accepted ? 3 : 0)),
6564
@UI.Importance : #High,
6665
@HTML5.CssDefaults: {width:'10em'}
6766
}
@@ -99,14 +98,13 @@ annotate TravelService.Travel with @UI : {
9998
}],
10099
FieldGroup#TravelData : { Data : [
101100
{ Value : TravelID },
102-
{ Value : to_Agency_AgencyID },
103-
{ Value : to_Customer_CustomerID },
101+
{ Value : (to_Agency.AgencyID) },
102+
{ Value : (to_Customer.CustomerID) },
104103
{ Value : Description },
105104
{
106105
$Type : 'UI.DataField',
107-
Value : TravelStatus_code,
108-
Criticality : { $edmJson: { $If: [{$Eq: [{ $Path: 'TravelStatus_code'}, 'O']}, 2,
109-
{ $If: [{$Eq: [{ $Path: 'TravelStatus_code'}, 'A']}, 3, 0] }] } },
106+
Value : (TravelStatus.code),
107+
Criticality : (TravelStatus.code = #Open ? 2 : (TravelStatus.code = #Accepted ? 3 : 0)),
110108
Label : '{i18n>Status}' // label only necessary if differs from title of element
111109
}
112110
]},
@@ -117,7 +115,7 @@ annotate TravelService.Travel with @UI : {
117115
FieldGroup #PriceData : {Data : [
118116
{ $Type : 'UI.DataField', Value : BookingFee },
119117
{ $Type : 'UI.DataField', Value : TotalPrice },
120-
{ $Type : 'UI.DataField', Value : CurrencyCode_code }
118+
{ $Type : 'UI.DataField', Value : (CurrencyCode.code) }
121119
]},
122120
FieldGroup #i18nSustainability: {
123121
$Type: 'UI.FieldGroupType',
@@ -161,14 +159,13 @@ annotate TravelService.Booking with @UI : {
161159
{ Value : to_Carrier.AirlinePicURL, Label : ' '},
162160
{ Value : BookingID },
163161
{ Value : BookingDate },
164-
{ Value : to_Customer_CustomerID },
165-
{ Value : to_Carrier_AirlineID },
162+
{ Value : (to_Customer.CustomerID) },
163+
{ Value : (to_Carrier.AirlineID ) },
166164
{ Value : ConnectionID, Label : '{i18n>FlightNumber}' },
167165
{ Value : FlightDate },
168166
{ Value : FlightPrice },
169-
{ Value : BookingStatus_code,
170-
Criticality : { $edmJson: { $If: [{$Eq: [{ $Path: 'BookingStatus_code'}, 'N']}, 2,
171-
{ $If: [{$Eq: [{ $Path: 'BookingStatus_code'}, 'B']}, 3, 0] }] } }
167+
{ Value : (BookingStatus.code),
168+
Criticality : (BookingStatus.code = #New ? 2 : (BookingStatus.code = #Booked ? 3 : 0)),
172169
}
173170
],
174171
Facets : [{
@@ -195,15 +192,14 @@ annotate TravelService.Booking with @UI : {
195192
FieldGroup #GeneralInformation : { Data : [
196193
{ Value : BookingID },
197194
{ Value : BookingDate, },
198-
{ Value : to_Customer_CustomerID },
195+
{ Value : (to_Customer.CustomerID) },
199196
{ Value : BookingDate, },
200-
{ Value : BookingStatus_code,
201-
Criticality : { $edmJson: { $If: [{$Eq: [{ $Path: 'BookingStatus_code'}, 'N']}, 2,
202-
{ $If: [{$Eq: [{ $Path: 'BookingStatus_code'}, 'B']}, 3, 0] }] } }
197+
{ Value : (BookingStatus.code),
198+
Criticality : (BookingStatus.code = #New ? 2 : (BookingStatus.code = #Booked ? 3 : 0)),
203199
}
204200
]},
205201
FieldGroup #Flight : { Data : [
206-
{ Value : to_Carrier_AirlineID },
202+
{ Value : (to_Carrier.AirlineID) },
207203
{ Value : ConnectionID },
208204
{ Value : FlightDate },
209205
{ Value : FlightPrice }
@@ -231,7 +227,7 @@ annotate TravelService.BookingSupplement with @UI : {
231227
},
232228
LineItem : [
233229
{ Value : BookingSupplementID },
234-
{ Value : to_Supplement_SupplementID, Label : '{i18n>ProductID}' },
235-
{ Value : Price, Label : '{i18n>ProductPrice}' }
230+
{ Value : (to_Supplement.SupplementID), Label : '{i18n>ProductID}' },
231+
{ Value : Price, Label : '{i18n>ProductPrice}' }
236232
],
237233
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
code;name;fieldControl;createDeleteHidden;insertDeleteRestriction
2-
O;Open;7;false;true
3-
A;Accepted;1;true;false
4-
X;Canceled;7;true;false
1+
code;name
2+
O;Open
3+
A;Accepted
4+
X;Canceled

db/schema.cds

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,6 @@ type TravelStatusCode : String(1) enum {
8181

8282
entity TravelStatus : CodeList {
8383
key code : TravelStatusCode;
84-
// can't use UInt8 (which would automatically be mapped to Edm.Byte) because it's not supported on H2
85-
fieldControl: Int16 @odata.Type:'Edm.Byte' enum {
86-
Inapplicable = 0;
87-
ReadOnly = 1;
88-
Optional = 3;
89-
Mandatory = 7;
90-
};
91-
createDeleteHidden: Boolean;
92-
insertDeleteRestriction: Boolean; // = NOT createDeleteHidden
9384
}
9485

9586
extend entity Travel with {

0 commit comments

Comments
 (0)