Skip to content

Commit e177ccc

Browse files
authored
Adaptations for 4.7.0 (#45)
- Improve handling of https://github.com/Assert on associations - Use $now as default for Date again
1 parent 52d53fd commit e177ccc

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<!-- DEPENDENCIES VERSION -->
2121
<jdk.version>21</jdk.version>
22-
<cds.services.version>4.6.2</cds.services.version>
22+
<cds.services.version>4.7.0</cds.services.version>
2323
<spring.boot.version>3.5.10</spring.boot.version>
2424
<sap.cloud.sdk.version>5.26.0</sap.cloud.sdk.version>
2525

srv/src/main/java/sap/capire/xtravels/handler/CreationHandler.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.sap.cds.services.handler.EventHandler;
1414
import com.sap.cds.services.handler.annotations.Before;
1515
import com.sap.cds.services.handler.annotations.ServiceName;
16-
import java.time.LocalDate;
1716
import org.springframework.stereotype.Component;
1817

1918
@Component
@@ -41,10 +40,8 @@ void calculateTravelId(final Travels travel) {
4140

4241
if (travel.getBookings() != null) {
4342
int nextPos = 1;
44-
LocalDate now = LocalDate.now(); // $now uses timestamp unexpectedly
4543
for (Bookings booking : travel.getBookings()) {
4644
booking.setPos(nextPos++);
47-
booking.setBookingDate(now);
4845
}
4946
}
5047
}
@@ -60,6 +57,5 @@ void calculateBookingPos(Bookings_ ref, final Bookings booking) {
6057
int pos = (int) maxPos;
6158
booking.setPos(++pos);
6259
}
63-
booking.setBookingDate(LocalDate.now());
6460
}
6561
}

srv/src/test/java/sap/capire/xtravels/handler/TravelServiceTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.sap.cds.Result;
1414
import com.sap.cds.ql.Insert;
1515
import com.sap.cds.ql.cqn.CqnInsert;
16-
import com.sap.cds.services.utils.CdsErrorStatuses;
1716
import java.math.BigDecimal;
1817
import java.util.List;
1918
import org.junit.jupiter.api.Test;
@@ -62,8 +61,8 @@ public void testCreateTravel_CustomerIsNull() {
6261
assertThatServiceException()
6362
.isThrownBy(() -> srv.run(insert))
6463
.isBadRequest()
65-
.withMessageOrKey(CdsErrorStatuses.VALUE_REQUIRED.getCodeString())
66-
.thatTargets("Customer");
64+
.withMessageOrKey("409003") // @mandatory
65+
.thatTargets("Customer_ID", "Customer.ID");
6766
}
6867

6968
@Test
@@ -76,7 +75,7 @@ public void testCreateTravel_CustomerDoesNotExist() {
7675
.isThrownBy(() -> srv.run(insert))
7776
.isBadRequest()
7877
.withMessageOrKey("Customer does not exist")
79-
.thatTargets("Customer_ID");
78+
.thatTargets("Customer", "Customer_ID");
8079
}
8180

8281
@Test
@@ -89,7 +88,7 @@ public void testCreateTravel_AgencyDoesNotExist() {
8988
.isThrownBy(() -> srv.run(insert))
9089
.isBadRequest()
9190
.withMessageOrKey("Agency does not exist")
92-
.thatTargets("Agency");
91+
.thatTargets("Agency", "Agency_ID");
9392
}
9493

9594
@Test

srv/travel-constraints.cds

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ annotate TravelService.Travels with {
88
end);
99

1010
Agency @assert: (case
11+
when Agency is null then null // handled by @mandatory
1112
when not exists Agency then 'Agency does not exist'
1213
end);
1314

1415
Customer @assert: (case
15-
when Customer is null then 'Customer must be specified'
16+
when Customer is null then null // handled by @mandatory
1617
when not exists Customer then 'Customer does not exist'
1718
end);
1819

@@ -26,6 +27,9 @@ annotate TravelService.Travels with {
2627

2728
};
2829

30+
// avoid propagation of @assert to FKs
31+
annotate TravelService.Travels:Agency.ID with @assert: null;
32+
annotate TravelService.Travels:Customer.ID with @assert: null;
2933

3034
annotate TravelService.Bookings with {
3135

0 commit comments

Comments
 (0)