From f6c5e620c0ad011e5a8fa0b23f1c45c4f8e604f9 Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Wed, 10 Nov 2021 09:14:56 +0100 Subject: [PATCH 1/2] In Fiori app, use bookstore consistently This also fixes validation errors from annotation LSP, which missed some of the bookstore elements Signed-off-by: Christian Georgi --- .tours/db-native.tour | 26 +++++++++++++------------- bookstore/index.cds | 4 ++++ fiori/app/admin/fiori-service.cds | 2 +- fiori/app/browse/fiori-service.cds | 2 +- fiori/app/common.cds | 2 +- 5 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 bookstore/index.cds diff --git a/.tours/db-native.tour b/.tours/db-native.tour index caf6f31f..d4d29e21 100644 --- a/.tours/db-native.tour +++ b/.tours/db-native.tour @@ -37,7 +37,7 @@ "title": "Authors service" }, { - "file": "fiori/db/sqlite/index.cds", + "file": "bookstore/db/sqlite/index.cds", "description": "#### SQLite Implementation\n\nHere's the first implementation for SQLite. It computes the two fields `age` and `lifetime` through SQLite's [strftime](https://sqlite.org/lang_datefunc.html) function.\n\nThrough the [`extend projection`](https://cap.cloud.sap/docs/cds/cdl#extend-view) clause you can add additional fields to projection entities. These are deployed as database views, which is why we can integrate the database functions in the first place.\n", "selection": { "start": { @@ -52,8 +52,8 @@ "title": "SQLite implementation" }, { - "file": "fiori/db/hana/index.cds", - "description": "#### SAP HANA Implementation\n\nThis is the second implementation for SAP HANA. It computes the same two fields `age` and `lifetime` through the [YEARS_BETWEEN](https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/7c0d2c161ea34def86de3f5eadd6a0af.html) and [YEAR](https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/20f5fac6751910148dabd3c6821f907d.html) functions of SAP HANA.\n\n#### File Layout and Code Structure\n\nNote the path of the `.cds` file we are in: it's in a subfolder of `db`, so that it's _not_ automatically picked up when we start the application. The same is true for the SQLite implementation: it's in a separate `db/sqlite/` folder as well. In the next step, you'll see how these files are loaded.\n\nAlso, we choose to implement all of that as an extension of the original bookshop here in the _fiori_ package. See the first [CAP Samples] code tour for more details on the different packages of this repository.", + "file": "bookstore/db/hana/index.cds", + "description": "#### SAP HANA Implementation\n\nThis is the second implementation for SAP HANA. It computes the same two fields `age` and `lifetime` through the [YEARS_BETWEEN](https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/7c0d2c161ea34def86de3f5eadd6a0af.html) and [YEAR](https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/20f5fac6751910148dabd3c6821f907d.html) functions of SAP HANA.\n\n#### File Layout and Code Structure\n\nNote the path of the `.cds` file we are in: it's in a subfolder of `db`, so that it's _not_ automatically picked up when we start the application. The same is true for the SQLite implementation: it's in a separate `db/sqlite/` folder as well. In the next step, you'll see how these files are loaded.\n\nAlso, we choose to implement all of that as an extension of the original bookshop here in the _bookstore_ package. See the first [CAP Samples] code tour for more details on the different packages of this repository.", "selection": { "start": { "line": 7, @@ -67,27 +67,27 @@ "title": "SAP HANA implementation" }, { - "file": "fiori/package.json", + "file": "bookstore/package.json", "description": "#### Configuration\n\nThe `cds` section in `package.json` is a place to configure which of the `db/sqlite` and `db/hana` folders are used for which database.\nWe use [Node.js profiles](https://cap.cloud.sap/docs/node.js/cds-env#profiles) to separate the configuration.\nIn the `development` profile, you can see that `db/sqlite` is set as the model, while the `db/hana` folder is configured in the `production` profile.", - "line": 17, + "line": 12, "title": "Configuration" }, { - "file": "fiori/package.json", - "description": "#### Run with SQLite\n\nTo run with `development` and an in-memory SQLite database, you don't need to do anything special, because it's activated by default. Just run:\n\n>> cds watch fiori\n\nThen open [http://localhost:4004/admin/Authors](http://localhost:4004/admin/Authors) to see the two new fields.\n", - "line": 28, + "file": "bookstore/package.json", + "description": "#### Run with SQLite\n\nTo run with `development` and an in-memory SQLite database, you don't need to do anything special, because it's activated by default. Just run:\n\n>> cds watch bookstore\n\nThen open [http://localhost:4004/admin/Authors](http://localhost:4004/admin/Authors) to see the two new fields.\n", + "line": 30, "title": "Run with SQLite" }, { - "file": "fiori/package.json", - "description": "#### Deploy the CDS Model to SAP HANA\n\nTo 'activate' SAP HANA through the `production` profile, you can use the global `--production` flag:\n\n>> cd fiori; cds deploy --to hana --production\n\n[Learn more about SAP HANA deployment](https://cap.cloud.sap/docs/guides/databases#get-hana)\n\n#### Run the Application\n\n>> cd fiori; cds watch --production\n\nThe service on [http://localhost:4004/admin/Authors](http://localhost:4004/admin/Authors) is the same as before, but this time the `Authors` entity is backed by a database view with an SAP HANA function.\n\n#### More\n\nIf you don't see data, you can add some in the next step.", - "line": 31, + "file": "bookstore/package.json", + "description": "#### Deploy the CDS Model to SAP HANA\n\nTo 'activate' SAP HANA through the `production` profile, you can use the global `--production` flag:\n\n>> cd bookstore; cds deploy --to hana --production\n\n[Learn more about SAP HANA deployment](https://cap.cloud.sap/docs/guides/databases#get-hana)\n\n#### Run the Application\n\n>> cd bookstore; cds watch --production\n\nThe service on [http://localhost:4004/admin/Authors](http://localhost:4004/admin/Authors) is the same as before, but this time the `Authors` entity is backed by a database view with an SAP HANA function.\n\n#### More\n\nIf you don't see data, you can add some in the next step.", + "line": 33, "title": "Run with SAP HANA" }, { - "file": "fiori/test/requests.http", + "file": "bookstore/test/requests.http", "description": "### Add More Data\n\nOptionally you can add some `Authors` data by clicking on the _Send Request_ link (provided by the [REST client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension).", - "line": 68, + "line": 72, "selection": { "start": { "line": 67, diff --git a/bookstore/index.cds b/bookstore/index.cds new file mode 100644 index 00000000..4b86c023 --- /dev/null +++ b/bookstore/index.cds @@ -0,0 +1,4 @@ +namespace sap.capire.bookshop; //> important for reflection + +using from '@capire/bookshop'; +using from './db/schema'; diff --git a/fiori/app/admin/fiori-service.cds b/fiori/app/admin/fiori-service.cds index fc1987cb..14d00a55 100644 --- a/fiori/app/admin/fiori-service.cds +++ b/fiori/app/admin/fiori-service.cds @@ -1,4 +1,4 @@ -using { AdminService } from '@capire/bookshop'; +using { AdminService } from '@capire/bookstore'; using from '../common'; // to help UI linter get the complete annotations //////////////////////////////////////////////////////////////////////////// diff --git a/fiori/app/browse/fiori-service.cds b/fiori/app/browse/fiori-service.cds index 352e52f5..47659669 100644 --- a/fiori/app/browse/fiori-service.cds +++ b/fiori/app/browse/fiori-service.cds @@ -1,4 +1,4 @@ -using CatalogService from '@capire/bookshop'; +using CatalogService from '@capire/bookstore'; //////////////////////////////////////////////////////////////////////////// // diff --git a/fiori/app/common.cds b/fiori/app/common.cds index b609498d..9139f717 100644 --- a/fiori/app/common.cds +++ b/fiori/app/common.cds @@ -2,7 +2,7 @@ Common Annotations shared by all apps */ -using { sap.capire.bookshop as my } from '@capire/bookshop'; +using { sap.capire.bookshop as my } from '@capire/bookstore'; using { sap.common } from '@capire/common'; //////////////////////////////////////////////////////////////////////////// From 769aa2b4f5c26029f2830be7f989c6c791116f97 Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Thu, 18 Nov 2021 15:34:59 +0100 Subject: [PATCH 2/2] Adjust samples tour to bookstore --- .tours/samples.tour | 19 +++++++++++-------- samples.md | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.tours/samples.tour b/.tours/samples.tour index b3a15c28..3b04a690 100644 --- a/.tours/samples.tour +++ b/.tours/samples.tour @@ -19,7 +19,7 @@ } }, { - "file": "hello/world.cds", + "file": "hello/srv/world.cds", "description": "### Hello World!\n\nThis is a simplistic [Hello World](https://cap.cloud.sap/docs/get-started/hello-world) service using [CDS](https://cap.cloud.sap/docs/cds/) and [cds.services](https://cap.cloud.sap/docs/node.js/api#services-api).", "line": 2, "selection": { @@ -68,7 +68,7 @@ }, { "file": "orders/db/schema.cds", - "description": "### Compositions and Serving Documents\n\nA standalone orders management service, demonstrating:\n- Using [Compositions](https://cap.cloud.sap/docs/cds/cdl#compositions) in [Domain Models](https://cap.cloud.sap/docs/guides/domain-models), along with\n- [Serving deeply nested documents](https://cap.cloud.sap/docs/guides/generic-providers#serving-structured-data)\n", + "description": "### Orders - Compositions and Serving Documents\n\nA standalone orders management service, demonstrating:\n- Using [Compositions](https://cap.cloud.sap/docs/cds/cdl#compositions) in [Domain Models](https://cap.cloud.sap/docs/guides/domain-models), along with\n- [Serving deeply nested documents](https://cap.cloud.sap/docs/guides/generic-providers#serving-structured-data)\n", "line": 1, "selection": { "start": { @@ -84,7 +84,7 @@ }, { "file": "reviews/db/schema.cds", - "description": "### More Modularity\n\nShows how to implement a modular service to manage product reviews, including:\n- Consuming other services synchronously and asynchronously\n- Serving requests synchronously\n- Emitting events asynchronously\n- Grow as you go, with:\n- Mocking app services\n- Running service meshes\n- Late-cut Micro Services\n- As well as managed data, input validations, and authorization\n", + "description": "### Reviews - More Modularity\n\nShows how to implement a modular service to manage product reviews, including:\n- Consuming other services synchronously and asynchronously\n- Serving requests synchronously\n- Emitting events asynchronously\n- Grow as you go, with:\n- Mocking app services\n- Running service meshes\n- Late-cut Micro Services\n- As well as managed data, input validations, and authorization\n", "line": 1, "selection": { "start": { @@ -99,8 +99,12 @@ "title": "Reviews" }, { - "file": "fiori/app/index.cds", - "description": "### Annotations for SAP Fiori Elements\n\nA [composite app, reusing and combining](https://cap.cloud.sap/docs/guides/verticalize) these packages:\n - [@capire/bookshop](bookshop)\n - [@capire/reviews](reviews)\n - [@capire/orders](orders)\n - [@capire/common](common)\n\n[Adds a SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookshop, thereby introducing to:\n - [OData Annotations](https://cap.cloud.sap/docs/guides/fiori#adding-odata-annotations) in `.cds` files\n - Support for [Fiori Draft](https://cap.cloud.sap/docs/guides/fiori#draft)\n - Support for [Value Helps](https://cap.cloud.sap/docs/guides/fiori#value-help)\n - Serving SAP Fiori apps locally\n\n[The Vue.js app](bookshop/app/vue) imported from bookshop is served as well.\n", + "title": "Bookstore", + "description": "### Bookstore - Reuse and UI\n\n- A [composite app, reusing and combining](https://cap.cloud.sap/docs/guides/reuse-and-compose) these packages:\n - [@capire/bookshop](bookshop)\n - [@capire/reviews](reviews)\n - [@capire/orders](orders)\n - [@capire/common](common)\n- [The Vue.js app](bookshop/app/vue) imported from bookshop is served as well\n- [The Vue.js app](reviews/app/vue) imported from reviews is served as well\n- [The Fiori app](orders/app) imported from orders is served as well\n- [OpenAPI export + Swagger UI](https://cap.cloud.sap/docs/advanced/openapi)" + }, + { + "file": "fiori/app/services.cds", + "description": "### Annotations for SAP Fiori Elements\n\n- [Adds an SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookstore, thereby introducing to:\n- [OData Annotations](https://cap.cloud.sap/docs/guides/fiori#adding-odata-annotations) in `.cds` files\n- Support for [Fiori Draft](https://cap.cloud.sap/docs/guides/fiori#draft)\n- Support for [Value Helps](https://cap.cloud.sap/docs/guides/fiori#value-help)\n- Serving SAP Fiori apps locally\n", "line": 1, "selection": { "start": { @@ -117,14 +121,13 @@ { "file": "package.json", "description": "### All-in-one Monorepo\n\nEach sample sub directory essentially is a standard npm package, some with standard npm dependencies to other samples. The root folder's [package.json](package.json) has local links to the sub folders, such that an `npm install` populates a local `node_modules` folder acts like a local npm registry to the individual sample packages.\n", - "line": 8, "selection": { "start": { "line": 8, "character": 1 }, "end": { - "line": 15, + "line": 16, "character": 1 } }, @@ -133,4 +136,4 @@ ], "isPrimary": true, "description": "Overview of CAP Samples for Node.js" -} +} \ No newline at end of file diff --git a/samples.md b/samples.md index 3e435561..c03f8fb0 100644 --- a/samples.md +++ b/samples.md @@ -67,7 +67,7 @@ Each sub directory essentially is an individual npm package arranged in an [all- ## [@capire/fiori](fiori) -- [Adds an SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookshop, thereby introducing to: +- [Adds an SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookstore, thereby introducing to: - [OData Annotations](https://cap.cloud.sap/docs/guides/fiori#adding-odata-annotations) in `.cds` files - Support for [Fiori Draft](https://cap.cloud.sap/docs/guides/fiori#draft) - Support for [Value Helps](https://cap.cloud.sap/docs/guides/fiori#value-help)