Skip to content

Commit 1f94362

Browse files
authored
Merge branch 'main' into d070615-modify-hierarchy
2 parents a84c110 + 1cc55c4 commit 1f94362

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

db/books.cds

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ entity Authors : cuid, managed {
3434
placeOfDeath : String;
3535
books : Association to many Books
3636
on books.author = $self;
37+
details : Map;
3738
}
3839

3940
// annotations for Data Privacy

db/data/my.bookshop-Authors.csv

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
ID;NAME;DATEOFBIRTH;PLACEOFBIRTH;DATEOFDEATH;PLACEOFDEATH
2-
335c7bcd-b826-4f14-a788-e0bf6738617a;Emily Brontë;1818-07-30;Thornton, Yorkshire;1848-12-19;Haworth, Yorkshire
3-
e3da2c2e-72ee-45d5-8def-52964c7b252a;Charlote Brontë;1818-04-21;Thornton, Yorkshire;1855-03-31;Haworth, Yorkshire
4-
e7643aae-2d2f-4656-bb2d-1328ad3c8045;Edgar Allen Poe;1809-01-19;Boston, Massachusetts;1849-10-07;Baltimore, Maryland
5-
3c081d9d-abda-4da9-8b6a-4f4555bb26bc;Richard Carpenter;1929-08-14;King’s Lynn, Norfolk;2012-02-26;Hertfordshire, England
6-
b834ddb0-613a-4edf-8d47-7d80989e1325;Jane Austen;1775-12-16;Steventon, United Kingdom;1817-07-18;Winchester, United Kingdom
7-
a57f75fa-2bda-47b5-ab4d-b644570f29cd;F. Scott Fitzgerald;1896-09-24;Saint Paul, Minnesota;1940-12-21;Los Angeles, California
8-
b22f5293-7eea-49bb-9ee7-17c5de81f1df;Harper Lee;1926-04-28;Monroeville, Alabama;2016-02-19;Monroeville, Alabama
9-
1d2ec887-cbf1-491e-943e-33a2b4f39a6f;Gabriel García Márquez;1927-03-06;Aracataca, Columbia;2014-04-17;Mexico City, Mexico
10-
c0526b1a-9a75-4a43-9133-163325cbbd2b;Truman Capote;1924-09-30;New Orleans, Louisiana;1984-08-25;Los Angeles, California
1+
ID;NAME;DATEOFBIRTH;PLACEOFBIRTH;DATEOFDEATH;PLACEOFDEATH;DETAILS
2+
335c7bcd-b826-4f14-a788-e0bf6738617a;Emily Brontë;1818-07-30;Thornton, Yorkshire;1848-12-19;Haworth, Yorkshire;{"pseudonyms": ["Ellis Bell"]}
3+
e3da2c2e-72ee-45d5-8def-52964c7b252a;Charlote Brontë;1818-04-21;Thornton, Yorkshire;1855-03-31;Haworth, Yorkshire;{"pseudonyms": ["Currer Bell"]}
4+
e7643aae-2d2f-4656-bb2d-1328ad3c8045;Edgar Allen Poe;1809-01-19;Boston, Massachusetts;1849-10-07;Baltimore, Maryland;{"nickname": "The Tomahawk Man"}
5+
3c081d9d-abda-4da9-8b6a-4f4555bb26bc;Richard Carpenter;1929-08-14;King’s Lynn, Norfolk;2012-02-26;Hertfordshire, England;{"nickname": "Kip"}
6+
b834ddb0-613a-4edf-8d47-7d80989e1325;Jane Austen;1775-12-16;Steventon, United Kingdom;1817-07-18;Winchester, United Kingdom;{"pseudonyms": ["By a Lady"], "nickname": "Jenny"}
7+
a57f75fa-2bda-47b5-ab4d-b644570f29cd;F. Scott Fitzgerald;1896-09-24;Saint Paul, Minnesota;1940-12-21;Los Angeles, California;{"nickname": "Scottie"}
8+
b22f5293-7eea-49bb-9ee7-17c5de81f1df;Harper Lee;1926-04-28;Monroeville, Alabama;2016-02-19;Monroeville, Alabama;{"nickname": "Nelle"}
9+
1d2ec887-cbf1-491e-943e-33a2b4f39a6f;Gabriel García Márquez;1927-03-06;Aracataca, Columbia;2014-04-17;Mexico City, Mexico;{"nickname": "Gabo"}
10+
c0526b1a-9a75-4a43-9133-163325cbbd2b;Truman Capote;1924-09-30;New Orleans, Louisiana;1984-08-25;Los Angeles, California;{"nickname": "Bulldog", "pseudonyms": ["Buddy"]}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<cloud.sdk.version>5.15.0</cloud.sdk.version>
2828
<xsuaa.version>3.5.7</xsuaa.version>
2929
<cf-java-logging-support.version>3.8.4</cf-java-logging-support.version>
30-
<cds-feature-attachments.version>1.0.6</cds-feature-attachments.version>
30+
<cds-feature-attachments.version>1.0.7</cds-feature-attachments.version>
3131
</properties>
3232

3333
<modules>

srv/src/main/java/my/bookshop/handlers/CatalogServiceHandler.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
import com.sap.cds.Result;
1515
import com.sap.cds.Struct;
16+
import com.sap.cds.ql.CQL;
1617
import com.sap.cds.ql.Insert;
1718
import com.sap.cds.ql.Select;
1819
import com.sap.cds.ql.Update;
1920
import com.sap.cds.ql.cqn.CqnAnalyzer;
2021
import com.sap.cds.ql.cqn.CqnSelect;
22+
import com.sap.cds.ql.cqn.CqnSelectListItem;
23+
import com.sap.cds.ql.cqn.Modifier;
2124
import com.sap.cds.reflect.CdsModel;
2225
import com.sap.cds.services.ErrorStatuses;
2326
import com.sap.cds.services.ServiceException;
@@ -74,6 +77,21 @@ class CatalogServiceHandler implements EventHandler {
7477
this.analyzer = CqnAnalyzer.create(model);
7578
}
7679

80+
@Before(entity = Books_.CDS_NAME)
81+
public void beforeReadBooks(CdsReadEventContext context) {
82+
CqnSelect copy = CQL.copy(context.getCqn(), new Modifier() {
83+
@Override
84+
public List<CqnSelectListItem> items(List<CqnSelectListItem> items) {
85+
CqnSelectListItem stock = CQL.get("stock");
86+
if (!items.contains(stock)) {
87+
items.add(stock);
88+
}
89+
return items;
90+
}
91+
});
92+
context.setCqn(copy);
93+
}
94+
7795
/**
7896
* Invokes some validations before creating a review.
7997
*
@@ -127,7 +145,6 @@ public void afterAddReview(BooksAddReviewContext context) {
127145
@After(event = CqnService.EVENT_READ)
128146
public void discountBooks(Stream<Books> books) {
129147
books.filter(b -> b.getTitle() != null).forEach(b -> {
130-
loadStockIfNotSet(b);
131148
discountBooksWithMoreThan111Stock(b, featureToggles.isEnabled("discount"));
132149
});
133150
}
@@ -185,10 +202,4 @@ private void discountBooksWithMoreThan111Stock(Books b, boolean premium) {
185202
}
186203
}
187204

188-
private void loadStockIfNotSet(Books b) {
189-
if (b.getId() != null && b.getStock() == null) {
190-
b.setStock(db.run(Select.from(BOOKS).byId(b.getId()).columns(Books_::stock)).single(Books.class).getStock());
191-
}
192-
}
193-
194205
}

0 commit comments

Comments
 (0)