From 7b31657f693412d4c44e1b4c134ecef622172ac1 Mon Sep 17 00:00:00 2001 From: Elena Oresharova Date: Tue, 7 Apr 2020 11:29:11 +0200 Subject: [PATCH] Update --- README.md | 4 ++-- packages/bookshop/db/schema.cds | 17 ++++++++++++++++- packages/bookshop/db/src/.hdiconfig | 10 ++++++---- packages/bookshop/db/src/data/Books.csv | 8 ++++---- .../db/src/sap.capire.bookshop.Books.hdbtable | 3 ++- .../sap.capire.bookshop.BooksDescr.hdbfunction | 10 ++++++++++ .../src/sap.capire.bookshop.BooksInfo.hdbview | 6 ++++++ packages/bookshop/srv/cat-service.cds | 5 ++++- packages/bookshop/tests/CatalogService.http | 8 ++++++++ 9 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 packages/bookshop/db/src/sap.capire.bookshop.BooksDescr.hdbfunction create mode 100644 packages/bookshop/db/src/sap.capire.bookshop.BooksInfo.hdbview create mode 100644 packages/bookshop/tests/CatalogService.http diff --git a/README.md b/README.md index 11237a2d..28a84315 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ In SAP Business Application Studio, open a terminal. Then clone the repo with this specific branch: ```sh -git clone https://github.com/sap-samples/cloud-cap-samples -b openSAP-week3-unit6 -cd cloud-cap-samples +git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week3-unit6 +cd projects/cloud-cap-samples ``` In the `cloud-cap-samples` folder run: diff --git a/packages/bookshop/db/schema.cds b/packages/bookshop/db/schema.cds index a011542e..07ea3829 100644 --- a/packages/bookshop/db/schema.cds +++ b/packages/bookshop/db/schema.cds @@ -2,7 +2,22 @@ namespace sap.capire.bookshop; @cds.persistence.exists entity Books { - key ID: UUID; + key ID: Integer; title : String(111); descr : String(1111); + author : String(50); + rating : Integer; +} + +@cds.persistence.exists +entity BooksDescr { + key id : Integer; + book_descr : String(2000); +} + +@cds.persistence.exists +entity BooksInfo (REQ_RATING : Integer) { + key id : Integer; + rating : Integer; + book_author_info : String; } diff --git a/packages/bookshop/db/src/.hdiconfig b/packages/bookshop/db/src/.hdiconfig index bf908b59..c1016ebe 100644 --- a/packages/bookshop/db/src/.hdiconfig +++ b/packages/bookshop/db/src/.hdiconfig @@ -1,8 +1,10 @@ { "file_suffixes": { - "hdbtable": { "plugin_name": "com.sap.hana.di.table", "plugin_version": "11.1.0" }, - "hdbtabletype": { "plugin_name": "com.sap.hana.di.tabletype", "plugin_version": "11.1.0" }, - "hdbtabledata": { "plugin_name": "com.sap.hana.di.tabledata", "plugin_version": "11.1.0" }, - "csv": { "plugin_name" : "com.sap.hana.di.tabledata.source" } + "hdbtable": { "plugin_name": "com.sap.hana.di.table", "plugin_version": "11.1.0" }, + "hdbview": { "plugin_name": "com.sap.hana.di.view" }, + "hdbfunction": { "plugin_name": "com.sap.hana.di.function" }, + "hdbtabletype": { "plugin_name": "com.sap.hana.di.tabletype", "plugin_version": "11.1.0" }, + "hdbtabledata": { "plugin_name": "com.sap.hana.di.tabledata", "plugin_version": "11.1.0" }, + "csv": { "plugin_name" : "com.sap.hana.di.tabledata.source" } } } \ No newline at end of file diff --git a/packages/bookshop/db/src/data/Books.csv b/packages/bookshop/db/src/data/Books.csv index b68c299e..65a232da 100644 --- a/packages/bookshop/db/src/data/Books.csv +++ b/packages/bookshop/db/src/data/Books.csv @@ -1,4 +1,4 @@ -ID;TITLE;DESCR -301;Anna Karenina;"Anna Karenina (Russian: «Анна Каренина», IPA: [ˈanːə kɐˈrʲenʲɪnə])[1] is a novel by the Russian author Leo Tolstoy, first published in book form in 1878. Many writers consider Anna Karenina the greatest work of literature ever,[2] and Tolstoy himself called it his first true novel. It was initially released in serial installments from 1873 to 1877 in the periodical The Russian Messenger." -307;The Great Gatsby;"The Great Gatsby is a 1925 novel written by American author F. Scott Fitzgerald that follows a cast of characters living in the fictional towns of West Egg and East Egg on prosperous Long Island in the summer of 1922. The story primarily concerns the young and mysterious millionaire Jay Gatsby and his quixotic passion and obsession with the beautiful former debutante Daisy Buchanan. Considered to be Fitzgerald's magnum opus, The Great Gatsby explores themes of decadence, idealism, resistance to change, social upheaval and excess, creating a portrait of the Roaring Twenties that has been described as a cautionary[a] tale regarding the American Dream." -406;Harry Potter;"Harry Potter is a series of fantasy novels written by British author J. K. Rowling. The novels chronicle the lives of a young wizard, Harry Potter, and his friends Hermione Granger and Ron Weasley, all of whom are students at Hogwarts School of Witchcraft and Wizardry. The main story arc concerns Harry's struggle against Lord Voldemort, a dark wizard who intends to become immortal, overthrow the wizard governing body known as the Ministry of Magic and subjugate all wizards and Muggles (non-magical people)." \ No newline at end of file +ID;TITLE;DESCR;AUTHOR;RATING +301;Anna Karenina;"Anna Karenina (Russian: «Анна Каренина», IPA: [ˈanːə kɐˈrʲenʲɪnə])[1] is a novel by the Russian author Leo Tolstoy, first published in book form in 1878. Many writers consider Anna Karenina the greatest work of literature ever,[2] and Tolstoy himself called it his first true novel. It was initially released in serial installments from 1873 to 1877 in the periodical The Russian Messenger.";Leo Tolstoy;4 +307;The Great Gatsby;"The Great Gatsby is a 1925 novel written by American author F. Scott Fitzgerald that follows a cast of characters living in the fictional towns of West Egg and East Egg on prosperous Long Island in the summer of 1922. The story primarily concerns the young and mysterious millionaire Jay Gatsby and his quixotic passion and obsession with the beautiful former debutante Daisy Buchanan. Considered to be Fitzgerald's magnum opus, The Great Gatsby explores themes of decadence, idealism, resistance to change, social upheaval and excess, creating a portrait of the Roaring Twenties that has been described as a cautionary[a] tale regarding the American Dream.";F. Scott Fitzgerald;4 +406;Harry Potter;"Harry Potter is a series of fantasy novels written by British author J. K. Rowling. The novels chronicle the lives of a young wizard, Harry Potter, and his friends Hermione Granger and Ron Weasley, all of whom are students at Hogwarts School of Witchcraft and Wizardry. The main story arc concerns Harry's struggle against Lord Voldemort, a dark wizard who intends to become immortal, overthrow the wizard governing body known as the Ministry of Magic and subjugate all wizards and Muggles (non-magical people).";J. K. Rowling;5 \ No newline at end of file diff --git a/packages/bookshop/db/src/sap.capire.bookshop.Books.hdbtable b/packages/bookshop/db/src/sap.capire.bookshop.Books.hdbtable index 3187dfe9..008bb0bc 100644 --- a/packages/bookshop/db/src/sap.capire.bookshop.Books.hdbtable +++ b/packages/bookshop/db/src/sap.capire.bookshop.Books.hdbtable @@ -1,7 +1,8 @@ --- generated by cds-compiler version 1.23.1-SNAPSHOT COLUMN TABLE SAP_CAPIRE_BOOKSHOP_BOOKS ( ID INTEGER NOT NULL, TITLE NVARCHAR(111), DESCR NVARCHAR(1111), + AUTHOR NVARCHAR(50), + RATING INTEGER, PRIMARY KEY(ID) ) \ No newline at end of file diff --git a/packages/bookshop/db/src/sap.capire.bookshop.BooksDescr.hdbfunction b/packages/bookshop/db/src/sap.capire.bookshop.BooksDescr.hdbfunction new file mode 100644 index 00000000..fbd34112 --- /dev/null +++ b/packages/bookshop/db/src/sap.capire.bookshop.BooksDescr.hdbfunction @@ -0,0 +1,10 @@ +FUNCTION SAP_CAPIRE_BOOKSHOP_BOOKSDESCR + RETURNS TABLE (ID integer, BOOK_DESCR nvarchar(2000)) + LANGUAGE SQLSCRIPT + AS +BEGIN + RETURN SELECT + 100 + ID AS ID, + 'From my HANA function: A summary for the book ' || TITLE || ': ' || DESCR AS BOOK_DESCR + FROM SAP_CAPIRE_BOOKSHOP_BOOKS; +END \ No newline at end of file diff --git a/packages/bookshop/db/src/sap.capire.bookshop.BooksInfo.hdbview b/packages/bookshop/db/src/sap.capire.bookshop.BooksInfo.hdbview new file mode 100644 index 00000000..c288554a --- /dev/null +++ b/packages/bookshop/db/src/sap.capire.bookshop.BooksInfo.hdbview @@ -0,0 +1,6 @@ +VIEW SAP_CAPIRE_BOOKSHOP_BOOKSINFO (in REQ_RATING integer) AS SELECT + ID, + RATING, + 'From my HANA view: The book ' || TITLE || ' is authored by ' || AUTHOR AS BOOK_AUTHOR_INFO +FROM SAP_CAPIRE_BOOKSHOP_BOOKS +WHERE RATING = :REQ_RATING; \ No newline at end of file diff --git a/packages/bookshop/srv/cat-service.cds b/packages/bookshop/srv/cat-service.cds index 3ff4e466..99079572 100644 --- a/packages/bookshop/srv/cat-service.cds +++ b/packages/bookshop/srv/cat-service.cds @@ -1,6 +1,9 @@ using { sap.capire.bookshop as db } from '../db/schema'; - service CatalogService { entity Books as projection on db.Books; + + entity BooksInfo (RATING : Integer) as select from db.BooksInfo(REQ_RATING: :RATING) {*}; + + entity BooksDescr as select from db.BooksDescr; } \ No newline at end of file diff --git a/packages/bookshop/tests/CatalogService.http b/packages/bookshop/tests/CatalogService.http new file mode 100644 index 00000000..b4bf956a --- /dev/null +++ b/packages/bookshop/tests/CatalogService.http @@ -0,0 +1,8 @@ +# Get all books +GET http://localhost:4004/catalog/Books + +# Get books description from the HANA function +GET http://localhost:4004/catalog/BooksDescr + +# Get books with rating 4 via the HANA view +GET http://localhost:4004/catalog/BooksInfo(RATING=4)/Set \ No newline at end of file