Compare commits

..

30 Commits

Author SHA1 Message Date
Laszlo Kajan
99861ca588 Patch of _reduceStock() under @sap/cds 4 (#136)
* Bump to cds 4
* Cosmetics in handler code
  * await and cds.run([...]) instead of Promise.all

Co-authored-by: Christian Georgi <christian.georgi@sap.com>
2020-09-18 10:49:46 +02:00
Christian Georgi
b5fc3fe4fa Add app/ dir to also also include annotations 2020-06-03 10:15:10 +02:00
Matthias Bühl
b371e10fdf Update README.md 2020-04-07 11:20:55 +02:00
Christian Georgi
9d31d66c78 Add package-lock.json, fix readme 2020-04-02 16:02:32 +02:00
Matthias Bühl
b34b1b0a17 Merge pull request #41 from SAP-samples/remove-insertonly-annotation
remove @insertonly of Orders in CatalogService
2020-03-25 18:19:52 +01:00
d045778
7d39278e79 remove @insertonly of Orders in CatalogService 2020-03-25 16:06:17 +01:00
Matthias Buehl
8395c3fbfc typo README.md 2020-03-24 16:52:01 +01:00
Matthias Buehl
6e5c23bc22 typo README 2020-03-24 16:49:21 +01:00
Matthias Buehl
57803e8f2b correct README 2020-03-24 16:44:28 +01:00
Matthias Buehl
7bbd4ffdb3 correct package.json 2020-03-24 16:27:29 +01:00
Matthias Buehl
ece7aa99cc delete local package.json 2020-03-24 16:07:17 +01:00
Matthias Buehl
e8156ce08a streamline branches 2020-03-24 15:47:03 +01:00
Matthias Buehl
2bf65fb50f Move to standard README and package-lock file 2020-03-24 11:17:23 +01:00
Christian Georgi
23cc571d8a Update readme 2020-03-23 17:09:18 +01:00
Matthias Buehl
50b1f1bb15 delete unused packages 2020-03-20 12:43:13 +01:00
Dominik Nehse
3b818b18c1 Added info on the usage of Windows Powershell
There is a known encoding issue with Windows Powershell that leads to the xs-security.json to not be accepted when creating the xsuaa service instance.
2020-03-19 16:42:24 +01:00
Matthias Bühl
2d7630449c README 2020-02-12 17:07:09 +01:00
Matthias Bühl
f4f41aca52 Update README 2020-02-11 16:43:20 +01:00
Matthias Bühl
a0d63890ac Reset toplevel Package.json 2020-02-06 14:36:07 +01:00
pianocktail
c2ef8c9a69 Merge branch 'OpenSAP-week3-unit5' of https://github.com/SAP-samples/cloud-cap-samples into OpenSAP-week3-unit5 2020-02-06 09:00:58 +00:00
pianocktail
44cf281360 package.json 2020-02-06 09:00:34 +00:00
pianocktail
cfc1ebc881 package.json 2020-02-06 08:37:21 +00:00
pianocktail
fef327f344 "Enable CF Merge branch 'OpenSAP-week3-unit5' of https://github.com/SAP-samples/cloud-cap-samples into OpenSAP-week3-unit5 2020-02-06 08:33:34 +00:00
pianocktail
9932d02d57 CF enablement 2020-02-06 08:27:57 +00:00
Matthias Bühl
cad3a32c78 Add model": "srv" in package.json 2020-02-03 12:44:13 +01:00
Matthias Bühl
05a5a68463 add HANATRIAL to MTA.YAML 2020-02-03 10:30:28 +01:00
Matthias Bühl
73cf655715 instance based restriction in catalogservice 2020-02-03 09:26:33 +01:00
Matthias Bühl
3c094c201b XSUAA 2020-01-31 15:59:43 +01:00
Matthias Bühl
a458c7bb0d cleanup 2020-01-30 17:48:32 +01:00
Matthias Bühl
e0e330c43a XSUAA Config 1 2020-01-30 17:32:23 +01:00
200 changed files with 3177 additions and 11449 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1 +0,0 @@
../../../bookshop/app/vue

View File

@@ -1 +0,0 @@
../../../orders/app/orders

View File

@@ -1 +0,0 @@
../../../reviews/app/vue

View File

@@ -1,41 +0,0 @@
{
"welcomeFile": "app/bookshop/index.html",
"routes": [
{
"source": "^/app/(.*)$",
"target": "$1",
"localDir": "resources",
"cacheControl": "no-cache, no-store, must-revalidate"
},
{
"source": "^/admin/(.*)$",
"target": "/admin/$1",
"destination": "bookstore-api",
"csrfProtection": true
},
{
"source": "^/browse/(.*)$",
"target": "/browse/$1",
"destination": "bookstore-api",
"csrfProtection": true
},
{
"source": "^/user/(.*)$",
"target": "/user/$1",
"destination": "bookstore-api",
"csrfProtection": true
},
{
"source": "^/odata/v4/orders/(.*)$",
"target": "/odata/v4/orders/$1",
"destination": "orders-api",
"csrfProtection": true
},
{
"source": "^/reviews/(.*)$",
"target": "/reviews/$1",
"destination": "reviews-api",
"csrfProtection": true
}
]
}

24
.eslintrc Normal file
View File

@@ -0,0 +1,24 @@
{
"extends": "eslint:recommended",
"env": {
"node": true,
"es6": true,
"jest": true
},
"parserOptions": {
"ecmaVersion": 2018
},
"globals": {
"SELECT": true,
"INSERT": true,
"UPDATE": true,
"DELETE": true,
"CREATE": true,
"DROP": true,
"cds": true
},
"rules": {
"no-console": "off",
"require-atomic-updates": "off"
}
}

View File

@@ -1,5 +0,0 @@
blank_issues_enabled: false
contact_links:
- name: This channel is CLOSED.
about: Use SAP community instead
url: https://answers.sap.com/tags/9f13aee1-834c-4105-8e43-ee442775e5ce

View File

@@ -1,23 +0,0 @@
version: 2
updates:
- package-ecosystem: npm
directory: /
versioning-strategy: increase-if-necessary
schedule:
interval: weekly
groups:
production-dependencies:
dependency-type: "production"
development-dependencies:
dependency-type: "development"
ignore:
- dependency-name: "chai"
# chai 5 doesn't work atm w/ cds.test, TODO fix that in cds.test
versions: ["5.x"]
- dependency-name: "chai-as-promised"
# chai-as-promised 8 doesn't work atm w/ cds.test, TODO fix that in cds.test
versions: ["8.x"]
- dependency-name: "express"
# express 5 not supported atm
versions: ["5.x"]

View File

@@ -1,38 +0,0 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22.x, 20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22.x
- run: npm ci
- run: npm run lint

10
.gitignore vendored
View File

@@ -12,14 +12,4 @@ target/
*.mtar
connection.properties
default-env.json
.cdsrc-private.json
packages/messageBox
reviews/msg-box
reviews/db/test.db
*.openapi3.json
*.sqlite
*.db
@types/
@cds-models/

1
.npmrc Normal file
View File

@@ -0,0 +1 @@
registry=https://registry.npmjs.org

View File

@@ -1,29 +0,0 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: cloud-cap-samples
Upstream-Contact: <Christian Georgi (christian.georgi@sap.com)>
Source: https://github.com/SAP-samples/cloud-cap-samples
Disclaimer: The code in this project may include calls to APIs (“API Calls”) of
SAP or third-party products or services developed outside of this project
(“External Products”).
“APIs” means application programming interfaces, as well as their respective
specifications and implementing code that allows software to communicate with
other software.
API Calls to External Products are not licensed under the open source license
that governs this project. The use of such API Calls and related External
Products are subject to applicable additional agreements with the relevant
provider of the External Products. In no event shall the open source license
that governs this project grant any rights in or to any External Products,or
alter, expand or supersede any terms of the applicable additional agreements.
If you have a valid license agreement with SAP for the use of a particular SAP
External Product, then you may make use of any API Calls included in this
projects code for that SAP External Product, subject to the terms of such
license agreement. If you do not have a valid license agreement for the use of
a particular SAP External Product, then you may only make use of any API Calls
in this project for that SAP External Product for your internal, non-productive
and non-commercial test and evaluation of such API Calls. Nothing herein grants
you any rights to use or access any SAP External Product, or provide any third
parties the right to use of access any SAP External Product, through API Calls.
Files: *.*
Copyright: 2019-2025 SAP SE or an SAP affiliate company and cap-cloud-samples
License: Apache-2.0

View File

@@ -1,17 +0,0 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"qwtel.sqlite-viewer",
"sapse.vscode-cds",
"dbaeumer.vscode-eslint",
"mechatroner.rainbow-csv",
"humao.rest-client",
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [
]
}

62
.vscode/launch.json vendored
View File

@@ -6,29 +6,59 @@
"configurations": [
{
"name": "bookshop",
"command": "npx cds watch bookshop",
"type": "node-terminal",
"request": "launch",
"type": "node",
"runtimeExecutable": "npx",
"runtimeArgs": [
"-n"
],
"args": [
"--",
"cds",
"run",
"--in-memory"
],
"cwd": "${workspaceFolder}/packages/bookshop",
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/cds/lib/lazy.js",
"**/cds/lib/req/cds-context.js",
"**/odata-v4/okra/**"
"<node_internals>/**"
]
},
{
"name": "bookstore",
"command": "npx cds watch bookstore",
"type": "node-terminal",
"name": "cds run ...",
"request": "launch",
"type": "node",
"runtimeExecutable": "npx",
"runtimeArgs": [
"-n"
],
"args": [
"--",
"cds",
"run",
"--with-mocks",
"--in-memory?"
],
"cwd": "${workspaceFolder}/packages/${input:service}",
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/cds/lib/lazy.js",
"**/cds/lib/req/cds-context.js",
"**/odata-v4/okra/**"
"<node_internals>/**"
]
}
],
"inputs": [
{
"type": "pickString",
"id": "service",
"description": "Which service do you want to start?",
"options": [
"bookshop",
"bookstore",
"media-server",
"office-supplies",
"reviews-service"
],
"default": "bookshop"
}
]
}
}

14
.vscode/settings.json vendored
View File

@@ -1,16 +1,6 @@
{
"files.exclude": {
"**/node_modules": true,
"LICENSES": true,
".reuse": true
},
"debug.javascript.terminalOptions": {
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/cds/lib/lazy.js",
"**/cds/lib/req/cds-context.js",
"**/odata-v4/okra/**"
]
"**/.gitignore": true,
"**/.vscode": true
}
}

28
.vscode/tasks.json vendored
View File

@@ -1,15 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "jest",
"group": {
"kind": "test",
"isDefault": true
}
}
]
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm", "script": "watch", "path": "packages/bookshop/",
"options": { "env": { "PORT": "4004" }},
"presentation": { "group": "A" }
},
{
"type": "npm", "script": "watch", "path": "packages/reviews-service/",
"options": { "env": { "PORT": "5005" }},
"presentation": { "group": "A" }
}
]
}

391
LICENSE
View File

@@ -1,201 +1,190 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SAP SAMPLE CODE LICENSE AGREEMENT
Please scroll down and read the following SAP Sample Code License Agreement
carefully ("Agreement"). By downloading, installing, or otherwise using the
SAP sample code or any materials that accompany the sample code documentation
(collectively, the "Sample Code"), You agree that this Agreement forms a legally
binding agreement between You ("You" or "Your") and SAP SE, for and on behalf
of itself and its subsidiaries and affiliates (as defined in Section 15 of the
German Stock Corporation Act), and You agree to be bound by all of the terms
and conditions stated in this Agreement. If You are trying to access or download
the Sample Code on behalf of Your employer or as a consultant or agent of a
third party (either "Your Company"), You represent and warrant that You have
the authority to act on behalf of and bind Your Company to the terms of this
Agreement and everywhere in this Agreement that refers to 'You' or 'Your' shall
also include Your Company. If You do not agree to these terms, do not attempt
to access or use the Sample Code.
1. LICENSE: Subject to the terms of this Agreement, SAP grants You a nonexclusive,
non-transferable, non-sublicensable, revocable, royalty-free,
limited license to use, copy, and modify the Sample Code solely for Your internal
business purposes.
2. RESTRICTIONS: You must not use the Sample Code to: (a) impair, degrade or
reduce the performance or security of any SAP products, services or related
technology (collectively, "SAP Products"); (b) enable the bypassing or
circumventing of SAP's license restrictions and/or provide users with access to
the SAP Products to which such users are not licensed; or (c) permit mass data
extraction from an SAP Product to a non-SAP Product, including use,
modification, saving or other processing of such data in the non-SAP Product.
Further, You must not: (i) provide or make the Sample Code available to any
third party other than your authorized employees, contractors and agents
(collectively, “Representatives”) and solely to be used by Your Representatives
for Your own internal business purposes; ii) remove or modify any marks or
proprietary notices from the Sample Code; iii) assign this Agreement, or any
interest therein, to any third party; (iv) use any SAP name, trademark or logo
without the prior written authorization of SAP; or (v) use the Sample Code to
modify an SAP Product or decompile, disassemble or reverse engineer an SAP
Product (except to the extent permitted by applicable law). You are responsible
for any breach of the terms of this Agreement by You or Your Representatives.
3. INTELLECTUAL PROPERTY: SAP or its licensors retain all ownership and
intellectual property rights in and to the Sample Code and SAP Products. In
exchange for the right to use, copy and modify the Sample Code provided under
this Agreement, You covenant not to assert any intellectual property rights in
or to any of Your products, services, or related technology that are based on
or incorporate the Sample Code against any individual or entity in respect of
any current or future SAP Products.
4. SAP AND THIRD PARTY APIS: The Sample Code may include API (application
programming interface) calls to SAP and third-party products or services. The
access or use of the third-party products and services to which the API calls
are directed may be subject to additional terms and conditions between you and
SAP or such third parties. You (and not SAP) are solely responsible for
understanding and complying with any additional terms and conditions that apply
to the access or use of those APIs and/or third-party products and services.
SAP does not grant You any rights in or to these APIs, products or services
under this Agreement.
5. FREE AND OPEN SOURCE COMPONENTS: The Sample Code may include third party
free or open source components ("FOSS Components"). You may have additional
rights in such FOSS Components that are provided by the third party licensors
of those components.
6. THIRD PARTY DEPENDENCIES: The Sample Code may require third party software
dependencies ("Dependencies") for the use or operation of the Sample Code. These
Dependencies may be identified by SAP in Maven POM files, documentation or by
other means. SAP does not grant You any rights in or to such Dependencies under
this Agreement. You are solely responsible for the acquisition, installation
and use of such Dependencies.
7. WARRANTY:
a) If You are located outside the US or Canada: AS THE SAMPLE CODE IS PROVIDED
TO YOU FREE OF CHARGE, SAP DOES NOT GUARANTEE OR WARRANT ANY FEATURES OR
QUALITIES OF THE SAMPLE CODE OR GIVE ANY UNDERTAKING WITH REGARD TO ANY OTHER
QUALITY. NO SUCH WARRANTY OR UNDERTAKING SHALL BE IMPLIED BY YOU FROM ANY
DESCRIPTION IN THE SAMPLE CODE OR ANY OTHER MATERIALS, COMMUNICATION OR
ADVERTISEMENT. IN PARTICULAR, SAP DOES NOT WARRANT THAT THE SAMPLE CODE WILL BE
AVAILABLE UNINTERRUPTED, ERROR FREE, OR PERMANENTLY AVAILABLE. ALL WARRANTY
CLAIMS RESPECTING THE SAMPLE CODE ARE SUBJECT TO THE LIMITATION OF LIABILITY
STIPULATED IN SECTION 8 BELOW.
b) If You are located in the US or Canada: THE SAMPLE CODE IS LICENSED TO YOU
"AS IS", WITHOUT ANY WARRANTY, ESCROW, TRAINING, MAINTENANCE, OR SERVICE
OBLIGATIONS WHATSOEVER ON THE PART OF SAP. SAP MAKES NO EXPRESS OR IMPLIED
WARRANTIES OR CONDITIONS OF SALE OF ANY TYPE WHATSOEVER, INCLUDING BUT NOT
LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND OF FITNESS FOR A PARTICULAR
PURPOSE. IN PARTICULAR, SAP DOES NOT WARRANT THAT THE SAMPLE CODE WILL BE
AVAILABLE UNINTERRUPTED, ERROR FREE, OR PERMANENTLY AVAILABLE. YOU ASSUME ALL
RISKS ASSOCIATED WITH THE USE OF THE SAMPLE CODE, INCLUDING WITHOUT LIMITATION
RISKS RELATING TO QUALITY, AVAILABILITY, PERFORMANCE, DATA LOSS, AND UTILITY IN
A PRODUCTION ENVIRONMENT.
c) For all locations: SAP DOES NOT MAKE ANY REPRESENTATIONS OR WARRANTIES IN
RESPECT OF THIRD PARTY DEPENDENCIES, APIS, PRODUCTS AND SERVICES, INCLUDING BUT
NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND OF FITNESS FOR A
PARTICULAR PURPOSE. IN PARTICULAR, SAP DOES NOT WARRANT THAT THIRDPARTY
DEPENDENCIES, APIS, PRODUCTS AND SERVICES WILL BE AVAILABLE, ERROR FREE,
INTEROPERABLE WITH THE SAMPLE CODE, SUITABLE FOR ANY PARTICULAR PURPOSE OR NONINFRINGING.
YOU ASSUME ALL RISKS ASSOCIATED WITH THE USE OF THIRD
PARTY DEPENDENCIES, APIS, PRODUCTS AND SERVICES, INCLUDING WITHOUT LIMITATION
RISKS RELATING TO QUALITY, AVAILABILITY, PERFORMANCE, DATA LOSS, UTILITY IN A
PRODUCTION ENVIRONMENT, AND NON-INFRINGEMENT. IN NO EVENT WILL SAP BE LIABLE
DIRECTLY OR INDIRECTLY IN RESPECT OF ANY USE OF THIRD PARTY DEPENDENCIES, APIS,
PRODUCTS AND SERVICES BY YOU.
8. LIMITATION OF LIABILITY:
a) If You are located outside the US or Canada: IRRESPECTIVE OF THE LEGAL
REASONS, SAP SHALL ONLY BE LIABLE FOR DAMAGES UNDER THIS AGREEMENT IF SUCH
DAMAGE (I) CAN BE CLAIMED UNDER THE GERMAN PRODUCT LIABILITY ACT OR (II) IS
CAUSED BY INTENTIONAL MISCONDUCT OF SAP OR (III) CONSISTS OF PERSONAL INJURY.
IN ALL OTHER CASES, NEITHER SAP NOR ITS EMPLOYEES, AGENTS AND SUBCONTRACTORS
SHALL BE LIABLE FOR ANY KIND OF DAMAGE OR CLAIMS HEREUNDER.
b) If You are located in the US or Canada: IN NO EVENT SHALL SAP BE LIABLE TO
YOU, YOUR COMPANY OR TO ANY THIRD PARTY FOR ANY DAMAGES IN AN AMOUNT IN EXCESS
OF $100 ARISING IN CONNECTION WITH YOUR USE OF OR INABILITY TO USE THE SAMPLE
CODE OR IN CONNECTION WITH SAP'S PROVISION OF OR FAILURE TO PROVIDE SERVICES
PERTAINING TO THE SAMPLE CODE, OR AS A RESULT OF ANY DEFECT IN THE SAMPLE COED.
THIS DISCLAIMER OF LIABILITY SHALL APPLY REGARDLESS OF THE FORM OF ACTION THAT
MAY BE BROUGHT AGAINST SAP, WHETHER IN CONTRACT OR TORT, INCLUDING WITHOUT
LIMITATION ANY ACTION FOR NEGLIGENCE. YOUR SOLE REMEDY IN THE EVENT OF BREACH
OF THIS AGREEMENT BY SAP OR FOR ANY OTHER CLAIM RELATED TO THE SAMPLE CODE SHALL
BE TERMINATION OF THIS AGREEMENT. NOTWITHSTANDING ANYTHING TO THE CONTRARY
HEREIN, UNDER NO CIRCUMSTANCES SHALL SAP OR ITS LICENSORS BE LIABLE TO YOU OR
ANY OTHER PERSON OR ENTITY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR
INDIRECT DAMAGES, LOSS OF GOOD WILL OR BUSINESS PROFITS, WORK STOPPAGE, DATA
LOSS, COMPUTER FAILURE OR MALFUNCTION, ANY AND ALL OTHER COMMERCIAL DAMAGES OR
LOSS, OR EXEMPLARY OR PUNITIVE DAMAGES.
9. INDEMNITY: You will fully indemnify, hold harmless and defend SAP against
law suits based on any claim: (a) that any of Your products, services or related
technology that are based on or incorporate the Sample Code infringes or
misappropriates any patent, copyright, trademark, trade secrets, or other
proprietary rights of a third party, or (b) related to Your alleged violation
of the terms of this Agreement.
10. EXPORT: The Sample Code is subject to German, EU and US export control
regulations. You confirm that: a) You will not use the Sample Code for, and
will not allow the Sample Code to be used for, any purposes prohibited by
German, EU and US law, including, without limitation, for the development,
design, manufacture or production of nuclear, chemical or biological weapons of
mass destruction; b) You are not located in Cuba, Iran, Sudan, Iraq, North
Korea, Syria, nor any other country to which the United States has prohibited
export or that has been designated by the U.S. Government as a "terrorist
supporting" country (any, an "US Embargoed Country"); c) You are not a citizen,
national or resident of, and are not under the control of, a US Embargoed
Country; d) You will not download or otherwise export or re-export the Sample
Code, directly or indirectly, to a US Embargoed Country nor to citizens,
nationals or residents of a US Embargoed Country; e) You are not listed on the
United States Department of Treasury lists of Specially Designated Nationals,
Specially Designated Terrorists, and Specially Designated Narcotic Traffickers,
nor listed on the United States Department of Commerce Table of Denial Orders
or any other U.S. government list of prohibited or restricted parties and f)
You will not download or otherwise export or re-export the Sample Code, directly
or indirectly, to persons on the above-mentioned lists.
11. SUPPORT: SAP does not offer support for the Sample Code.
12. TERM AND TERMINATION: You may terminate this Agreement by destroying all
copies of the Sample Code in Your possession or control. SAP may terminate Your
license to use the Sample Code immediately if You fail to comply with any of
the terms of this Agreement, or, for SAP's convenience by providing you with
ten (10) days written notice of termination. In case of termination or
expiration of this Agreement, You must immediately destroy all copies of the
Sample Code in your possession or control. In the event Your Company is acquired
(by merger, purchase of stock, assets or intellectual property or exclusive
license), or You become employed, by a direct competitor of SAP, then this
Agreement and all licenses granted to You in this Agreement shall immediately
terminate upon the date of such acquisition or change of employment.
13. LAW/VENUE:
a) If You are located outside the US or Canada: This Agreement is governed by
and construed in accordance with the laws of Germany without reference to its
conflicts of law principles. You and SAP agree to submit to the exclusive
jurisdiction of, and venue in, the courts located in Karlsruhe, Germany in any
dispute arising out of or relating to this Agreement or the Sample Code. The
United Nations Convention on Contracts for the International Sale of Goods shall
not apply to this Agreement.
b) If You are located in the US or Canada: This Agreement shall be governed by
and construed in accordance with the laws of the State of New York, USA without
reference to its conflicts of law principles. You and SAP agree to submit to
the exclusive jurisdiction of, and venue in, the courts located in New York,
New York, USA in any dispute arising out of or relating to this Agreement or
the Sample Code. The United Nations Convention on Contracts for the
International Sale of Goods shall not apply to this Agreement.
14. MISCELLANEOUS: This Agreement is the complete agreement between the parties
respecting the Sample Code. This Agreement supersedes all prior or
contemporaneous agreements or representations with regards to the Sample Code.
If any term of this Agreement is found to be invalid or unenforceable, the
surviving provisions shall remain effective. SAP's failure to enforce any right
or provisions stipulated in this Agreement will not constitute a waiver of such
provision, or any other provision of this Agreement.
v1.0-071618

1
NOTICE Normal file
View File

@@ -0,0 +1 @@
Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.

118
README.md Normal file
View File

@@ -0,0 +1,118 @@
# Welcome to SAP Cloud Application Programming model samples
Find here the samples for the openSAP course [Building Applications with the SAP Cloud Application Programming Model](https://open.sap.com/courses/cp7).
## Get Access to SAP Business Application Studio
The recommended environment for the course is SAP Business Application Studio. Watch [unit 2 of week 1](https://open.sap.com/courses/cp7/items/51pzQUzbXHr2kdbOmVs6jI) for how to get access.
## Setup
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 projects/cloud-cap-samples -b openSAP-week3-unit5
cd projects/cloud-cap-samples
```
In the `cloud-cap-samples` folder run:
```sh
npm install
```
## Run
Now you're ready to run the samples, for example:
```sh
cd packages/bookshop
cds deploy
cds watch
```
After that, watch out for the little popup in the lower right corner of SAP Business Application Studio that asks you to open the application in your browser.
## Hints
- If your demo user logon window does not show up: clear the browsers login data
- If your port is still in use run in your terminal:
```
> pkill node //kill running node proceses
```
## Deploy to Cloud Foundry
Clean-up the CF space in your trial account if you already used it before. Make sure that there are no services or applications deployed.
Generation of the XSUAA service configuration file xs-security.json:
```sh
cds compile srv/ --to xsuaa > xs-security.json
```
In this unit we use [MTA](https://sap.github.io/cloud-mta-build-tool/) to do the deployment to CF
```sh
npm install -g mbt
```
You can generate the MTA.yaml from CDS and do manual modifications or simply use the already generated and adapted mta.yaml in the branch and directly generate the .mtar file
#### BEGIN OPTIONAL PART
If you want to generate the MTA.YAML yourself please do the following:
- Generate the mta.yaml with the HANA dependency
```sh
cds add hana --force
cds add mta
```
- Add the path to the generated xs-security.json in the MTA.YAML
```
parameters:
path: ./xs-security.json
service:xsuaa
service-plan: application
....
```
- Add the application block in the MTA.YAML
```
############## APP #########################
- name: capire-bookshop-app
type: nodejs
path: gen/app
parameters:
memory: 256M
build-parameters:
requires:
- name: capire-bookshop-srv
requires:
- name: capire-bookshop-uaa
- name: srv-binding
group: destinations
properties:
forwardAuthToken: true
name: srv-binding
url: ~{srv-url}
```
- Make sure to use service hanatrial instead of hana in the MTA.YAML
```
parameters:
service: hanatrial
```
#### END OPTIONAL PART
Generate the .mtar file for the deployment and deploy to cloud foundry:
```sh
mbt build -t ./
cf login -a https://api.cf.eu10.hana.ondemand.com
cf deploy sap.capire-bookshop_1.0.0.mtar
```
## Get Support
Check out the cap docs at https://cap.cloud.sap. <br>
In case you find a bug or need support, please [open an issue in here](https://github.com/SAP-samples/cloud-cap-samples/issues/new).
## License
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under SAP Sample Code License Agreement, except as noted otherwise in the [LICENSE](/LICENSE) file.

View File

@@ -1,25 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach to...",
"type": "node",
"request": "attach",
"processId": "${command:PickProcess}",
"skipFiles": ["<node_internals>/**"]
},
{
"name": "cds run",
"type": "node",
"request": "launch",
"runtimeExecutable": "npx",
"runtimeArgs": ["-n"],
"args": ["--", "cds", "run", "--with-mocks", "--in-memory?"],
"console": "integratedTerminal",
"skipFiles": ["<node_internals>/**"]
}
]
}

View File

@@ -1,89 +0,0 @@
/* global Vue axios */ //> from vue.html
const $ = sel => document.querySelector(sel)
const GET = (url) => axios.get('/browse'+url)
const POST = (cmd,data) => axios.post('/browse'+cmd,data)
const books = Vue.createApp ({
data() {
return {
list: [],
book: undefined,
order: { quantity:1, succeeded:'', failed:'' },
user: undefined
}
},
methods: {
search: ({target:{value:v}}) => books.fetch(v && '&$search='+v),
async fetch (etc='') {
const {data} = await GET(`/ListOfBooks?$expand=genre($select=name),currency($select=symbol)${etc}`)
books.list = data.value
},
async inspect (eve) {
const book = books.book = books.list [eve.currentTarget.rowIndex-1]
const res = await GET(`/Books/${book.ID}?$select=descr,stock,image`)
Object.assign (book, res.data)
books.order = { quantity:1 }
setTimeout (()=> $('form > input').focus(), 111)
},
async submitOrder () {
const {book,order} = books, quantity = parseInt (order.quantity) || 1 // REVISIT: Okra should be less strict
try {
const res = await POST(`/submitOrder`, { quantity, book: book.ID })
book.stock = res.data.stock
books.order = { quantity, succeeded: `Successfully ordered ${quantity} item(s).` }
} catch (e) {
books.order = { quantity, failed: e.response.data.error ? e.response.data.error.message : e.response.data }
}
},
async login() {
try {
const { data:user } = await axios.post('/user/login',{})
if (user.id !== 'anonymous') books.user = user
} catch (err) { books.user = { id: err.message } }
},
async getUserInfo() {
try {
const { data:user } = await axios.get('/user/me')
if (user.id !== 'anonymous') books.user = user
} catch (err) { books.user = { id: err.message } }
},
}
}).mount('#app')
books.getUserInfo()
books.fetch() // initially fill list of books
document.addEventListener('keydown', (event) => {
// hide user info on request
if (event.key === 'u') books.user = undefined
})
axios.interceptors.request.use(csrfToken)
function csrfToken (request) {
if (request.method === 'head' || request.method === 'get') return request
if ('csrfToken' in document) {
request.headers['x-csrf-token'] = document.csrfToken
return request
}
return fetchToken().then(token => {
document.csrfToken = token
request.headers['x-csrf-token'] = document.csrfToken
return request
}).catch(() => {
document.csrfToken = null // set mark to not try again
return request
})
function fetchToken() {
return axios.get('/', { headers: { 'x-csrf-token': 'fetch' } })
.then(res => res.headers['x-csrf-token'])
}
}

View File

@@ -1,78 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title> Capire Books </title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/primitive-ui/dist/css/main.css">
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
<style>
.hovering tr:hover td { color:cyan; background: #123; cursor: pointer; }
.rating-stars { color:teal }
.succeeded { color:teal }
.failed { color:red }
.user {text-align: end; color: grey;}
</style>
</head>
<body class="small-container", style="margin-top: 70px;">
<div id='app'>
<form class="user" @submit.prevent="login">
<div v-if="user">
<div v-if="user.tenant">Tenant: {{ user.tenant }}</div>
<div> User: {{ user.id }}</div>
<div>Locale: {{ user.locale }}</div>
</div>
<div v-else>
<input type="submit" value="Login" class="muted-button">
<!-- <a href="/user/login()">Login</a> -->
</div>
</form>
<h1> Capire Books </h1>
<input type="text" placeholder="Search..." @input="search">
<table id='books' class="hovering">
<thead>
<th> Book </th>
<th> Author </th>
<th> Genre </th>
<th> Rating </th>
<th> Price </th>
</thead>
<tr v-for="book in list" v-bind:id="book.ID" v-on:click="inspect">
<td>{{ book.title }}</td>
<td>{{ book.author }}</td>
<td>{{ book.genre.name }}</td>
<td class="rating-stars">
{{ ('★'.repeat(Math.round(book.rating))+'☆☆☆☆☆').slice(0,5) }} ({{ book.numberOfReviews }})
</td>
<td>{{ book.currency && book.currency.symbol }} {{ book.price }}</td>
</tr>
</table>
<div v-if="book">
<img v-bind:src="book.image" alt=""/>
<label style="text-align:right">
<span class="succeeded"> {{ order.succeeded }} </span>
<span class="failed"> {{ order.failed }} </span>
&nbsp;&nbsp; {{ book.stock }} in stock
</label>
<form @submit.prevent="submitOrder" style="float:right; display:flex; flex-direction:row-reverse">
<input type="number" v-model="order.quantity" v-bind:class="{ failed: order.failed }" style="width:5em">
<input type="submit" value="Order:" class="muted-button">
</form>
<h4> {{ book.title }} </h4>
<p> {{ book.descr }} </p>
</div>
<div v-else>
( click on a row to see details... )
</div>
</div>
</body>
<script src="app.js"></script>
</html>

View File

@@ -1,5 +0,0 @@
ID,name,dateOfBirth,placeOfBirth,dateOfDeath,placeOfDeath
101,Emily Brontë,1818-07-30,"Thornton, Yorkshire",1848-12-19,"Haworth, Yorkshire"
107,Charlotte Brontë,1818-04-21,"Thornton, Yorkshire",1855-03-31,"Haworth, Yorkshire"
150,Edgar Allen Poe,1809-01-19,"Boston, Massachusetts",1849-10-07,"Baltimore, Maryland"
170,Richard Carpenter,1929-08-14,"Kings Lynn, Norfolk",2012-02-26,"Hertfordshire, England"
1 ID name dateOfBirth placeOfBirth dateOfDeath placeOfDeath
2 101 Emily Brontë 1818-07-30 Thornton, Yorkshire 1848-12-19 Haworth, Yorkshire
3 107 Charlotte Brontë 1818-04-21 Thornton, Yorkshire 1855-03-31 Haworth, Yorkshire
4 150 Edgar Allen Poe 1809-01-19 Boston, Massachusetts 1849-10-07 Baltimore, Maryland
5 170 Richard Carpenter 1929-08-14 King’s Lynn, Norfolk 2012-02-26 Hertfordshire, England

View File

@@ -1,5 +0,0 @@
ID_texts,ID,locale,title,descr
d2a65a27-9f2a-480f-bc38-84ee8ec5c13e,201,de,Sturmhöhe,"Sturmhöhe (Originaltitel: Wuthering Heights) ist der einzige Roman der englischen Schriftstellerin Emily Brontë (18181848). Der 1847 unter dem Pseudonym Ellis Bell veröffentlichte Roman wurde vom viktorianischen Publikum weitgehend abgelehnt, heute gilt er als ein Klassiker der britischen Romanliteratur des 19. Jahrhunderts."
8c42c706-a979-41cf-9ffe-91e6cf1383a0,201,fr,Les Hauts de Hurlevent,"Les Hauts de Hurlevent (titre original : Wuthering Heights), parfois orthographié Les Hauts de Hurle-Vent, est l'unique roman d'Emily Brontë, publié pour la première fois en 1847 sous le pseudonyme dEllis Bell. Loin d'être un récit moralisateur, Emily Brontë achève néanmoins le roman dans une atmosphère sereine, suggérant le triomphe de la paix et du Bien sur la vengeance et le Mal."
9e1c4c81-dc90-4600-85b1-e9dd4bf12ce0,207,de,Jane Eyre,"Jane Eyre. Eine Autobiographie (Originaltitel: Jane Eyre. An Autobiography), erstmals erschienen im Jahr 1847 unter dem Pseudonym Currer Bell, ist der erste veröffentlichte Roman der britischen Autorin Charlotte Brontë und ein Klassiker der viktorianischen Romanliteratur des 19. Jahrhunderts. Der Roman erzählt in Form einer Ich-Erzählung die Lebensgeschichte von Jane Eyre (ausgesprochen /ˌdʒeɪn ˈɛə/), die nach einer schweren Kindheit eine Stelle als Gouvernante annimmt und sich in ihren Arbeitgeber verliebt, jedoch immer wieder um ihre Freiheit und Selbstbestimmung kämpfen muss. Als klein, dünn, blass, stets schlicht dunkel gekleidet und mit strengem Mittelscheitel beschrieben, gilt die Heldin des Romans Jane Eyre nicht zuletzt aufgrund der Kino- und Fernsehversionen der melodramatischen Romanvorlage als die bekannteste englische Gouvernante der Literaturgeschichte"
9be0524b-4cb9-4fc1-9dc2-d65b1c13cf53,252,de,Eleonora,"“Eleonora” ist eine Erzählung von Edgar Allan Poe. Sie wurde 1841 erstveröffentlicht. In ihr geht es um das Paradox der Treue in der Treulosigkeit."
1 ID_texts ID locale title descr
2 d2a65a27-9f2a-480f-bc38-84ee8ec5c13e 201 de Sturmhöhe Sturmhöhe (Originaltitel: Wuthering Heights) ist der einzige Roman der englischen Schriftstellerin Emily Brontë (1818–1848). Der 1847 unter dem Pseudonym Ellis Bell veröffentlichte Roman wurde vom viktorianischen Publikum weitgehend abgelehnt, heute gilt er als ein Klassiker der britischen Romanliteratur des 19. Jahrhunderts.
3 8c42c706-a979-41cf-9ffe-91e6cf1383a0 201 fr Les Hauts de Hurlevent Les Hauts de Hurlevent (titre original : Wuthering Heights), parfois orthographié Les Hauts de Hurle-Vent, est l'unique roman d'Emily Brontë, publié pour la première fois en 1847 sous le pseudonyme d’Ellis Bell. Loin d'être un récit moralisateur, Emily Brontë achève néanmoins le roman dans une atmosphère sereine, suggérant le triomphe de la paix et du Bien sur la vengeance et le Mal.
4 9e1c4c81-dc90-4600-85b1-e9dd4bf12ce0 207 de Jane Eyre Jane Eyre. Eine Autobiographie (Originaltitel: Jane Eyre. An Autobiography), erstmals erschienen im Jahr 1847 unter dem Pseudonym Currer Bell, ist der erste veröffentlichte Roman der britischen Autorin Charlotte Brontë und ein Klassiker der viktorianischen Romanliteratur des 19. Jahrhunderts. Der Roman erzählt in Form einer Ich-Erzählung die Lebensgeschichte von Jane Eyre (ausgesprochen /ˌdʒeɪn ˈɛə/), die nach einer schweren Kindheit eine Stelle als Gouvernante annimmt und sich in ihren Arbeitgeber verliebt, jedoch immer wieder um ihre Freiheit und Selbstbestimmung kämpfen muss. Als klein, dünn, blass, stets schlicht dunkel gekleidet und mit strengem Mittelscheitel beschrieben, gilt die Heldin des Romans Jane Eyre nicht zuletzt aufgrund der Kino- und Fernsehversionen der melodramatischen Romanvorlage als die bekannteste englische Gouvernante der Literaturgeschichte
5 9be0524b-4cb9-4fc1-9dc2-d65b1c13cf53 252 de Eleonora “Eleonora” ist eine Erzählung von Edgar Allan Poe. Sie wurde 1841 erstveröffentlicht. In ihr geht es um das Paradox der Treue in der Treulosigkeit.

View File

@@ -1,43 +0,0 @@
ID,parent_ID,name
10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,,Fiction
11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Drama
12aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Poetry
13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Fantasy
131aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Fairy Tale
132aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Epic Fantasy
133aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,High Fantasy
134aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Gothic
14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Science Fiction
141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Utopian and Dystopian
1411aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Utopian
1412aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Dystopian
14121aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1412aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Cyberpunk
141211aa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14121aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Steampunk
142aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Space Opera
143aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Time Travel
144aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Tech Noir
15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Romance
151aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Contemporary Romance
152aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Historical Romance
153aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Romantic Suspense
16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Mystery
161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Crime
1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Thriller
16111aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Police Procedural
16112aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Legal Thriller
16113aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Medical Thriller
16114aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Spy Thriller
1612aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Detective
1613aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Suspense
162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Noir
1621aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Nordic Noir
1622aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Tart Noir
163aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Cozy Mystery
17aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Adventure
18aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Short Story
19aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Graphic Novel
20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,,Non-Fiction
21aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Biography
22aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,21aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Autobiography
23aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Essay
24aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa,Speech
1 ID parent_ID name
2 10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Fiction
3 11aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Drama
4 12aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Poetry
5 13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Fantasy
6 131aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Fairy Tale
7 132aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Epic Fantasy
8 133aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa High Fantasy
9 134aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 13aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Gothic
10 14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Science Fiction
11 141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Utopian and Dystopian
12 1411aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Utopian
13 1412aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 141aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Dystopian
14 14121aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 1412aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Cyberpunk
15 141211aa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 14121aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Steampunk
16 142aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Space Opera
17 143aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Time Travel
18 144aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 14aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Tech Noir
19 15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Romance
20 151aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Contemporary Romance
21 152aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Historical Romance
22 153aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 15aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Romantic Suspense
23 16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Mystery
24 161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Crime
25 1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Thriller
26 16111aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Police Procedural
27 16112aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Legal Thriller
28 16113aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Medical Thriller
29 16114aaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 1611aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Spy Thriller
30 1612aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Detective
31 1613aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 161aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Suspense
32 162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Noir
33 1621aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Nordic Noir
34 1622aaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 162aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Tart Noir
35 163aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 16aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Cozy Mystery
36 17aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Adventure
37 18aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Short Story
38 19aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 10aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Graphic Novel
39 20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Non-Fiction
40 21aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Biography
41 22aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 21aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Autobiography
42 23aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Essay
43 24aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa 20aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa Speech

View File

@@ -1,21 +0,0 @@
const cds = require('@sap/cds')
/**
* In order to keep basic bookshop sample as simple as possible, we don't add
* reuse dependencies. This db/init.js ensures we still have a minimum set of
* currencies, if not obtained through @capire/common.
*/
// NOTE: We use cds.on('served') to delay the UPSERTs after the db init
// to run after all INSERTs from .csv files happened.
module.exports = cds.on('served', ()=>
UPSERT.into ('sap.common.Currencies') .columns (
[ 'code', 'symbol', 'name' ]
) .rows (
[ 'EUR', '€', 'Euro' ],
[ 'USD', '$', 'US Dollar' ],
[ 'GBP', '£', 'British Pound' ],
[ 'ILS', '₪', 'Shekel' ],
[ 'JPY', '¥', 'Yen' ],
)
)

View File

@@ -1,38 +0,0 @@
using { Currency, managed, sap } from '@sap/cds/common';
namespace sap.capire.bookshop;
entity Books : managed {
key ID : Integer;
title : localized String(111) @mandatory;
descr : localized String(1111);
author : Association to Authors @mandatory;
genre : Association to Genres;
stock : Integer;
price : Price;
currency : Currency;
image : LargeBinary @Core.MediaType: 'image/png';
}
entity Authors : managed {
key ID : Integer;
name : String(111) @mandatory;
dateOfBirth : Date;
dateOfDeath : Date;
placeOfBirth : String;
placeOfDeath : String;
books : Association to many Books on books.author = $self;
}
/** Hierarchically organized Code List for Genres */
entity Genres : sap.common.CodeList {
key ID : UUID;
parent : Association to Genres;
children : Composition of many Genres on children.parent = $self;
}
type Price : Decimal(9,2);
// ------------------------------------------------------------------
// temporary workaround for reuse in fiori sample and hana deployment
annotate Books with @fiori.draft.enabled;

View File

@@ -1,5 +0,0 @@
namespace sap.capire.bookshop; //> important for reflection
using from './db/schema';
using from './srv/cat-service';
using from './srv/admin-service';
using from './srv/user-service';

View File

@@ -1,23 +0,0 @@
{
"name": "@capire/bookshop",
"version": "1.0.0",
"description": "A simple self-contained bookshop service.",
"files": [
"app",
"srv",
"db",
"index.cds"
],
"devDependencies": {
"@cap-js/sqlite": ">=1"
},
"dependencies": {
"@sap/cds": ">=7",
"express": "^4.17.1"
},
"scripts": {
"genres": "cds serve test/genres.cds",
"start": "cds-serve",
"watch": "cds watch"
}
}

View File

@@ -1,31 +0,0 @@
# Bookshop Getting Started Sample
This stand-alone sample introduces the essential tasks in the development of CAP-based services as also covered in the [Getting Started guide in capire](https://cap.cloud.sap/docs/get-started/in-a-nutshell).
## Hypothetical Use Cases
1. Build a service that allows to browse _Books_ and _Authors_.
2. Books have assigned _Genres_, which are organized hierarchically.
3. All users may browse books without login.
4. All entries are maintained by Administrators.
5. End users may order books (the actual order mgmt being out of scope).
## Running the Sample
```sh
npm run watch
```
## Content & Best Practices
| Links to capire | Sample files / folders |
| --------------------------------------------------------------------------------------------------------- | ------------------------------------ |
| [Project Setup & Layouts](https://cap.cloud.sap/docs/get-started/jumpstart#project-structure) | [`./`](./) |
| [Domain Modeling with CDS](https://cap.cloud.sap/docs/guides/domain-modeling) | [`./db/schema.cds`](./db/schema.cds) |
| [Defining Services](https://cap.cloud.sap/docs/guides/providing-services#modeling-services) | [`./srv/*.cds`](./srv) |
| [Single-purposed Services](https://cap.cloud.sap/docs/guides/providing-services#single-purposed-services) | [`./srv/*.cds`](./srv) |
| [Providing & Consuming Providers](https://cap.cloud.sap/docs/guides/providing-services) | http://localhost:4004 |
| [Using Databases](https://cap.cloud.sap/docs/guides/databases) | [`./db/data/*.csv`](./db/data) |
| [Adding Custom Logic](https://cap.cloud.sap/docs/guides/providing-services#adding-custom-logic) | [`./srv/*.js`](./srv) |
| Adding Tests | [`./test`](./test) |
| [Sharing for Reuse](https://cap.cloud.sap/docs/guides/extensibility/composition) | [`./index.cds`](./index.cds) |

View File

@@ -1,2 +0,0 @@
using { AdminService } from './admin-service';
annotate AdminService with @requires:'admin';

View File

@@ -1,6 +0,0 @@
using { sap.capire.bookshop as my } from '../db/schema';
service AdminService @(path:'/admin') {
entity Authors as projection on my.Authors;
entity Books as projection on my.Books;
entity Genres as projection on my.Genres;
}

View File

@@ -1,14 +0,0 @@
const cds = require('@sap/cds')
module.exports = class AdminService extends cds.ApplicationService { init(){
this.before (['NEW','CREATE'],'Authors', genid)
this.before (['NEW','CREATE'],'Books', genid)
return super.init()
}}
/** Generate primary keys for target entity in request */
async function genid (req) {
if (req.data.ID) return
const {id} = await SELECT.one.from(req.target).columns('max(ID) as id')
req.data.ID = id + 4 // Note: that is not safe! ok for this sample only.
}

View File

@@ -1,16 +0,0 @@
using { sap.capire.bookshop as my } from '../db/schema';
service CatalogService @(path:'/browse') {
/** For displaying lists of Books */
@readonly entity ListOfBooks as projection on Books
excluding { descr };
/** For display in details pages */
@readonly entity Books as projection on my.Books { *,
author.name as author
} excluding { createdBy, modifiedBy };
@requires: 'authenticated-user'
action submitOrder ( book: Books:ID, quantity: Integer ) returns { stock: Integer };
event OrderedBook : { book: Books:ID; quantity: Integer; buyer: String };
}

View File

@@ -1,38 +0,0 @@
const cds = require('@sap/cds')
class CatalogService extends cds.ApplicationService { init() {
const { Books } = cds.entities('sap.capire.bookshop')
const { ListOfBooks } = this.entities
// Add some discount for overstocked books
this.after('each', ListOfBooks, book => {
if (book.stock > 111) book.title += ` -- 11% discount!`
})
// Reduce stock of ordered books if available stock suffices
this.on('submitOrder', async req => {
let { book:id, quantity } = req.data
let book = await SELECT.from (Books, id, b => b.stock)
// Validate input data
if (!book) return req.error (404, `Book #${id} doesn't exist`)
if (quantity < 1) return req.error (400, `quantity has to be 1 or more`)
if (quantity > book.stock) return req.error (409, `${quantity} exceeds stock for book #${id}`)
// Reduce stock in database and return updated stock value
await UPDATE (Books, id) .with ({ stock: book.stock -= quantity })
return book
})
// Emit event when an order has been submitted
this.after('submitOrder', async (_,req) => {
let { book, quantity } = req.data
await this.emit('OrderedBook', { book, quantity, buyer: req.user.id })
})
// Delegate requests to the underlying generic service
return super.init()
}}
module.exports = CatalogService

View File

@@ -1,15 +0,0 @@
/**
* Exposes user information
*/
service UserService @(path: '/user') {
/**
* The current user
*/
@odata.singleton entity me @cds.persistence.skip {
id : String; // user id
locale : String;
tenant : String;
}
action login() returns me;
}

View File

@@ -1,9 +0,0 @@
const cds = require('@sap/cds')
module.exports = class UserService extends cds.Service { init(){
this.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant }))
this.on('login', (req) => {
if (req.user._is_anonymous)
req._.res.set('WWW-Authenticate','Basic realm="Users"').sendStatus(401)
else return this.read('me')
})
}}

View File

@@ -1,844 +0,0 @@
const cds = require('@sap/cds')
const { expect } = cds.test
describe('cds.ql → cqn', () => {
const Foo = { name: 'Foo' }
const Books = { name: 'capire.bookshop.Books' }
const STAR = '*'
const skip = {to:{eql:()=>skip}}
const srv = new cds.Service
let cqn
expect.plain = (cqn) => !cqn.SELECT.one && !cqn.SELECT.distinct ? expect(cqn) : skip
expect.one = (cqn) => !cqn.SELECT.distinct ? expect(cqn) : skip
describe.each(['SELECT', 'SELECT one', 'SELECT distinct'])(`%s...`, (each) => {
let SELECT; beforeEach(()=> SELECT = (
each === 'SELECT distinct' ? cds.ql.SELECT.distinct :
each === 'SELECT one' ? cds.ql.SELECT.one :
cds.ql.SELECT
))
test(`from Foo`, () => {
expect(cqn = SELECT `from Foo`)
.to.eql(SELECT.from `Foo`)
.to.eql(SELECT.from('Foo'))
.to.eql(SELECT.from(Foo))
.to.eql(SELECT`Foo`)
.to.eql(SELECT('Foo'))
.to.eql(SELECT(Foo))
expect.plain(cqn)
.to.eql(CQL`SELECT from Foo`)
.to.eql(srv.read `Foo`)
.to.eql(srv.read('Foo'))
.to.eql(srv.read(Foo))
.to.eql({
SELECT: { from: { ref: ['Foo'] } },
})
})
if (each === 'SELECT')
test('SELECT ( Foo )', () => {
expect({
SELECT: { from: { ref: ['Foo'] } },
})
.to.eql(CQL`SELECT from Foo`)
.to.eql(SELECT(Foo))
})
if (each === 'SELECT')
test('SELECT ( Foo ) .from ( Bar )', () => {
expect({
SELECT: { columns:[{ref:['Foo']}], from: { ref: ['Bar'] } },
})
.to.eql(CQL`SELECT Foo from Bar`)
.to.eql(SELECT `Foo` .from `Bar`)
.to.eql(SELECT `Foo` .from('Bar'))
.to.eql(SELECT('Foo').from('Bar'))
.to.eql(SELECT(['Foo']).from('Bar'))
.to.eql(SELECT(['Foo']).from('Bar'))
.to.eql(SELECT `Bar` .columns `Foo`)
.to.eql(SELECT `Bar` .columns ('Foo'))
.to.eql(SELECT `Bar` .columns (['Foo']))
.to.eql(SELECT.from `Bar` .columns ('Foo'))
.to.eql(SELECT.from `Bar` .columns (['Foo']))
expect({
SELECT: { columns:[
{ref:['Foo']},
{ref:['Boo']},
], from: { ref: ['Bar'] } },
})
.to.eql(CQL`SELECT Foo, Boo from Bar`)
.to.eql(SELECT `Foo, Boo` .from `Bar`)
.to.eql(SELECT `Foo, Boo` .from('Bar'))
.to.eql(SELECT('Foo','Boo').from('Bar'))
.to.eql(SELECT(['Foo','Boo']).from('Bar'))
.to.eql(SELECT `Bar` .columns `Foo, Boo`)
.to.eql(SELECT `Bar` .columns `{ Foo, Boo }`)
.to.eql(SELECT `Bar` .columns ('{ Foo, Boo }'))
.to.eql(SELECT `Bar` .columns ('Foo','Boo'))
.to.eql(SELECT `Bar` .columns (['Foo','Boo']))
.to.eql(SELECT.from `Bar` .columns ('Foo','Boo'))
.to.eql(SELECT.from `Bar` .columns (['Foo','Boo']))
expect({
SELECT: { columns:[
{ref:['Foo']},
{ref:['Boo']},
{ref:['Moo']},
], from: { ref: ['Bar'] } },
})
.to.eql(CQL`SELECT Foo, Boo, Moo from Bar`)
.to.eql(SELECT `Foo, Boo, Moo` .from `Bar`)
.to.eql(SELECT `Foo, Boo, Moo` .from('Bar'))
.to.eql(SELECT('Foo','Boo','Moo').from('Bar'))
.to.eql(SELECT(['Foo','Boo','Moo']).from('Bar'))
.to.eql(SELECT `Bar` .columns `Foo, Boo, Moo`)
.to.eql(SELECT `Bar` .columns ('Foo','Boo','Moo'))
.to.eql(SELECT `Bar` .columns (['Foo','Boo','Moo']))
.to.eql(SELECT.from `Bar` .columns ('Foo','Boo','Moo'))
.to.eql(SELECT.from `Bar` .columns (['Foo','Boo','Moo']))
expect({
SELECT: { one:true, columns:[{ref:['Foo']}], from: { ref: ['Bar'] } },
})
// .to.eql(CQL`SELECT one Foo from Bar`)
.to.eql(SELECT.one `Foo` .from `Bar`)
.to.eql(SELECT.one `Foo` .from('Bar'))
.to.eql(SELECT.one('Foo').from('Bar'))
.to.eql(SELECT.one(['Foo']).from('Bar'))
.to.eql(SELECT.one(['Foo']).from('Bar'))
.to.eql(SELECT.one('Bar',['Foo']))
.to.eql(SELECT.one `Bar` .columns `Foo`)
.to.eql(SELECT.one('Bar').columns('Foo'))
.to.eql(SELECT.one('Bar').columns(['Foo']))
.to.eql(SELECT.one.from('Bar',['Foo']))
.to.eql(SELECT.one.from('Bar').columns('Foo'))
.to.eql(SELECT.one.from('Bar').columns(['Foo']))
expect({
SELECT: { one:true, columns:[
{ref:['Foo']},
{ref:['Boo']},
], from: { ref: ['Bar'] } },
})
// .to.eql(CQL`SELECT Foo, Boo from Bar`)
.to.eql(SELECT.one `Foo, Boo` .from `Bar`)
.to.eql(SELECT.one `Foo, Boo` .from('Bar'))
.to.eql(SELECT.one('Foo','Boo').from('Bar'))
.to.eql(SELECT.one(['Foo','Boo']).from('Bar'))
.to.eql(SELECT.one('Bar',['Foo','Boo']))
.to.eql(SELECT.one `Bar` .columns `Foo, Boo`)
.to.eql(SELECT.one('Bar').columns('Foo','Boo'))
.to.eql(SELECT.one('Bar').columns(['Foo','Boo']))
.to.eql(SELECT.one.from('Bar',['Foo','Boo']))
.to.eql(SELECT.one.from('Bar').columns('Foo','Boo'))
.to.eql(SELECT.one.from('Bar').columns(['Foo','Boo']))
expect({
SELECT: { one:true, columns:[
{ref:['Foo']},
{ref:['Boo']},
{ref:['Moo']},
], from: { ref: ['Bar'] } },
})
// .to.eql(CQL`SELECT Foo, Boo, Moo from Bar`)
.to.eql(SELECT.one `Foo, Boo, Moo` .from `Bar`)
.to.eql(SELECT.one `Foo, Boo, Moo` .from('Bar'))
.to.eql(SELECT.one('Foo','Boo','Moo').from('Bar'))
.to.eql(SELECT.one(['Foo','Boo','Moo']).from('Bar'))
.to.eql(SELECT.one('Bar',['Foo','Boo','Moo']))
.to.eql(SELECT.one `Bar` .columns `Foo, Boo, Moo`)
.to.eql(SELECT.one('Bar').columns('Foo','Boo','Moo'))
.to.eql(SELECT.one('Bar').columns(['Foo','Boo','Moo']))
.to.eql(SELECT.one.from('Bar',['Foo','Boo','Moo']))
.to.eql(SELECT.one.from('Bar').columns('Foo','Boo','Moo'))
.to.eql(SELECT.one.from('Bar').columns(['Foo','Boo','Moo']))
})
if (each === 'SELECT')
test('from ( Foo )', () => {
expect({
SELECT: { from: {ref: [{ id:'Foo', where: [{val:11}] }] }}
})
.to.eql(srv.read`Foo[${11}]`)
.to.eql(SELECT`Foo[${11}]`)
expect((cqn = SELECT`from Foo[ID=11]`))
.to.eql(SELECT`from Foo[ID=${11}]`)
.to.eql(SELECT.from `Foo[ID=11]`)
.to.eql(SELECT.from `Foo[ID=${11}]`)
.to.eql(SELECT`Foo[ID=11]`)
expect.plain(cqn)
.to.eql(CQL`SELECT from Foo[ID=11]`)
.to.eql(srv.read`Foo[ID=11]`)
.to.eql({
SELECT: { from: {
ref: [{ id: 'Foo', where: [{ ref: ['ID'] }, '=', { val: 11 }] }],
}},
})
expect.plain (cqn)
.to.eql(SELECT`Foo[ID=${11}]`)
.to.eql(srv.read`Foo[ID=${11}]`)
// Following implicitly resolve to SELECT.one
expect(cqn = SELECT.from(Foo,11))
.to.eql(SELECT.from(Foo,{ID:11}))
.to.eql(SELECT.from(Foo).byKey(11))
.to.eql(SELECT.from(Foo).byKey({ID:11}))
if (cds.version >= '5.6.0') {
expect.one(cqn)
.to.eql({
SELECT: {
one: true,
from: { ref: [{ id: 'Foo', where: [{ ref: ['ID'] }, '=', { val: 11 }] }] },
},
})
} else {
expect.one(cqn)
.to.eql({
SELECT: {
one: true,
from: { ref: ['Foo'] },
where: [{ ref: ['ID'] }, '=', { val: 11 }],
},
})
}
})
test('from Foo {...}', () => {
expect(cqn = SELECT `*,a,b as c` .from `Foo`)
.to.eql(SELECT `*,a,b as c`. from(Foo))
.to.eql(SELECT('*','a',{b:'c'}).from`Foo`)
.to.eql(SELECT('*','a',{b:'c'}).from(Foo))
.to.eql(SELECT(['*','a',{b:'c'}]).from(Foo))
.to.eql(SELECT.columns('*','a',{b:'c'}).from(Foo))
.to.eql(SELECT.columns(['*','a',{b:'c'}]).from(Foo))
.to.eql(SELECT.columns((foo) => { foo`.*`, foo.a, foo.b`as c` }).from(Foo))
.to.eql(SELECT.columns((foo) => { foo('*'), foo.a, foo.b.as('c') }).from(Foo))
.to.eql(SELECT.from(Foo).columns('*','a',{b:'c'}))
.to.eql(SELECT.from(Foo).columns(['*','a',{b:'c'}]))
.to.eql(SELECT.from(Foo).columns((foo) => { foo`.*`, foo.a, foo.b`as c` }))
.to.eql(SELECT.from(Foo).columns((foo) => { foo('*'), foo.a, foo.b.as('c') }))
.to.eql(SELECT.from(Foo,['*','a',{b:'c'}]))
.to.eql(SELECT.from(Foo, (foo) => { foo`.*`, foo.a, foo.b`as c` }))
.to.eql(SELECT.from(Foo, (foo) => { foo('*'), foo.a, foo.b.as('c') }))
expect.plain(cqn)
.to.eql({
SELECT: {
from: { ref: ['Foo'] },
columns: [ STAR, { ref: ['a'] }, { ref: ['b'], as: 'c' }],
},
})
expect.plain(cqn)
.to.eql(CQL`SELECT *,a,b as c from Foo`)
.to.eql(CQL`SELECT from Foo {*,a,b as c}`)
// Test combination with key as second argument to .from
expect(cqn = SELECT.from(Foo, 11, ['a']))
.to.eql(SELECT.from(Foo, 11, foo => foo.a))
if (cds.version >= '5.6.0') {
expect.one(cqn)
.to.eql({
SELECT: {
one: true,
from: { ref: [{ id: 'Foo', where: [{ ref: ['ID'] }, '=', { val: 11 }]}] },
columns: [{ ref: ['a'] }]
},
})
} else {
expect.one(cqn)
.to.eql({
SELECT: {
one: true,
from: { ref: ['Foo'] },
columns: [{ ref: ['a'] }],
where: [{ ref: ['ID'] }, '=', { val: 11 }],
},
})
}
})
test('with nested expands', () => {
// SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } }
expect(cqn =
SELECT.from (Foo, foo => {
foo`*`, foo.x, foo.car`*`, foo.boo (b => {
b`*`, b.moo.zoo(
x => x.y.z
)
})
})
).to.eql(
SELECT.from (Foo, foo => {
foo('*'), foo.x, foo.car('*'), foo.boo (b => {
b('*'), b.moo.zoo(
x => x.y.z
)
})
})
)
expect.plain(cqn)
.to.eql({
SELECT: {
from: { ref: ['Foo'] },
columns: [
STAR,
{ ref: ['x'] },
{ ref: ['car'], expand: ['*'] },
{
ref: ['boo'],
expand: [ '*', { ref: ['moo', 'zoo'], expand: [{ ref: ['y', 'z'] }] }],
},
],
},
})
})
test('with nested inlines', () => {
// SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } }
expect.plain(
SELECT.from (Foo, foo => {
foo.bar `*`,
foo.bar `.*`, //> leading dot indicates inline
foo.boo(_ => _.moo.zoo), //> underscore arg name indicates inline
foo.boo(x => x.moo.zoo)
})
).to.eql({
SELECT: {
from: { ref: ['Foo'] },
columns: [
{ ref: ['bar'], expand: ['*'] },
{ ref: ['bar'], inline: ['*'] },
{ ref: ['boo'], inline: [{ ref: ['moo', 'zoo'] }] },
{ ref: ['boo'], expand: [{ ref: ['moo', 'zoo'] }] },
],
},
})
})
})
describe ('SELECT where...', ()=>{
it('should correctly handle { ... and:{...} }', () => {
expect(SELECT.from(Foo).where({ x: 1, and: { y: 2, or: { z: 3 } } })).to.eql({
SELECT: {
from: { ref: ['Foo'] },
where: [
{ ref: ['x'] },
'=',
{ val: 1 },
'and',
// '(',
{xpr:[
{ ref: ['y'] },
'=',
{ val: 2 },
'or',
{ ref: ['z'] },
'=',
{ val: 3 },
]},
// ')',
],
},
})
})
test ("where x='*'", ()=>{
expect (SELECT.from(Foo).where({x:'*'}))
.to.eql(SELECT.from(Foo).where("x='*'"))
.to.eql(SELECT.from(Foo).where("x=",'*'))
.to.eql(SELECT.from(Foo).where`x=${'*'}`)
.to.eql(
CQL`SELECT from Foo where x='*'`
)
expect (SELECT.from(Foo).where({x:['*',1]}))
.to.eql(SELECT.from(Foo).where("x in ('*',1)"))
.to.eql(SELECT.from(Foo).where("x in",['*',1]))
.to.eql(SELECT.from(Foo).where`x in ${['*',1]}`)
.to.eql(
CQL`SELECT from Foo where x in ('*',1)`
)
})
test ('where, and, or', ()=>{
expect (
SELECT.from(Foo).where({x:1,and:{y:2}})
).to.eql (
CQL`SELECT from Foo where x=1 and y=2`
) .to.eql ({ SELECT: {
from: {ref:['Foo']},
where: [
{ref:['x']}, '=', {val:1},
'and',
{ref:['y']}, '=', {val:2}
]
}})
const ql_with_groups_fix = !!cds.ql.Query.prototype.flat
if (ql_with_groups_fix) {
expect (
SELECT.from(Foo).where({x:1}).or({y:2}).and({z:3})
).to.eql ({ SELECT: {
from: {ref:['Foo']},
where: [
{ref:['x']}, '=', {val:1},
'or',
{ref:['y']}, '=', {val:2},
'and',
{ref:['z']}, '=', {val:3},
]
}})
expect (
SELECT.from(Foo).where({x:1,or:{y:2}}).and({z:3})
).to.eql ({ SELECT: {
from: {ref:['Foo']},
where: [
{xpr:[
{ref:['x']}, '=', {val:1},
'or',
{ref:['y']}, '=', {val:2},
]},
'and',
{ref:['z']}, '=', {val:3},
]
}})
expect (
SELECT.from(Foo).where({a:1}).or({x:1,or:{y:2}}).and({z:3})
).to.eql ({ SELECT: {
from: {ref:['Foo']},
where: [
{ref:['a']}, '=', {val:1},
'or',
{xpr:[
{ref:['x']}, '=', {val:1},
'or',
{ref:['y']}, '=', {val:2},
]},
'and',
{ref:['z']}, '=', {val:3},
]
}})
expect (
{ SELECT: SELECT.from(Foo).where({x:1,or:{y:2}}).SELECT }
).to.eql ({ SELECT: {
from: {ref:['Foo']},
where: [
{ref:['x']}, '=', {val:1},
'or',
{ref:['y']}, '=', {val:2},
]
}})
}
expect (
SELECT.from(Foo).where({x:1,and:{y:2}}).or({z:3})
).to.eql (
CQL`SELECT from Foo where x=1 and y=2 or z=3`
)
expect (
SELECT.from(Foo).where({x:1}).and({y:2,or:{z:3}})
).to.eql (
CQL`SELECT from Foo where x=1 and ( y=2 or z=3 )`
)
expect (
SELECT.from(Foo).where({1:1}).and({x:1,or:{x:2}}).and({y:2,or:{z:3}})
).to.eql (
CQL`SELECT from Foo where 1=1 and ( x=1 or x=2 ) and ( y=2 or z=3 )`
)
expect (
SELECT.from(Foo).where({x:1,or:{x:2}}).and({y:2,or:{z:3}})
).to.eql (
CQL`SELECT from Foo where ( x=1 or x=2 ) and ( y=2 or z=3 )`
)
})
test('where ({x:[undefined]})', () => {
expect (
SELECT.from(Foo).where({x:[undefined]})
).to.eql ({ SELECT: {
from: {ref:['Foo']},
where: [
{ref:['x']},
'in',
{ list: [ {val:undefined} ] }
]
}})
})
test('where ( ... cql | {x:y} )', () => {
const args = [`foo`, "'bar'", 3]
const ID = 11
// using simple predicate objects
// (Note: this doesn't support paths in left-hand-sides, nor references in arrays)
expect(
SELECT.from(Foo).where({
ID,
args,
and: { x: { like: '%x%' }, or: { y: { '>=': 9 } } },
})
).to.eql({
SELECT: {
from: { ref: ['Foo'] },
where: [
{ ref: ['ID'] },
'=',
{ val: ID },
'and',
{ ref: ['args'] },
'in',
{ list: args.map(val => ({ val })) },
'and',
{
xpr: [
{ ref: ['x'] },
'like',
{ val: '%x%' },
'or',
{ ref: ['y'] },
'>=',
{ val: 9 },
]
},
],
}
})
// using CQL fragments -> uses cds.parse.expr
const is_v2 = !!cds.parse.expr('(1,2)').list
if (is_v2) expect((cqn = CQL`SELECT from Foo where ID=11 and x in ( foo, 'bar', 3)`)).to.eql({
SELECT: {
from: { ref: ['Foo'] },
where: [
{ ref: ['ID'] },
'=',
{ val: ID },
'and',
{ ref: ['x'] },
'in',
{list:[
{ ref: ['foo'] },
{ val: 'bar' },
{ val: 3 },
]}
],
},
})
else expect((cqn = CQL`SELECT from Foo where ID=11 and x in ( foo, 'bar', 3)`)).to.eql({
SELECT: {
from: { ref: ['Foo'] },
where: [
{ ref: ['ID'] },
'=',
{ val: ID },
'and',
{ ref: ['x'] },
'in',
'(',
{ ref: ['foo'] },
',',
{ val: 'bar' },
',',
{ val: 3 },
')',
],
},
})
if (!is_v2) expect(
SELECT.from(Foo).where(`x=`, 1, `or y.z is null and (a>`, 2, `or b=`, 3, `)`)
).to.eql(CQL`SELECT from Foo where x=1 or y.z is null and (a>2 or b=3)`)
expect(SELECT.from(Foo).where(`x between`, 1, `and`, 9)).to.eql(
CQL`SELECT from Foo where x between 1 and 9`
)
})
test('w/ sub selects', () => {
// in where causes
expect(SELECT.from(Foo).where({ x: SELECT('y').from('Bar') })).to.eql(
CQL`SELECT from Foo where x in (SELECT y from Bar)`
)
// using query api
expect(SELECT.from('Books').where(
`author.name in`, SELECT('name').from('Authors'))).to.eql(CQL`SELECT from Books where author.name in (SELECT name from Authors)`
)
// in classical semi joins
expect(
SELECT('x').from(Foo) .where ( `exists`,
SELECT(1).from('Bar') .where ({ y: { ref: ['x'] } })
) // prettier-ignore
).to.eql(CQL`SELECT x from Foo where exists (SELECT 1 from Bar where y=x)`)
// in select clauses
cqn = CQL`SELECT from Foo { x, (SELECT y from Bar) as y }`
cds.version >= '3.33.3' &&
expect(
SELECT.from(Foo, (foo) => {
foo.x, foo(SELECT.from('Bar', (b) => b.y)).as('y')
})
).to.eql(cqn)
cds.version >= '3.33.3' &&
expect(
SELECT.from(Foo, ['x', Object.assign(SELECT('y').from('Bar'), { as: 'y' })])
).to.eql(cqn)
})
test('w/ plain SQL', () => {
expect(SELECT.from(Books) + 'WHERE ...').to.eql(
'SELECT * FROM capire_bookshop_Books WHERE ...'
)
})
it('should consistently handle *', () => {
expect({
SELECT: { from: { ref: ['Foo'] }, columns: ['*'] },
})
.to.eql(CQL`SELECT * from Foo`)
.to.eql(CQL`SELECT from Foo{*}`)
.to.eql(SELECT('*').from(Foo))
.to.eql(SELECT.from(Foo,['*']))
})
it('should consistently handle lists', () => {
const ID = 11, args = [{ref:['foo']}, "bar", 3]
const cqn = CQL`SELECT from Foo where ID=11 and x in (foo,'bar',3)`
expect(SELECT.from(Foo).where`ID=${ID} and x in ${args}`).to.eql(cqn)
expect(SELECT.from(Foo).where(`ID=`, ID, `and x in`, args)).to.eql(cqn)
expect(SELECT.from(Foo).where({ ID, x:args })).to.eql(cqn)
})
//
})
describe(`SELECT for update`, () => {
beforeAll(() => {
delete cds.env.sql.lock_acquire_timeout
})
it('no wait', () => {
const q = SELECT.from('Foo').forUpdate()
expect(q.SELECT.forUpdate).eqls({})
})
it('specific wait', () => {
const q = SELECT.from('Foo').forUpdate({ wait: 1 })
expect(q.SELECT.forUpdate).eqls({ wait: 1 })
})
it('default wait', () => {
cds.env.sql.lock_acquire_timeout = 2
const q = SELECT.from('Foo').forUpdate()
expect(q.SELECT.forUpdate).eqls({ wait: 2 })
})
it('override default', () => {
cds.env.sql.lock_acquire_timeout = 1
const q = SELECT.from('Foo').forUpdate({ wait:-1 })
expect(q.SELECT.forUpdate).eqls({})
})
})
describe(`INSERT...`, () => {
test('entries ({a,b}, ...)', () => {
const entries = [{ foo: 1 }, { boo: 2 }]
expect(INSERT(...entries).into(Foo))
.to.eql(INSERT(entries).into(Foo))
.to.eql(INSERT.into(Foo).entries(...entries))
.to.eql(INSERT.into(Foo).entries(entries))
.to.eql({
INSERT: { into: { ref: ['Foo'] }, entries },
})
})
test('rows ([1,2], ...)', () => {
expect(
INSERT.into(Foo)
.columns('a', 'b')
.rows([
[1, 2],
[3, 4],
])
)
.to.eql(INSERT.into(Foo).columns('a', 'b').rows([1, 2], [3, 4]))
.to.eql({
INSERT: {
into: { ref: ['Foo'] },
columns: ['a', 'b'],
rows: [
[1, 2],
[3, 4],
],
},
})
})
test('values (1,2)', () => {
expect(INSERT.into(Foo).columns('a', 'b').values([1, 2]))
.to.eql(INSERT.into(Foo).columns('a', 'b').values(1, 2))
.to.eql({
INSERT: { into: { ref: ['Foo'] }, columns: ['a', 'b'], values: [1, 2] },
})
})
test('w/ plain SQL', () => {
expect(INSERT.into(Books) + 'VALUES ...').to.eql(
'INSERT INTO capire_bookshop_Books VALUES ...'
)
})
})
describe(`UPDATE...`, () => {
test('entity (..., <key>)', () => {
const cqnWhere = {
UPDATE: {
entity: { ref: ['capire.bookshop.Books'] },
where: [{ ref: ['ID'] }, '=', { val: 4711 }],
},
}
expect(UPDATE(Books).where({ ID: 4711 }))
.to.eql(UPDATE(Books).where(`ID=`, 4711))
.to.eql(cqnWhere)
const cqnKey = (cds.version >= '5.6.0') ?
{
UPDATE: {
entity: { ref: [{ id: 'capire.bookshop.Books', where: [{ ref: ['ID'] }, '=', { val: 4711 }] }] }
}
}
: cqnWhere
expect(UPDATE(Books, 4711))
.to.eql(UPDATE(Books, { ID: 4711 }))
.to.eql(UPDATE(Books).byKey(4711))
.to.eql(UPDATE(Books).byKey({ ID: 4711 }))
.to.eql(UPDATE.entity(Books, 4711))
.to.eql(UPDATE.entity(Books, { ID: 4711 }))
// etc...
.to.eql(cqnKey)
})
/*
UPDATE.with allows to pass in plain data payloads, e.g. as obtained from REST clients.
In addition, UPDATE.with supports specifying expressions, either in CQL fragements
notation or as simple expression objects.
UPDATE.data allows to pass in plain data payloads, e.g. as obtained from REST clients.
The passed in object can be modified subsequently, e.g. by adding or modifying values
before the query is finally executed.
*/
test('with + data', () => {
if (cds.version < '4.1.0') return
const o = {}
const q = UPDATE(Foo).data(o).with(`bar-=`, 22)
o.foo = 11
expect(q)
.to.eql(UPDATE(Foo).with(`foo=`, 11, `bar-=`, 22))
.to.eql(UPDATE(Foo).with({ foo: 11, bar: { '-=': 22 } }))
.to.eql({
UPDATE: {
entity: { ref: ['Foo'] },
data: { foo: 11 },
with: {
bar: { xpr: [{ ref: ['bar'] }, '-', { val: 22 }] },
},
},
})
// some more
expect(UPDATE(Foo).with(`bar = coalesce(x,y), car = 'foo''s bar, car'`)).to.eql({
UPDATE: {
entity: { ref: ['Foo'] },
data: {
car: "foo's bar, car",
},
with: {
bar: { func: 'coalesce', args: [{ ref: ['x'] }, { ref: ['y'] }] },
},
},
})
})
test('w/ plain SQL', () => {
expect(UPDATE(Books) + 'SET ...').to.eql('UPDATE capire_bookshop_Books SET ...')
})
})
describe(`DELETE...`, () => {
test('from (..., <key>)', () => {
const cqnWhere = {
DELETE: {
from: { ref: ['capire.bookshop.Books'] },
where: [{ ref: ['ID'] }, '=', { val: 4711 }],
},
}
expect(DELETE.from(Books).where({ ID: 4711 }))
.to.eql(DELETE.from(Books).where(`ID=`, 4711))
.to.eql(cqnWhere)
const cqnKey = (cds.version >= '5.6.0') ?
{
DELETE: {
from: { ref: [{ id: 'capire.bookshop.Books', where: [{ ref: ['ID'] }, '=', { val: 4711 }]}] }
},
} : cqnWhere
expect(DELETE(Books, 4711))
.to.eql(DELETE(Books, { ID: 4711 }))
.to.eql(DELETE.from(Books, 4711))
.to.eql(DELETE.from(Books, { ID: 4711 }))
.to.eql(DELETE.from(Books).byKey(4711))
.to.eql(DELETE.from(Books).byKey({ ID: 4711 }))
.to.eql(cqnKey)
})
test('/w plain SQL', () => {
expect(DELETE.from(Books) + 'WHERE ...').to.eql(
'DELETE FROM capire_bookshop_Books WHERE ...'
)
})
})
describe(`cds.ql etc...`, () => {
it('should keep null and undefined', () => {
for (let each of [null, undefined]) {
expect(SELECT.from(Foo).where({ ID: each })).to.eql({
SELECT: {
from: { ref: ['Foo'] },
where: [{ ref: ['ID'] }, '=', { val: each }],
},
})
}
})
})
//
})

View File

@@ -1,53 +0,0 @@
const cds = require("@sap/cds");
const { expect } = cds.test(
"serve",
"CatalogService",
"--from",
"@capire/bookshop,@capire/common",
"--in-memory"
);
describe("Consuming actions locally", () => {
let cats, CatalogService, Books, stockBefore;
const BOOK_ID = 251;
const QUANTITY = 1;
before("bootstrap the database", async () => {
CatalogService = cds.services.CatalogService;
expect(CatalogService).not.to.be.undefined;
Books = CatalogService.entities.Books;
expect(Books).not.to.be.undefined;
cats = await cds.connect.to("CatalogService");
});
beforeEach(async () => {
// Read the stock before the action is called
stockBefore = (await cats.get(Books, BOOK_ID)).stock;
});
it("calls unbound actions - basic variant using srv.send", async () => {
// Use a managed transaction to create a continuation with an authenticated user
const res1 = await cats.tx({ user: "alice" }, () => {
return cats.send("submitOrder", { book: BOOK_ID, quantity: QUANTITY });
});
expect(res1.stock).to.eql(stockBefore - QUANTITY);
});
it("calls unbound actions - named args variant", async () => {
// Use a managed transaction to create a continuation with an authenticated user
const res2 = await cats.tx({ user: "alice" }, () => {
return cats.submitOrder({ book: BOOK_ID, quantity: QUANTITY });
});
expect(res2.stock).to.eql(stockBefore - QUANTITY);
});
it("calls unbound actions - positional args variant", async () => {
// Use a managed transaction to create a continuation with an authenticated user
const res3 = await cats.tx({ user: "alice" }, () => {
return cats.submitOrder(BOOK_ID, QUANTITY);
});
expect(res3.stock).to.eql(stockBefore - QUANTITY);
});
});

View File

@@ -1,82 +0,0 @@
const cds = require('@sap/cds')
const { expect } = cds.test ('@capire/bookshop')
cds.User.default = cds.User.privileged // disable auth checks
describe('cap/samples - Consuming Services locally', () => {
it('bootstrapped the database successfully', ()=>{
const { AdminService } = cds.services
const { Authors } = AdminService.entities
expect(AdminService).to.exist
expect(Authors).to.exist
})
it('supports targets as strings or reflected defs', async () => {
const AdminService = await cds.connect.to('AdminService')
const { Authors } = AdminService.entities
expect (await SELECT.from(Authors))
// .to.eql(await SELECT.from('Authors'))
.to.eql(await AdminService.read(Authors))
.to.eql(await AdminService.read('Authors'))
.to.eql(await AdminService.run(SELECT.from(Authors)))
.to.eql(await AdminService.run(SELECT.from('Authors')))
})
it('allows reading from local services using cds.ql', async () => {
const AdminService = await cds.connect.to('AdminService')
const authors = await AdminService.read (`Authors`, a => {
a.name,
a.books((b) => {
b.title,
b.currency((c) => {
c.name, c.symbol
})
})
}).where(`name like`, 'E%')
expect(authors).to.containSubset([
{
name: 'Emily Brontë',
books: [
{
title: 'Wuthering Heights',
currency: { name: 'British Pound', symbol: '£' },
},
],
},
{
name: 'Edgar Allen Poe',
books: [
{ title: 'The Raven', currency: { name: 'US Dollar', symbol: '$' } },
{ title: 'Eleonora', currency: { name: 'US Dollar', symbol: '$' } },
],
},
])
})
it('provides CRUD-style convenience methods', async () => {})
it('uses same methods for all kind of services, including dbs', async () => {
const srv = await cds.connect.to('AdminService')
const db = await cds.connect.to('db')
const { Authors } = srv.entities
const projection = (a) => {
a.name,
a.books((b) => {
b.title,
b.currency((c) => {
c.name, c.symbol
})
})
}
const query1 = SELECT.from(Authors, projection).where(`name like`, 'E%')
const query2 = cds.read(Authors, projection).where(`name like`, 'E%')
expect(await cds.run(query1))
.to.eql(await db.run(query1))
.to.eql(await srv.run(query1))
.to.eql(await srv.read(Authors, projection).where(`name like`, 'E%'))
.to.eql(await cds.run(query2))
.to.eql(await db.run(query2))
.to.eql(await srv.run(query2))
.to.eql(await db.read(Authors, projection).where(`name like`, 'E%'))
})
})

View File

@@ -1,15 +0,0 @@
const cds = require('@sap/cds')
const { GET, POST, expect } = cds.test(__dirname+'/..')
cds.User.default = cds.User.Privileged // hard core monkey patch
describe('cap/samples - Custom Handlers', () => {
it('should reject out-of-stock orders', async () => {
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.fulfilled
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.fulfilled
await expect(POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`).to.be.rejectedWith(
/409 - 5 exceeds stock for book #201/)
const { data } = await GET`/admin/Books/201/stock/$value`
expect(data).to.equal(2)
})
})

View File

@@ -1,123 +0,0 @@
const cds = require('@sap/cds')
const { expect } = cds.test.in(__dirname,'..','..')
describe('cap/samples - Hierarchical Data', ()=>{
const csn = CDL`
entity Categories {
key ID : Integer;
name : String;
children : Composition of many Categories on children.parent = $self;
parent : Association to Categories;
}
`
const model = cds.compile.for.nodejs(csn)
const {Categories:Cats} = model.definitions
before ('bootstrap sqlite in-memory db...', async()=>{
await cds.deploy (csn) .to ('sqlite::memory:') // REVISIT: cds.compile.to.sql should accept cds.compiled.for.nodejs models
expect (cds.db) .to.exist
expect (cds.db.model) .to.exist
})
it ('supports deeply nested inserts', ()=> INSERT.into (Cats,
{ ID:100, name:'Some Cats...', children:[
{ ID:101, name:'Cat', children:[
{ ID:102, name:'Kitty', children:[
{ ID:103, name:'Kitty Cat', children:[
{ ID:104, name:'Aristocat' } ]},
{ ID:105, name:'Kitty Bat' } ]},
{ ID:106, name:'Catwoman', children:[
{ ID:107, name:'Catalina' } ]} ]},
{ ID:108, name:'Catweazle' }
]}
))
it ('should generate correct queries for expands', ()=>{
let q = SELECT.from (Cats, c => { c.ID, c.name, c.children (c => c.name) })
expect (q) .to.eql ({
SELECT: {
from: { ref:[ "Categories" ] },
columns: [
{ ref: [ "ID" ] },
{ ref: [ "name" ] },
{ ref: [ "children" ], expand: [ {ref:['name']} ] },
]
}
})
/* temp skip for release
if (q.forSQL) expect (q.forSQL()) .to.eql ({
SELECT: {
from: { ref:[ "Categories" ], as: "Categories" },
columns: [
{ ref: [ "Categories", "ID" ] },
{ ref: [ "Categories", "name" ] },
{ as: "children", SELECT: { expand: true,
one: false,
columns: [{ ref: [ "children", "name" ]}],
from: { ref:["Categories"], as: "children" },
where: [
{ref:[ "Categories", "ID" ]}, "=", {ref:[ "children", "parent_ID" ]}
],
}},
],
}
})
if (q.toSql) expect (q.toSql()) .to.eql (
`SELECT json_insert('{}',` +
`'$."ID"',ID,` +
`'$."name"',name,` +
`'$."children"',children->'$'` +
`) as _json_ FROM (` +
`SELECT Categories.ID,Categories.name,(` +
`SELECT jsonb_group_array(jsonb_insert('{}','$."name"',name)) as _json_ FROM (` +
`SELECT children.name FROM Categories as children WHERE Categories.ID = children.parent_ID` +
`)` +
`) as children FROM Categories as Categories` +
`)`
)
*/
})
it ('supports nested reads', ()=> expect (
SELECT.one.from (Cats, c=>{
c.ID, c.name.as('parent'), c.children (c=>{
c.name.as('child')
})
}) .where ({name:'Cat'})
) .to.eventually.eql (
{ ID:101, parent:'Cat', children:[
{ child:'Kitty' },
{ child:'Catwoman' },
]}
))
it ('supports deeply nested reads', ()=> expect (
SELECT.one.from (Cats, c=>{
c.ID, c.name, c.children (
c => { c.name },
{levels:3}
)
}) .where ({name:'Cat'})
) .to.eventually.eql (
{ ID:101, name:'Cat', children:[
{ name:'Kitty', children:[
{ name:'Kitty Cat', children:[
{ name:'Aristocat' }, ]}, // level 3
{ name:'Kitty Bat', children:[] }, ]},
{ name:'Catwoman', children:[
{ name:'Catalina', children:[] } ]},
]}
))
it ('supports cascaded deletes', async()=>{
const affectedRows = await DELETE.from (Cats) .where ({ID:[102,106]})
expect (affectedRows) .to.be.greaterThan (0)
await expect (SELECT`ID,name`.from(Cats) ).to.eventually.eql ([
{ ID:100, name:'Some Cats...' },
{ ID:101, name:'Cat' },
{ ID:108, name:'Catweazle' }
])
})
})

View File

@@ -1,37 +0,0 @@
#################################################
#
# Genres
#
GET http://localhost:4004/odata/v4/test/Genres?
###
GET http://localhost:4004/odata/v4/test/Genres?
&$filter=parent_ID eq null&$select=name
&$expand=children($select=name)
###
POST http://localhost:4004/odata/v4/test/Genres?
Content-Type: application/json
{ "ID":"100aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Some Sample Genres...", "children":[
{ "ID":"101aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Cat", "children":[
{ "ID":"102aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Kitty", "children":[
{ "ID":"103aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Aristocat" },
{ "ID":"104aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Kitty Bat" } ]},
{ "ID":"105aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Catwoman", "children":[
{ "ID":"106aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Catalina" } ]} ]},
{ "ID":"107aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "name":"Catweazle" }
]}
###
GET http://localhost:4004/odata/v4/test/Genres(100aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)?
&$expand=children
&$expand=children($expand=children($expand=children($expand=children)))
###
DELETE http://localhost:4004/odata/v4/test/Genres(103aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)
###
DELETE http://localhost:4004/odata/v4/test/Genres(100aaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)
###

View File

@@ -1,4 +0,0 @@
using { sap.capire.bookshop as my } from '../../db/schema';
service TestService {
entity Genres as projection on my.Genres;
}

View File

@@ -1,5 +0,0 @@
{
"devDependencies": {
"@cap-js/sqlite": "*"
}
}

View File

@@ -1,12 +0,0 @@
using { CatalogService, sap.capire.bookshop as my } from '@capire/bookshop';
using from '@capire/common';
extend service CatalogService with {
@cds.localized:false
entity BooksSans as projection on my.Books {
*, //> non-localized defaults, e.g. title
key ID,
texts.title as localized_title,
texts.locale
};
}

View File

@@ -1,79 +0,0 @@
const cds = require('@sap/cds')
const { GET, expect } = cds.test (__dirname)
cds.User.default = cds.User.Privileged // hard core monkey patch
describe('cap/samples - Localized Data', () => {
it('serves localized $metadata documents', async () => {
const { data } = await GET(`/browse/$metadata?sap-language=de`, { headers: { 'accept-language': 'de' }})
expect(data).to.contain('<Annotation Term="Common.Label" String="Währung"/>')
})
it('supports accept-language header', async () => {
const { data } = await GET(`/browse/Books?$select=title,author`, {
headers: { 'Accept-Language': 'de' },
})
expect(data.value).to.containSubset([
{ title: 'Sturmhöhe', author: 'Emily Brontë' },
{ title: 'Jane Eyre', author: 'Charlotte Brontë' },
{ title: 'The Raven', author: 'Edgar Allen Poe' },
{ title: 'Eleonora', author: 'Edgar Allen Poe' },
{ title: 'Catweazle', author: 'Richard Carpenter' },
])
})
it('supports queries with $expand', async () => {
const { data } = await GET(`/browse/Books?&$select=title,author&$expand=currency`, {
headers: { 'Accept-Language': 'de' },
})
expect(data.value).to.containSubset([
{ title: 'Sturmhöhe', author: 'Emily Brontë', currency: { name: 'Pfund' } },
{ title: 'Jane Eyre', author: 'Charlotte Brontë', currency: { name: 'Pfund' } },
{ title: 'The Raven', author: 'Edgar Allen Poe', currency: { name: 'US-Dollar' } },
{ title: 'Eleonora', author: 'Edgar Allen Poe', currency: { name: 'US-Dollar' } },
{ title: 'Catweazle', author: 'Richard Carpenter', currency: { name: 'Yen' } },
])
})
it('supports queries with nested $expand', async () => {
const { data } = await GET(`/admin/Authors`, {
params: {
$filter: `startswith(name,'E')`,
$expand: `books(
$select=title;
$expand=currency(
$select=name,symbol
)
)`.replace(/\s/g, ''),
$select: `name`,
},
headers: { 'Accept-Language': 'de' },
})
expect(data.value).to.containSubset([
{
name: 'Emily Brontë',
books: [{ title: 'Sturmhöhe', currency: { name: 'Pfund', symbol: '£' } }],
},
{
name: 'Edgar Allen Poe',
books: [
{ title: 'The Raven', currency: { name: 'US-Dollar', symbol: '$' } },
{ title: 'Eleonora', currency: { name: 'US-Dollar', symbol: '$' } },
],
},
])
})
it('supports @cds.localized:false', async ()=>{
const { data } = await GET(`/browse/BooksSans?&$select=title,localized_title&$expand=currency&$filter=locale eq 'de' or locale eq null`, {
headers: { 'Accept-Language': 'de' },
})
expect(data.value).to.containSubset([
{ title: 'Wuthering Heights', localized_title: 'Sturmhöhe', currency: { name: 'British Pound' } },
{ title: 'Jane Eyre', currency: { name: 'British Pound' } },
{ title: 'The Raven', currency: { name: 'US Dollar' } },
{ title: 'Eleonora', currency: { name: 'US Dollar' } },
{ title: 'Catweazle', currency: { name: 'Yen' } },
])
})
})

View File

@@ -1,74 +0,0 @@
const cds = require('@sap/cds')
const { expect } = cds.test.in(__dirname,'..')
describe('cap/samples - Messaging', ()=>{
const _model = '@capire/reviews'
const Reviews = 'sap.capire.reviews.Reviews'
beforeAll(()=>{
cds.User.default = cds.User.Privileged // hard core monkey patch
})
it ('should bootstrap sqlite in-memory db', async()=>{
const db = await cds.deploy (_model) .to ('sqlite::memory:')
await db.delete(Reviews)
expect (db.model) .not.undefined
})
let srv
it ('should serve ReviewsService', async()=>{
srv = await cds.serve('ReviewsService') .from (_model)
expect (srv.name) .to.match (/ReviewsService/)
})
let N=0, received=[], M=0
it ('should add messaging event handlers', ()=>{
srv.on('reviewed', (msg)=> received.push(msg))
})
it ('should add more messaging event handlers', ()=>{
srv.on('reviewed', ()=> ++M)
})
it ('should add review', async ()=>{
const review = { subject: "201", title: "Captivating", rating: ++N }
cds._debug = 1
const response = await srv.create ('Reviews') .entries (review)
expect (response) .to.containSubset (review)
})
it ('should add more reviews', ()=> Promise.all ([
// REVISIT: mass operation should trigger one message per entry
// srv.create('Reviews').entries(
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
// ),
srv.create ('Reviews') .entries (
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N }
),
srv.create ('Reviews') .entries (
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N }
),
srv.create ('Reviews') .entries (
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N }
),
srv.create ('Reviews') .entries (
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N }
),
]))
it ('should have received all messages', async()=> {
await new Promise((done)=>setImmediate(done))
expect(M).equals(N)
expect(received.length).equals(N)
expect(received.map(m=>m.data)).to.deep.equal([
{ count: 1, subject: '201', rating: 1 },
{ count: 2, subject: '201', rating: 1.5 },
{ count: 3, subject: '201', rating: 2 },
{ count: 4, subject: '201', rating: 2.5 },
{ count: 5, subject: '201', rating: 3 },
])
})
})

View File

@@ -1,101 +0,0 @@
const cds = require('@sap/cds')
const { GET, expect, axios } = cds.test ('@capire/bookshop')
axios.defaults.auth = { username: 'alice', password: 'admin' }
describe('cap/samples - Bookshop APIs', () => {
it('serves $metadata documents in v4', async () => {
const { headers, status, data } = await GET `/browse/$metadata`
expect(status).to.equal(200)
expect(headers).to.contain({
// 'content-type': 'application/xml', //> fails with 'application/xml;charset=utf-8', which is set by express
'odata-version': '4.0',
})
expect(headers['content-type']).to.match(/application\/xml/)
expect(data).to.contain('<EntitySet Name="Books" EntityType="CatalogService.Books">')
expect(data).to.contain('<Annotation Term="Common.Label" String="Currency"/>')
})
it('serves ListOfBooks?$expand=genre,currency', async () => {
const Mystery = { name: 'Mystery' }
const Romance = { name: 'Romance' }
const USD = { code: 'USD', name: 'US Dollar', descr: null, symbol: '$' }
const { data } = await GET `/browse/ListOfBooks ${{
params: { $search: 'Po', $select: `title,author`, $expand:`genre,currency` },
}}`
expect(data.value).to.containSubset([
{ ID: 251, title: 'The Raven', author: 'Edgar Allen Poe', genre:Mystery, currency:USD },
{ ID: 252, title: 'Eleonora', author: 'Edgar Allen Poe', genre:Romance, currency:USD },
])
})
describe('query options...', () => {
it('supports $search in multiple fields', async () => {
const { data } = await GET `/browse/Books ${{
params: { $search: 'Po', $select: `title,author` },
}}`
expect(data.value).to.containSubset([
{ ID: 201, title: 'Wuthering Heights', author: 'Emily Brontë' },
{ ID: 207, title: 'Jane Eyre', author: 'Charlotte Brontë' },
{ ID: 251, title: 'The Raven', author: 'Edgar Allen Poe' },
{ ID: 252, title: 'Eleonora', author: 'Edgar Allen Poe' },
])
})
it('supports $select', async () => {
const { data } = await GET(`/browse/Books`, {
params: { $select: `ID,title` },
})
expect(data.value).to.containSubset([
{ ID: 201, title: 'Wuthering Heights' },
{ ID: 207, title: 'Jane Eyre' },
{ ID: 251, title: 'The Raven' },
{ ID: 252, title: 'Eleonora' },
{ ID: 271, title: 'Catweazle' },
])
})
it('supports $expand', async () => {
const { data } = await GET(`/admin/Authors`, {
params: {
$select: `name`,
$expand: `books($select=title)`,
},
})
expect(data.value).to.containSubset([
{ name: 'Emily Brontë', books: [{ title: 'Wuthering Heights' }] },
{ name: 'Charlotte Brontë', books: [{ title: 'Jane Eyre' }] },
{ name: 'Edgar Allen Poe', books: [{ title: 'The Raven' }, { title: 'Eleonora' }] },
{ name: 'Richard Carpenter', books: [{ title: 'Catweazle' }] },
])
})
it('supports $value requests', async () => {
const { data } = await GET`/admin/Books/201/stock/$value`
expect(data).to.equal(12)
})
it('supports $top/$skip paging', async () => {
const { data: p1 } = await GET`/browse/Books?$select=title&$top=3`
expect(p1.value).to.containSubset([
{ ID: 201, title: 'Wuthering Heights' },
{ ID: 207, title: 'Jane Eyre' },
{ ID: 251, title: 'The Raven' },
])
const { data: p2 } = await GET`/browse/Books?$select=title&$skip=3`
expect(p2.value).to.containSubset([
{ ID: 252, title: 'Eleonora' },
{ ID: 271, title: 'Catweazle' },
])
})
})
it('serves user info', async () => {
const { data: alice } = await GET `/user/me`
expect(alice).to.containSubset({ id: 'alice' })
const { data: joe } = await GET (`/user/me`, {auth: { username: 'joe' }})
expect(joe).to.containSubset({ id: 'joe' })
})
})

View File

@@ -1,94 +0,0 @@
@server = http://localhost:4004
@me = Authorization: Basic {{$processEnv USER}}:
### ------------------------------------------------------------------------
# Get service info
GET {{server}}/browse
{{me}}
### ------------------------------------------------------------------------
# Get $metadata document
GET {{server}}/browse/$metadata
{{me}}
### ------------------------------------------------------------------------
# Browse Books as any user
GET {{server}}/browse/ListOfBooks?
# &$select=title,stock
&$expand=genre
# &sap-language=de
{{me}}
### ------------------------------------------------------------------------
# Fetch Authors as admin
GET {{server}}/admin/Authors?
# &$select=name,dateOfBirth,placeOfBirth
# &$expand=books($select=title;$expand=currency)
# &$filter=ID eq 101
# &sap-language=de
Authorization: Basic alice:
### ------------------------------------------------------------------------
# Create Author
POST {{server}}/admin/Authors
Content-Type: application/json;IEEE754Compatible=true
Authorization: Basic alice:
{
"ID": 112,
"name": "Shakespeeeeere"
}
### ------------------------------------------------------------------------
# Create book
POST {{server}}/admin/Books
Content-Type: application/json;IEEE754Compatible=true
Authorization: Basic alice:
{
"ID": 2,
"title": "Poems : Pocket Poets",
"descr": "The Everyman's Library Pocket Poets hardcover series is popular for its compact size and reasonable price which does not compromise content. Poems: Bronte contains poems that demonstrate a sensibility elemental in its force with an imaginative discipline and flexibility of the highest order. Also included are an Editor's Note and an index of first lines.",
"author": { "ID": 101 },
"genre": { "ID": "12aaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" },
"stock": 5,
"price": "12.05",
"currency": { "code": "USD" }
}
### ------------------------------------------------------------------------
# Put image to books
PUT {{server}}/admin/Books(2)/image
Content-Type: image/png
Authorization: Basic alice:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANwAAADcCAYAAAAbWs+BAAAGwElEQVR4Ae3cwZFbNxBFUY5rkrDTmKAUk5QT03Aa44U22KC7NHptw+DRikVAXf8fzC3u8Hj4R4AAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAgZzAW26USQT+e4HPx+Mz+RRvj0e0kT+SD2cWAQK1gOBqH6sEogKCi3IaRqAWEFztY5VAVEBwUU7DCNQCgqt9rBKICgguymkYgVpAcLWPVQJRAcFFOQ0jUAsIrvaxSiAqILgop2EEagHB1T5WCUQFBBflNIxALSC42scqgaiA4KKchhGoBQRX+1glEBUQXJTTMAK1gOBqH6sEogKCi3IaRqAWeK+Xb1z9iN558fHxcSPS9p2ezx/ROz4e4TtIHt+3j/61hW9f+2+7/+UXbifjewIDAoIbQDWSwE5AcDsZ3xMYEBDcAKqRBHYCgtvJ+J7AgIDgBlCNJLATENxOxvcEBgQEN4BqJIGdgOB2Mr4nMCAguAFUIwnsBAS3k/E9gQEBwQ2gGklgJyC4nYzvCQwICG4A1UgCOwHB7WR8T2BAQHADqEYS2AkIbifjewIDAoIbQDWSwE5AcDsZ3xMYEEjfTzHwiK91B8npd6Q8n8/oGQ/ckRJ9vvQwv3BpUfMIFAKCK3AsEUgLCC4tah6BQkBwBY4lAmkBwaVFzSNQCAiuwLFEIC0guLSoeQQKAcEVOJYIpAUElxY1j0AhILgCxxKBtIDg0qLmESgEBFfgWCKQFhBcWtQ8AoWA4AocSwTSAoJLi5pHoBAQXIFjiUBaQHBpUfMIFAKCK3AsEUgLCC4tah6BQmDgTpPsHSTFs39p6fQ7Q770UsV/Ov19X+2OFL9wxR+rJQJpAcGlRc0jUAgIrsCxRCAtILi0qHkECgHBFTiWCKQFBJcWNY9AISC4AscSgbSA4NKi5hEoBARX4FgikBYQXFrUPAKFgOAKHEsE0gKCS4uaR6AQEFyBY4lAWkBwaVHzCBQCgitwLBFICwguLWoegUJAcAWOJQJpAcGlRc0jUAgIrsCxRCAt8J4eePq89B0ar3ZnyOnve/rfn1+400/I810lILirjtPLnC4guNNPyPNdJSC4q47Ty5wuILjTT8jzXSUguKuO08ucLiC400/I810lILirjtPLnC4guNNPyPNdJSC4q47Ty5wuILjTT8jzXSUguKuO08ucLiC400/I810lILirjtPLnC4guNNPyPNdJSC4q47Ty5wuILjTT8jzXSUguKuO08ucLiC400/I810l8JZ/m78+szP/zI47fJo7Q37vgJ7PHwN/07/3TOv/9gu3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhAcMPAxhNYBQS3avhMYFhg4P6H9J0maYHXuiMlrXf+vOfA33Turf3C5SxNItAKCK4lsoFATkBwOUuTCLQCgmuJbCCQExBcztIkAq2A4FoiGwjkBASXszSJQCsguJbIBgI5AcHlLE0i0AoIriWygUBOQHA5S5MItAKCa4lsIJATEFzO0iQCrYDgWiIbCOQEBJezNIlAKyC4lsgGAjkBweUsTSLQCgiuJbKBQE5AcDlLkwi0Akff//Dz6U+/I6U1/sUNr3bnytl3kPzi4bXb/cK1RDYQyAkILmdpEoFWQHAtkQ0EcgKCy1maRKAVEFxLZAOBnIDgcpYmEWgFBNcS2UAgJyC4nKVJBFoBwbVENhDICQguZ2kSgVZAcC2RDQRyAoLLWZpEoBUQXEtkA4GcgOByliYRaAUE1xLZQCAnILicpUkEWgHBtUQ2EMgJCC5naRKBVkBwLZENBHIC/4M7TXIv+3PS22d24qvdQfL3C/7N5P5i/MLlLE0i0AoIriWygUBOQHA5S5MItAKCa4lsIJATEFzO0iQCrYDgWiIbCOQEBJezNIlAKyC4lsgGAjkBweUsTSLQCgiuJbKBQE5AcDlLkwi0AoJriWwgkBMQXM7SJAKtgOBaIhsI5AQEl7M0iUArILiWyAYCOQHB5SxNItAKCK4lsoFATkBwOUuTCBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIDAvyrwDySEJ2VQgUSoAAAAAElFTkSuQmCC
### ------------------------------------------------------------------------
# Reading image from from the server directly
GET {{server}}/browse/Books(2)/image
### ------------------------------------------------------------------------
# Submit Order as authenticated user
# (send that three times to get out-of-stock message)
POST {{server}}/browse/submitOrder
Content-Type: application/json
{{me}}
{ "book":201, "quantity":5 }
### ------------------------------------------------------------------------
# Browse Genres
GET {{server}}/browse/Genres?
# &$filter=parent_ID eq null&$select=name
# &$expand=children($select=name)
{{me}}

View File

@@ -1,126 +0,0 @@
const cds = require('@sap/cds/lib')
const { GET, expect, axios } = cds.test(__dirname)
// Fetch API disallows GET|HEAD requests with body
if (axios.constructor.name === 'Naxios') it = it.skip
describe ('GET w/ query in body', () => {
it ('serves CQN query objects in body', async () => {
const {data:books} = await GET ('/hcql/admin', {
headers: { 'Content-Type': 'application/json' },
data: cds.ql `SELECT from Books`
})
expect(books).to.be.an('array').of.length(5)
})
it ('serves plain CQL strings in body', async () => {
const {data:books} = await GET ('/hcql/admin', {
headers: { 'Content-Type': 'text/plain' },
data: `SELECT from Books`
})
expect(books).to.be.an('array').of.length(5)
})
it ('serves complex and deep queries', async () => {
const {data:books} = await GET ('/hcql/admin', {
headers: { 'Content-Type': 'text/plain' },
data: `SELECT from Authors {
name,
books [order by title] {
title,
genre.name as genre
}
}`
})
expect(books).to.deep.equal([
{
name: "Emily Brontë",
books: [
{ title: "Wuthering Heights", genre: 'Drama' }
]
},
{
name: "Charlotte Brontë",
books: [
{ title: "Jane Eyre", genre: 'Drama' }
]
},
{
name: "Edgar Allen Poe",
books: [
{ title: "Eleonora", genre: 'Romance' },
{ title: "The Raven", genre: 'Mystery' },
]
},
{
name: "Richard Carpenter",
books: [
{ title: "Catweazle", genre: 'Fantasy' }
]
}
])
})
})
describe ('Sluggified variants', () => {
test ('GET /Books', async () => {
const {data:books} = await GET ('/hcql/admin/Books')
expect(books).to.be.an('array').of.length(5)
expect(books.length).to.eql(5) //.of.length(5)
})
test ('GET /Books/201', async () => {
const {data:book} = await GET ('/hcql/admin/Books/201')
expect(book).to.be.an('object')
expect(book).to.have.property ('title', "Wuthering Heights")
})
test ('GET /Books { title, author.name as author }' , async () => {
const {data:books} = await GET ('/hcql/admin/Books { title, author.name as author } order by ID')
expect(books).to.deep.equal ([
{ title: "Wuthering Heights", author: "Emily Brontë" },
{ title: "Jane Eyre", author: "Charlotte Brontë" },
{ title: "The Raven", author: "Edgar Allen Poe" },
{ title: "Eleonora", author: "Edgar Allen Poe" },
{ title: "Catweazle", author: "Richard Carpenter" }
])
})
test ('GET /Books/201 w/ CQL tail in URL' , async () => {
const {data:book} = await GET ('/hcql/admin/Books/201 { title, author.name as author } order by ID')
expect(book).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
})
it ('GET /Books/201 w/ CQL fragment in body' , async () => {
const {data:book} = await GET ('/hcql/admin/Books/201', {
headers: { 'Content-Type': 'text/plain' },
data: `{ title, author.name as author }`
})
expect(book).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
})
it ('GET /Books/201 w/ CQN fragment in body' , async () => {
const {data:book} = await GET ('/hcql/admin/Books/201', {
data: cds.ql `SELECT title, author.name as author` .SELECT
})
expect(book).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
})
it ('GET /Books/201 w/ tail in URL plus CQL/CQN fragments in body' , async () => {
const {data:[b1]} = await GET ('/hcql/admin/Books where ID=201', {
data: cds.ql `SELECT title, author.name as author` .SELECT
})
expect(b1).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
const {data:[b2]} = await GET ('/hcql/admin/Books where ID=201', {
headers: { 'Content-Type': 'text/plain' },
data: `{ title, author.name as author }`
})
expect(b2).to.deep.equal ({ title: "Wuthering Heights", author: "Emily Brontë" })
})
})

View File

@@ -1,225 +0,0 @@
@server = http://localhost:4004
GET {{server}}/odata/v4/admin/Authors?
&$select=ID,name
&$expand=books($select=ID,title)
&$count=true
###
#
# The basic variant expects a CQN object passed as an application/json body
# to a POST request. This is also the fastest one, as it doesn't need CQL parsing.
# Note: $count is returned in X-Total-Count response header
#
GET {{server}}/hcql/admin
Content-Type: application/json
# Accept-Language: de
{ "SELECT": {
"from": { "ref": [ "Authors" ] },
"columns": [
{ "ref": [ "name" ] },
{ "ref": [ "books" ], "expand": [
{ "ref": [ "ID" ] },
{ "ref": [ "title" ] }
]}
],
"count": true
}}
###
POST {{server}}/hcql/browse/submitOrder?book=201&quantity=2
Authorization: Basic alice:
###
POST {{server}}/hcql/browse/submitOrder
Authorization: Basic alice:
Content-Type: application/json
{
"book": 201,
"quantity": 2
}
###
GET {{server}}/hcql/browse/submitOrder?book=201&quantity=2
Authorization: Basic alice:
###
#
# Alternatively you can pass a CQL string as plain/text body
#
GET {{server}}/hcql/admin
Content-Type: text/plain
# X-Total-Count: true
SELECT from Authors { name, books { title }}
# SELECT from Books { title, currency }
###
#
# In addition we offer convenience slug routes...
# .e.g. /srv/entity routes
#
GET {{server}}/hcql/admin/Books
###
GET {{server}}/hcql/admin/Books/201
###
GET {{server}}/hcql/admin/Books { ID, title, author.name as author }
###
GET {{server}}/hcql/admin/Books order by stock desc
Content-Type: text/plain
{ title, stock }
###
GET {{server}}/hcql/admin/Books/201 { ID, title, author.name }
###
GET {{server}}/hcql/admin/Books/201 { ID, title, author{name} }
###
POST {{server}}/hcql/admin/Books?title=The Black Cat&author_ID=101
###
POST {{server}}/hcql/admin/Books?title=The Black Cat
Content-Type: application/json
{
"author_ID": 101
}
###
POST {{server}}/hcql/admin/Books
Content-Type: application/json
{
"title": "The Black Cat",
"author": { "ID": 101 }
}
###
PUT {{server}}/hcql/admin/Books/275?title=Catastrophe
###
PATCH {{server}}/hcql/admin/Books/275
Content-Type: application/json
{
"title": "Catastrophe"
}
###
GET {{server}}/hcql/admin/Authors { name, books { ID, title }}
###
GET {{server}}/hcql/admin/Books { ID, title, author.name as author } order by ID desc
###
// ------------------------------------
POST {{server}}/hcql/admin
Content-Type: application/json
{"SELECT": { "from": { "ref": ["Books"] }}}
###
POST {{server}}/hcql/admin
Content-Type: text/plain
SELECT from Authors {
name as author,
books {
title,
stock,
price,
currency { * }
}
}
where name like '%Bro%'
order by name asc
###
#
# Simple REST-style URLs as supported as well
#
GET {{server}}/hcql/admin/Books
###
GET {{server}}/hcql/admin/Books/201
###
#
# REST-style URLs can be combined with trailing CQL in the path, in plain
# text body, or with projections sent as application/json array
#
GET {{server}}/hcql/admin/Books order by stock desc
###
GET {{server}}/hcql/admin/Books { title as book, stock } order by stock desc
###
GET {{server}}/hcql/admin/Authors
Content-Type: text/plain
Accept-Language: fr
{
ID, name as author,
books {
title,
stock,
currency { * }
}
}
where name like '%Bro%'
order by name asc
###
GET {{server}}/hcql/admin/Books/201 { title, stock }
###
GET {{server}}/hcql/admin/Books order by stock desc
Content-Type: text/plain
{ title, stock }
###
#
# CQL adaptor also provides access to the underlying CSN schema
#
GET {{server}}/hcql/admin/$csn
###
#
# CQL adaptor also supports INSERTs, UPDATEs, DELETEs ...
#
POST {{server}}/hcql/admin
Content-Type: application/jsonin wonderland
{ "INSERT": {
"into": "Books",
"entries": [{
"title": "The Black Cat",
"author": { "ID": 150 }
}]
}}
###

View File

@@ -1,26 +0,0 @@
@server = http://localhost:4004
GET {{server}}/odata/v2/admin/Authors
Authorization: Basic alice:
###
GET {{server}}/odata/v2/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
Authorization: Basic alice:
###
GET {{server}}/odata/v4/admin/Authors
Authorization: Basic alice:
###
GET {{server}}/odata/v4/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
Authorization: Basic alice:
###
GET {{server}}/rest/admin/Authors
Authorization: Basic alice:
###
GET {{server}}/rest/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
Authorization: Basic alice:
###

View File

@@ -1,9 +0,0 @@
@server = http://localhost:4004
GET {{server}}/rest/admin/Authors
Authorization: Basic alice:
###
GET {{server}}/rest/admin/Authors?$select=ID,name&$expand=books($select=ID,title)
Authorization: Basic alice:
###

View File

@@ -1,4 +0,0 @@
using { CatalogService, AdminService } from '@capire/bookstore';
annotate CatalogService with @hcql @odata @path:'browse' @requires:[];
annotate AdminService with @hcql @odata @path:'admin';

View File

@@ -1,21 +0,0 @@
Books = Books
Book = Book
ID = ID
Title = Title
Description = Description
Stock = Stock
Image = Image
Price = Price
Currency = Currency
Authors = Authors
Author = Author
AuthorID = Author''s ID
Name = Name
DateOfBirth = Date of Birth
DateOfDeath = Date of Death
PlaceOfBirth = Place of Birth
PlaceOfDeath = Place of Death
Genres = Genres
Genre = Genre

View File

@@ -1,20 +0,0 @@
Books = Livres
Book = Livre
Title = Titre
Description = Description
Stock = Action
Image = Image
Price = Prix
Currency = Devise
Authors = Auteurs
Author = Auteur
AuthorID = ID de l''auteur
Name = Nom
DateOfBirth = Date de naissance
DateOfDeath = Date de décès
PlaceOfBirth = Lieu de naissance
PlaceOfDeath = Lieu de décès
Genres = Genre
Genre = Genre

View File

@@ -1,34 +0,0 @@
400 = Ungültige Anfrage
401 = Nicht autorisiert
403 = Verboten
404 = Nicht gefunden
405 = Methode nicht zulässig
406 = Nicht akzeptabel
407 = Proxy-Authentifizierung erforderlich
408 = Anfrage-Timeout
409 = Konflikt
410 = Weg
411 = Erforderliche Länge
412 = Vorbedingung fehlgeschlagen
413 = Nutzlast zu groß
414 = URI zu lang
415 = Nicht unterstützter Medientyp
416 = Bereich nicht erfüllbar
417 = Erwartung fehlgeschlagen
422 = Nicht verarbeitbarer Inhalt
424 = Fehlgeschlagene Abhängigkeit
428 = Vorbedingung erforderlich
429 = Zu viele Anfragen
431 = Anfrage-Headerfelder zu groß
451 = Aus rechtlichen Gründen nicht verfügbar
500 = Interner Serverfehler
501 = Der Server unterstützt die zur Erfüllung der Anfrage erforderliche Funktionalität nicht
502 = Ungültiges Gateway
503 = Dienst nicht verfügbar
504 = Gateway-Timeout
ASSERT_RANGE = Wert {0} liegt nicht im angegebenen Bereich [{1}, {2}]
ASSERT_FORMAT = Wert "{0}" liegt nicht im angegebenen Format "{1}"
ASSERT_ARRAY = Wert muss ein Array sein
ASSERT_ENUM = Wert {0} ist gemäß Enumerationsdeklaration {{1}} ungültig
ASSERT_NOT_NULL = Wert ist erforderlich

View File

@@ -1,34 +0,0 @@
400 = Bad Request
401 = Unauthorized
403 = Forbidden
404 = Not Found
405 = Method Not Allowed
406 = Not Acceptable
407 = Proxy Authentication Required
408 = Request Timeout
409 = Conflict
410 = Gone
411 = Length Required
412 = Precondition Failed
413 = Payload Too Large
414 = URI Too Long
415 = Unsupported Media Type
416 = Range Not Satisfiable
417 = Expectation Failed
422 = Unprocessable Content
424 = Failed Dependency
428 = Precondition Required
429 = Too Many Requests
431 = Request Header Fields Too Large
451 = Unavailable For Legal Reasons
500 = Internal Server Error
501 = The server does not support the functionality required to fulfill the request
502 = Bad Gateway
503 = Service Unavailable
504 = Gateway Timeout
ASSERT_RANGE = Value {0} is not in specified range [{1}, {2}]
ASSERT_FORMAT = Value "{0}" is not in specified format "{1}"
ASSERT_ARRAY = Value must be an array
ASSERT_ENUM = Value {0} is invalid according to enum declaration {{1}}
ASSERT_NOT_NULL = Value is required

View File

@@ -1,34 +0,0 @@
400 = Requête incorrecte
401 = Non autorisée
403 = Interdite
404 = Introuvable
405 = Méthode non autorisée
406 = Non acceptable
407 = Authentification proxy requise
408 = Délai d''expiration de la requête
409 = Conflit
410 = Disparu
411 = Longueur requise
412 = Échec de la condition préalable
413 = Charge utile trop importante
414 = URI trop longue
415 = Type de média non pris en charge
416 = Plage non satisfaisante
417 = Échec de l''attente
422 = Contenu non traitable
424 = Dépendance échouée
428 = Condition préalable requise
429 = Trop de requêtes
431 = Champs d''en-tête de requête trop importants
451 = Indisponible pour des raisons juridiques
500 = Erreur interne du serveur
501 = Le serveur ne prend pas en charge la fonctionnalité requise pour répondre à la requête
502 = Passerelle incorrecte
503 = Service indisponible
504 = Délai d''attente de la passerelle
ASSERT_RANGE = La valeur {0} n''est pas dans la plage spécifiée [{1}, {2}]
ASSERT_FORMAT = La valeur "{0}" n''est pas au format spécifié "{1}"
ASSERT_ARRAY = La valeur doit être un tableau
ASSERT_ENUM = La valeur {0} n''est pas valide selon la déclaration d''énumération {{1}}
ASSERT_NOT_NULL = La valeur est obligatoire

View File

@@ -1,5 +0,0 @@
AuthorName = Name des Autors
Age = Alter
rder = Bestellung
Orders = Bestellungen
Price = Preis

View File

@@ -1,8 +0,0 @@
Age = Age
Lifetime = Lifetime
SubGenres = Subgenre
NumCode = Numeric Code
MinorUnit = Minor Unit
Exponent = Exponent

View File

@@ -1,52 +0,0 @@
using {AdminService} from '@capire/bookshop';
annotate AdminService.Authors with @odata.draft.enabled;
////////////////////////////////////////////////////////////////////////////
//
// Authors Object Page
//
annotate AdminService.Authors with @(UI : {
HeaderInfo : {
TypeName : 'Author',
TypeNamePlural : 'Authors',
Description : {Value : lifetime}
},
Facets : [
{
$Type : 'UI.ReferenceFacet',
Label : '{i18n>Details}',
Target : '@UI.FieldGroup#Details'
},
{
$Type : 'UI.ReferenceFacet',
Label : '{i18n>Books}',
Target : 'books/@UI.LineItem'
},
],
FieldGroup #Details : {Data : [
{Value : placeOfBirth},
{Value : placeOfDeath},
{Value : dateOfBirth},
{Value : dateOfDeath},
{
Value : age,
Label : '{i18n>Age}'
},
]},
});
// Workaround to avoid errors for unknown db-specific calculated fields above
extend sap.capire.bookshop.Authors with {
virtual age : Integer;
virtual lifetime : String;
}
annotate AdminService.Authors with {
age @Common.Label : '{i18n>Age}';
lifetime @Common.Label : '{i18n>Lifetime}'
}
// Workaround for Fiori popup for asking user to enter a new UUID on Create
annotate AdminService.Authors with { ID @Core.Computed; }

View File

@@ -1,7 +0,0 @@
sap.ui.define(["sap/fe/core/AppComponent"], function (AppComponent) {
"use strict";
return AppComponent.extend("authors.Component", {
metadata: { manifest: "json" },
});
});
/* eslint no-undef:0 */

View File

@@ -1,11 +0,0 @@
# This is the resource bundle of itelo
# __ldi.translation.uuid=c3431418-9caf-11e8-98d0-529269fb1459
# JCI app descriptor contains lower case TITLE
appTitle=Manage Authors
# JCI app descriptor contains lower case DESCRIPTION
appSubTitle=CAP Sample Application
# JCI app descriptor contains lower case DESCRIPTION
appDescription=Bookshop Authors

View File

@@ -1,141 +0,0 @@
{
"_version": "1.28.0",
"sap.app": {
"id": "authors",
"type": "application",
"title": "Manage Authors",
"description": "Sample Application",
"i18n": "i18n/i18n.properties",
"applicationVersion": {
"version": "1.0.0"
},
"dataSources": {
"AdminService": {
"uri": "admin/",
"type": "OData",
"settings": {
"odataVersion": "4.0"
}
}
},
"sourceTemplate": {
"id": "ui5template.basicSAPUI5ApplicationProject",
"-id": "ui5template.smartTemplate",
"version": "1.40.12"
},
"crossNavigation": {
"inbounds": {
"intent1": {
"signature": {
"parameters": {
"Books.author.ID":{
"renameTo": "ID"
}
},
"additionalParameters": "ignored"
},
"semanticObject": "Authors",
"action": "manage",
"title": "{{appTitle}}",
"info": "{{appInfo}}",
"subTitle": "{{appSubTitle}}",
"icon": "sap-icon://SAP-icons-TNT/user",
"indicatorDataSource": {
"dataSource": "AdminService",
"path": "Authors/$count",
"refresh": 1800
}
}
}
}
},
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.81.0",
"libs": {
"sap.fe.templates": {}
}
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"uri": "i18n/i18n.properties"
},
"": {
"dataSource": "AdminService",
"settings": {
"synchronizationMode": "None",
"operationMode": "Server",
"autoExpandSelect": true,
"earlyRequests": true,
"groupProperties": {
"default": {
"submit": "Auto"
}
}
}
}
},
"routing": {
"routes": [
{
"pattern": ":?query:",
"name": "AuthorsList",
"target": "AuthorsList"
},
{
"pattern": "Authors({key}):?query:",
"name": "AuthorsDetails",
"target": "AuthorsDetails"
}
],
"targets": {
"AuthorsList": {
"type": "Component",
"id": "AuthorsList",
"name": "sap.fe.templates.ListReport",
"options": {
"settings": {
"entitySet": "Authors",
"initialLoad": true,
"navigation": {
"Authors": {
"detail": {
"route": "AuthorsDetails"
}
}
}
}
}
},
"AuthorsDetails": {
"type": "Component",
"id": "AuthorsDetailsList",
"name": "sap.fe.templates.ObjectPage",
"options": {
"settings": {
"entitySet": "Authors"
}
}
}
}
},
"contentDensities": {
"compact": true,
"cozy": true
}
},
"sap.ui": {
"technology": "UI5",
"fullWidth": false,
"deviceTypes":{
"desktop": true,
"tablet": true,
"phone": true
}
},
"sap.fiori": {
"registrationIds": [],
"archeType": "transactional"
}
}

View File

@@ -1,112 +0,0 @@
using { AdminService } from '@capire/bookstore';
using from '../common'; // to help UI linter get the complete annotations
////////////////////////////////////////////////////////////////////////////
//
// Books Object Page
//
annotate AdminService.Books with @(
UI: {
Facets: [
{$Type: 'UI.ReferenceFacet', Label: '{i18n>General}', Target: '@UI.FieldGroup#General'},
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Translations}', Target: 'texts/@UI.LineItem'},
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'},
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Admin}', Target: '@UI.FieldGroup#Admin'},
],
FieldGroup#General: {
Data: [
{Value: title},
{Value: author_ID},
{Value: genre_ID},
{Value: descr},
]
},
FieldGroup#Details: {
Data: [
{Value: stock},
{Value: price},
{Value: currency_code, Label: '{i18n>Currency}'},
]
},
FieldGroup#Admin: {
Data: [
{Value: createdBy},
{Value: createdAt},
{Value: modifiedBy},
{Value: modifiedAt}
]
}
}
);
////////////////////////////////////////////////////////////////////////////
//
// Value Help for Tree Table
//
annotate AdminService.Books with {
genre @(Common: {
Label : 'Genre',
ValueList: {
CollectionPath : 'Genres',
Parameters : [
{
$Type : 'Common.ValueListParameterDisplayOnly',
ValueListProperty: 'name',
},
{
$Type : 'Common.ValueListParameterInOut',
LocalDataProperty: genre_ID,
ValueListProperty: 'ID',
}
],
}
});
}
// Hide ID because of the ValueHelp
annotate AdminService.Genres with {
ID @UI.Hidden;
};
////////////////////////////////////////////////////////////
//
// Draft for Localized Data
//
annotate sap.capire.bookshop.Books with @fiori.draft.enabled;
annotate AdminService.Books with @odata.draft.enabled;
annotate AdminService.Books.texts with @(
UI: {
Identification: [{Value:title}],
SelectionFields: [ locale, title ],
LineItem: [
{Value: locale, Label: 'Locale'},
{Value: title, Label: 'Title'},
{Value: descr, Label: 'Description'},
]
}
);
annotate AdminService.Books.texts with {
ID @UI.Hidden;
ID_texts @UI.Hidden;
};
// Add Value Help for Locales
annotate AdminService.Books.texts {
locale @(
ValueList.entity:'Languages', Common.ValueListWithFixedValues, //show as drop down, not a dialog
)
}
// In addition we need to expose Languages through AdminService as a target for ValueList
using { sap } from '@sap/cds/common';
extend service AdminService {
@readonly entity Languages as projection on sap.common.Languages;
}
// Workaround for Fiori popup for asking user to enter a new UUID on Create
annotate AdminService.Books with { ID @Core.Computed; }

View File

@@ -1,8 +0,0 @@
sap.ui.define(["sap/fe/core/AppComponent"], function(AppComponent) {
"use strict";
return AppComponent.extend("books.Component", {
metadata: { manifest: "json" }
});
});
/* eslint no-undef:0 */

View File

@@ -1,167 +0,0 @@
{
"services": {
"LaunchPage": {
"adapter": {
"config": {
"groups": [
{
"id": "Bookshop",
"title": "Bookshop",
"isPreset": true,
"isVisible": true,
"isGroupLocked": false,
"tiles": [
{
"id": "BrowseBooks",
"tileType": "sap.ushell.ui.tile.StaticTile",
"properties": {
"title": "Browse Books",
"targetURL": "#Books-display"
}
},
{
"id": "BrowseGenres",
"tileType": "sap.ushell.ui.tile.StaticTile",
"properties": {
"title": "Browse Genres",
"targetURL": "#Genres-display"
}
}
]
},
{
"id": "Administration",
"title": "Administration",
"isPreset": true,
"isVisible": true,
"isGroupLocked": false,
"tiles": [
{
"id": "ManageBooks",
"tileType": "sap.ushell.ui.tile.StaticTile",
"properties": {
"title": "Manage Books",
"targetURL": "#Books-manage"
}
},
{
"id": "ManageAuthors",
"tileType": "sap.ushell.ui.tile.StaticTile",
"properties": {
"title": "Manage Authors",
"targetURL": "#Authors-manage"
}
},
{
"id": "ManageOrders",
"tileType": "sap.ushell.ui.tile.StaticTile",
"properties": {
"title": "Manage Orders",
"targetURL": "#Orders-manage"
}
}
]
}
]
}
}
},
"NavTargetResolution": {
"config": {
"enableClientSideTargetResolution": true
}
},
"ClientSideTargetResolution": {
"adapter": {
"config": {
"inbounds": {
"BrowseBooks": {
"semanticObject": "Books",
"action": "display",
"title": "Browse Books",
"signature": {
"parameters": {
"Books.ID": {
"renameTo": "ID"
},
"Authors.books.ID": {
"renameTo": "ID"
}
},
"additionalParameters": "ignored"
},
"resolutionResult": {
"applicationType": "SAPUI5",
"additionalInformation": "SAPUI5.Component=bookshop",
"url": "/browse/webapp"
}
},
"BrowseAuthors": {
"semanticObject": "Authors",
"action": "manage",
"title": "Browse Authors",
"signature": {
"parameters": {
"Books.author.ID":{
"renameTo": "ID"
}
},
"additionalParameters": "ignored"
},
"resolutionResult": {
"applicationType": "SAPUI5",
"additionalInformation": "SAPUI5.Component=authors",
"url": "/admin-authors/webapp"
}
},
"BrowseGenres": {
"semanticObject": "Genres",
"action": "display",
"title": "Browse Genres",
"signature": {
"parameters": {
"Genre.ID": {
"renameTo": "ID"
}
},
"additionalParameters": "ignored"
},
"resolutionResult": {
"applicationType": "SAPUI5",
"additionalInformation": "SAPUI5.Component=genres",
"url": "/genres/webapp"
}
},
"ManageBooks": {
"semanticObject": "Books",
"action": "manage",
"title": "Manage Books",
"signature": {
"parameters": {},
"additionalParameters": "allowed"
},
"resolutionResult": {
"applicationType": "SAPUI5",
"additionalInformation": "SAPUI5.Component=books",
"url": "/admin-books/webapp"
}
},
"ManageOrders": {
"semanticObject": "Orders",
"action": "manage",
"signature": {
"parameters": {},
"additionalParameters": "allowed"
},
"resolutionResult": {
"applicationType": "SAPUI5",
"additionalInformation": "SAPUI5.Component=orders",
"url": "/orders/webapp"
}
}
}
}
}
}
}
}

View File

@@ -1,57 +0,0 @@
using CatalogService from '@capire/bookstore';
////////////////////////////////////////////////////////////////////////////
//
// Books Object Page
//
annotate CatalogService.Books with @(UI : {
HeaderInfo : {
TypeName : '{i18n>Book}',
TypeNamePlural : '{i18n>Books}',
Description : {Value : author}
},
HeaderFacets : [{
$Type : 'UI.ReferenceFacet',
Label : '{i18n>Description}',
Target : '@UI.FieldGroup#Descr'
}, ],
Facets : [{
$Type : 'UI.ReferenceFacet',
Label : '{i18n>Details}',
Target : '@UI.FieldGroup#Price'
}, ],
FieldGroup #Descr : {Data : [{Value : descr}, ]},
FieldGroup #Price : {Data : [
{Value : price},
{
Value : currency.symbol,
Label : '{i18n>Currency}'
},
]},
});
////////////////////////////////////////////////////////////////////////////
//
// Books List Page
//
annotate CatalogService.Books with @(UI : {
SelectionFields : [
ID,
price,
currency_code
],
LineItem : [
{
Value : ID,
Label : '{i18n>Title}'
},
{
Value : author,
Label : '{i18n>Author}'
},
{Value : genre.name},
{Value : price},
{Value : currency.symbol},
]
}, );

View File

@@ -1,7 +0,0 @@
sap.ui.define(["sap/fe/core/AppComponent"], function(AppComponent) {
"use strict";
return AppComponent.extend("bookshop.Component", {
metadata: { manifest: "json" }
});
});
/* eslint no-undef:0 */

View File

@@ -1,233 +0,0 @@
/*
Common Annotations shared by all apps
*/
using { sap.capire.bookshop as my } from '@capire/bookstore';
using { sap.common } from '@capire/common';
////////////////////////////////////////////////////////////////////////////
//
// Books Lists
//
annotate my.Books with @(
Common.SemanticKey : [ID],
UI : {
Identification : [{ Value: title }],
SelectionFields : [
ID,
author_ID,
price,
currency_code
],
LineItem : [
{ Value: ID, Label: '{i18n>Title}' },
{ Value: author.ID, Label: '{i18n>Author}' },
{ Value: genre.name },
{ Value: stock },
{ Value: price },
{ Value: currency.symbol },
]
}
) {
ID @Common: {
SemanticObject : 'Books',
Text: title,
TextArrangement : #TextOnly
};
author @ValueList.entity : 'Authors';
};
annotate common.Currencies with {
symbol @Common.Label : '{i18n>Currency}';
}
////////////////////////////////////////////////////////////////////////////
//
// Books Details
//
annotate my.Books with @(UI : {HeaderInfo : {
TypeName : '{i18n>Book}',
TypeNamePlural : '{i18n>Books}',
Title : { Value: title },
Description : { Value: author.name }
}, });
////////////////////////////////////////////////////////////////////////////
//
// Books Elements
//
annotate my.Books with {
ID @title: '{i18n>ID}';
title @title: '{i18n>Title}';
genre @title: '{i18n>Genre}' @Common: { Text: genre.name, TextArrangement: #TextOnly };
author @title: '{i18n>Author}' @Common: { Text: author.name, TextArrangement: #TextOnly };
price @title: '{i18n>Price}' @Measures.ISOCurrency : currency_code;
stock @title: '{i18n>Stock}';
descr @title: '{i18n>Description}' @UI.MultiLineText;
image @title: '{i18n>Image}';
}
////////////////////////////////////////////////////////////////////////////
//
// Authors List
//
annotate my.Authors with @(
Common.SemanticKey : [ID],
UI : {
Identification : [{ Value: name}],
SelectionFields : [name],
LineItem : [
{ Value: ID },
{ Value: dateOfBirth },
{ Value: dateOfDeath },
{ Value: placeOfBirth },
{ Value: placeOfDeath },
],
}
) {
ID @Common: {
SemanticObject : 'Authors',
Text: name,
TextArrangement : #TextOnly,
};
};
////////////////////////////////////////////////////////////////////////////
//
// Author Details
//
annotate my.Authors with @(UI : {
HeaderInfo : {
TypeName : '{i18n>Author}',
TypeNamePlural : '{i18n>Authors}',
Title : { Value: name },
Description : { Value: dateOfBirth }
},
Facets : [{
$Type : 'UI.ReferenceFacet',
Target : 'books/@UI.LineItem'
}, ],
});
////////////////////////////////////////////////////////////////////////////
//
// Authors Elements
//
annotate my.Authors with {
ID @title: '{i18n>ID}';
name @title: '{i18n>Name}';
dateOfBirth @title: '{i18n>DateOfBirth}';
dateOfDeath @title: '{i18n>DateOfDeath}';
placeOfBirth @title: '{i18n>PlaceOfBirth}';
placeOfDeath @title: '{i18n>PlaceOfDeath}';
}
////////////////////////////////////////////////////////////////////////////
//
// Languages List
//
annotate common.Languages with @(
Common.SemanticKey : [code],
Identification : [{ Value: code}],
UI : {
SelectionFields : [
name,
descr
],
LineItem : [
{ Value: code },
{ Value: name },
],
}
);
////////////////////////////////////////////////////////////////////////////
//
// Language Details
//
annotate common.Languages with @(UI : {
HeaderInfo : {
TypeName : '{i18n>Language}',
TypeNamePlural : '{i18n>Languages}',
Title : { Value: name },
Description : { Value: descr }
},
Facets : [{
$Type : 'UI.ReferenceFacet',
Label : '{i18n>Details}',
Target : '@UI.FieldGroup#Details'
}, ],
FieldGroup #Details : {Data : [
{ Value: code },
{ Value: name },
{ Value: descr }
]},
});
////////////////////////////////////////////////////////////////////////////
//
// Currencies List
//
annotate common.Currencies with @(
Common.SemanticKey : [code],
Identification : [{ Value: code}],
UI : {
SelectionFields : [
name,
descr
],
LineItem : [
{ Value: descr },
{ Value: symbol },
{ Value: code },
],
}
);
////////////////////////////////////////////////////////////////////////////
//
// Currency Details
//
annotate common.Currencies with @(UI : {
HeaderInfo : {
TypeName : '{i18n>Currency}',
TypeNamePlural : '{i18n>Currencies}',
Title : { Value: descr },
Description : { Value: code }
},
Facets : [
{
$Type : 'UI.ReferenceFacet',
Label : '{i18n>Details}',
Target : '@UI.FieldGroup#Details'
},
{
$Type : 'UI.ReferenceFacet',
Label : '{i18n>Extended}',
Target : '@UI.FieldGroup#Extended'
},
],
FieldGroup #Details : {Data : [
{ Value: name },
{ Value: symbol },
{ Value: code },
{ Value: descr }
]},
FieldGroup #Extended : {Data : [
{ Value: numcode },
{ Value: minor },
{ Value: exponent }
]},
});
////////////////////////////////////////////////////////////////////////////
//
// Currencies Elements
//
annotate common.Currencies with {
numcode @title: '{i18n>NumCode}';
minor @title: '{i18n>MinorUnit}';
exponent @title: '{i18n>Exponent}';
}

View File

@@ -1,31 +0,0 @@
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bookshop</title>
<script>
window["sap-ushell-config"] = {
defaultRenderer: "fiori2",
applications: {},
};
</script>
<script id="sap-ushell-bootstrap" src="https://ui5.sap.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
<script id="sap-ui-bootstrap" src="https://ui5.sap.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout" data-sap-ui-compatVersion="edge"
data-sap-ui-theme="sap_horizon"></script>
<script>
sap.ui.getCore().attachInit(() =>
sap.ushell.Container.createRenderer().placeAt("content")
);
</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>

View File

@@ -1,33 +0,0 @@
using { sap.capire.bookshop.Genres } from '@capire/bookstore';
annotate Genres with @cds.search: {name};
annotate Genres with @readonly;
annotate Genres with {
name @title: '{i18n>Genre}';
}
// Lists
annotate Genres with @(
Common.SemanticKey : [name],
UI.SelectionFields : [name],
UI.LineItem : [
{ Value: name, Label: '{i18n>Name}' },
],
);
// Details
annotate Genres with @(UI : {
Identification : [{ Value: name }],
HeaderInfo : {
TypeName : '{i18n>Genre}',
TypeNamePlural : '{i18n>Genres}',
Title : { Value: name },
Description : { Value: ID }
}
});
// Tree Views
// annotate AdminService.Genres with @hierarchy; // upcomming simplification
using from './tree-view';
using from './value-help';

View File

@@ -1,42 +0,0 @@
using { AdminService } from '@capire/bookstore';
////////////////////////////////////////////////////////////////////////////
//
// Genres Tree View
//
// Tell Fiori about the structure of the hierarchy
annotate AdminService.Genres with @Aggregation.RecursiveHierarchy #GenresHierarchy : {
ParentNavigationProperty : parent, // navigates to a node's parent
NodeProperty : ID, // identifies a node, usually the key
};
// Fiori expects the following to be defined explicitly, even though they're always the same
extend AdminService.Genres with @(
// The columns expected by Fiori to be present in hierarchy entities
Hierarchy.RecursiveHierarchy #GenresHierarchy : {
LimitedDescendantCount : LimitedDescendantCount,
DistanceFromRoot : DistanceFromRoot,
DrillState : DrillState,
LimitedRank : LimitedRank
},
// Disallow filtering on these properties from Fiori UIs
Capabilities.FilterRestrictions.NonFilterableProperties: [
'LimitedDescendantCount',
'DistanceFromRoot',
'DrillState',
'LimitedRank'
],
// Disallow sorting on these properties from Fiori UIs
Capabilities.SortRestrictions.NonSortableProperties : [
'LimitedDescendantCount',
'DistanceFromRoot',
'DrillState',
'LimitedRank'
],
) columns { // Ensure we can query these fields from database
null as LimitedDescendantCount : Int16,
null as DistanceFromRoot : Int16,
null as DrillState : String,
null as LimitedRank : Int16,
};

View File

@@ -1,6 +0,0 @@
// Value help with Tree View
using from '../admin-books/fiori-service';
annotate AdminService.Books:genre with @Common.ValueList.PresentationVariantQualifier: 'VH';
annotate AdminService.Genres with @UI.PresentationVariant #VH: {
RecursiveHierarchyQualifier : 'GenresHierarchy',
};

View File

@@ -1,3 +0,0 @@
sap.ui.define(["sap/fe/core/AppComponent"], ac => ac.extend("genres.Component", {
metadata:{ manifest:'json' }
}))

View File

@@ -1,4 +0,0 @@
#XTIT
appTitle=Browse Genres
#XTXT
appDescription=Genres as Tree View

View File

@@ -1,2 +0,0 @@
appTitle=Zeige Genres
appDescription=Genres als Baumansicht

View File

@@ -1,124 +0,0 @@
{
"_version": "1.8.0",
"sap.app": {
"id": "genres",
"type": "application",
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"applicationVersion": {
"version": "1.0.0"
},
"dataSources": {
"AdminService": {
"uri": "admin/",
"type": "OData",
"settings": {
"odataVersion": "4.0"
}
}
},
"crossNavigation": {
"inbounds": {
"Genres-display": {
"signature": {
"parameters": {},
"additionalParameters": "allowed"
},
"semanticObject": "Genres",
"action": "display"
}
}
}
},
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.122.0",
"libs": {
"sap.fe.templates": {}
}
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"uri": "i18n/i18n.properties"
},
"": {
"dataSource": "AdminService",
"settings": {
"synchronizationMode": "None",
"operationMode": "Server",
"autoExpandSelect": true,
"earlyRequests": true,
"groupProperties": {
"default": {
"submit": "Auto"
}
}
}
}
},
"routing": {
"routes": [
{
"pattern": ":?query:",
"name": "GenresList",
"target": "GenresList"
},
{
"pattern": "Genres({key}):?query:",
"name": "GenresDetails",
"target": "GenresDetails"
}
],
"targets": {
"GenresList": {
"type": "Component",
"id": "GenresList",
"name": "sap.fe.templates.ListReport",
"options": {
"settings": {
"contextPath": "/Genres",
"navigation": {
"Genres": {
"detail": {
"route": "GenresDetails"
}
}
},
"controlConfiguration": {
"@com.sap.vocabularies.UI.v1.LineItem": {
"tableSettings": {
"hierarchyQualifier": "GenresHierarchy",
"type": "TreeTable"
}
}
}
}
}
},
"GenresDetails": {
"type": "Component",
"id": "GenresDetails",
"name": "sap.fe.templates.ObjectPage",
"options": {
"settings": {
"contextPath": "/Genres"
}
}
}
}
},
"contentDensities": {
"compact": true,
"cozy": true
}
},
"sap.ui": {
"technology": "UI5",
"fullWidth": false
},
"sap.fiori": {
"registrationIds": [],
"archeType": "transactional"
}
}

View File

@@ -1,11 +0,0 @@
/*
This model controls what gets served to Fiori frontends...
*/
using from './admin-authors/fiori-service';
using from './admin-books/fiori-service';
using from './browse/fiori-service';
using from './genres/fiori-service';
using from './common';
using from '@capire/bookstore/srv/mashup';

View File

@@ -1,10 +0,0 @@
//
// Add Author.age and .lifetime with a DB-specific function
//
using { AdminService } from '@capire/bookshop';
extend projection AdminService.Authors with {
YEARS_BETWEEN(dateOfBirth, dateOfDeath) as age: Integer,
YEAR(dateOfBirth) || ' ' || YEAR(dateOfDeath) as lifetime : String
}

View File

@@ -1,10 +0,0 @@
//
// Add Author.age and .lifetime with a DB-specific function
//
using { AdminService } from '@capire/bookshop';
extend projection AdminService.Authors with {
strftime('%Y',dateOfDeath)-strftime('%Y',dateOfBirth) as age: Integer,
strftime('%Y',dateOfBirth) || ' ' || strftime('%Y',dateOfDeath) as lifetime : String
}

View File

@@ -1,2 +0,0 @@
namespace sap.capire.bookshop; //> important for reflection
using from './srv/mashup';

View File

@@ -1,51 +0,0 @@
{
"name": "@capire/bookstore",
"version": "1.0.0",
"dependencies": {
"@capire/bookshop": "*",
"@capire/reviews": "*",
"@capire/orders": "*",
"@capire/common": "*",
"@capire/data-viewer": "*",
"@cap-js/hana": ">=1",
"@sap-cloud-sdk/http-client": "^4",
"@sap-cloud-sdk/resilience": "^4",
"@sap/cds": ">=5",
"express": "^4.17.1"
},
"devDependencies": {
"@cap-js/sqlite": ">=1"
},
"scripts": {
"start": "cds-serve",
"watch": "cds watch"
},
"cds": {
"requires": {
"ReviewsService": {
"kind": "odata",
"model": "@capire/reviews"
},
"OrdersService": {
"kind": "odata",
"model": "@capire/orders"
},
"messaging": true,
"db": true,
"db-ext": {
"[development]": {
"model": "db/sqlite"
},
"[production]": {
"model": "db/hana"
}
}
},
"log": { "service": true }
},
"sapux": [
"app/admin-authors",
"app/admin-books",
"app/browse"
]
}

View File

@@ -1,2 +0,0 @@
require('./srv/mashup')
require('./srv/trees')

View File

@@ -1,31 +0,0 @@
////////////////////////////////////////////////////////////////////////////
//
// Enhancing bookshop with Reviews and Orders provided through
// respective reuse packages and services
//
//
// Extend Books with access to Reviews and average ratings
//
using { sap.capire.bookshop.Books } from '@capire/bookshop';
using { ReviewsService.Reviews } from '@capire/reviews';
extend Books with {
reviews : Composition of many Reviews on reviews.subject = $self.ID;
rating : type of Reviews:rating; // average rating
numberOfReviews : Integer @title : '{i18n>NumberOfReviews}';
}
//
// Extend Orders with Books as Products
//
using { sap.capire.orders.Orders } from '@capire/orders';
extend Orders:Items with {
book : Association to Books on product.ID = book.ID
}
// Ensure models from all imported packages are loaded
using from '@capire/orders/app/fiori';
using from '@capire/data-viewer';
using from '@capire/common';

View File

@@ -1,65 +0,0 @@
const cds = require ('@sap/cds')
// Add routes to UIs from imported packages
if (!cds.env.production) cds.once ('bootstrap', (app) => {
app.serve ('/bookshop') .from ('@capire/bookshop','app/vue')
app.serve ('/reviews') .from ('@capire/reviews','app/vue')
app.serve ('/orders') .from('@capire/orders','app/orders')
})
// Mashing up bookshop services with required services...
cds.once ('served', async ()=>{
const CatalogService = await cds.connect.to ('CatalogService')
const ReviewsService = await cds.connect.to ('ReviewsService')
const OrdersService = await cds.connect.to ('OrdersService')
const db = await cds.connect.to ('db')
// reflect entity definitions used below...
const { Books } = db.entities ('sap.capire.bookshop')
//
// Delegate requests to read reviews to the ReviewsService
// Note: prepend is neccessary to intercept generic default handler
//
CatalogService.prepend (srv => srv.on ('READ', 'Books/reviews', (req) => {
console.debug ('> delegating request to ReviewsService') // eslint-disable-line no-console
const [id] = req.params, { columns, limit } = req.query.SELECT
return ReviewsService.read ('Reviews',columns).limit(limit).where({subject:String(id)})
}))
//
// Create an order with the OrdersService when CatalogService signals a new order
//
CatalogService.on ('OrderedBook', async (msg) => {
const { book, quantity, buyer } = msg.data
const { title, price } = await db.read (Books, book, b => { b.title, b.price })
return OrdersService.create ('OrdersNoDraft').entries({
OrderNo: 'Order at '+ (new Date).toLocaleString(),
Items: [{ product:{ID:`${book}`}, title, price, quantity }],
buyer, createdBy: buyer
})
})
//
// Update Books' average ratings when ReviewsService signals updated reviews
//
ReviewsService.on ('reviewed', (msg) => {
console.debug ('> received:', msg.event, msg.data) // eslint-disable-line no-console
const { subject, count, rating } = msg.data
return UPDATE(Books,subject).with({ numberOfReviews:count, rating })
})
//
// Reduce stock of ordered books for orders are created from Orders admin UI
//
OrdersService.on ('OrderChanged', (msg) => {
console.debug ('> received:', msg.event, msg.data) // eslint-disable-line no-console
const { product, deltaQuantity } = msg.data
return UPDATE (Books) .where ('ID =', product)
.and ('stock >=', deltaQuantity)
.set ('stock -=', deltaQuantity)
})
})

View File

@@ -1,50 +0,0 @@
const cds = require('@sap/cds/lib')
// PoC for simplified Fiori Tree Views
cds.on('compile.for.runtime', csn => {
for (let each of cds.linked(csn).definitions) {
if (each.is_entity && each._service && each['@hierarchy']) _hierarchy (each)
}
})
const _hierarchy = entity => {
// Add annotations explaining the hierarchy structure to Fiori
const Qualifier = entity.name.slice (entity._service.name.length+1) + 'Hierarchy'
const parent = _parent4(entity)
entity[`@Aggregation.RecursiveHierarchy#${Qualifier}.ParentNavigationProperty`] ??= {'=': parent.name }
entity[`@Aggregation.RecursiveHierarchy#${Qualifier}.NodeProperty`] ??= {'=': parent.keys[0].ref[0] }
// Add expected hierarchy elements to the entity
const columns = entity.projection.columns ??= ['*']
const elements = entity.elements
for (let e of Hierarchy.elements) {
entity[`@Hierarchy.RecursiveHierarchy#${Qualifier}.${e.name}`] = {'=': e.name }
if (e.name in elements) continue
const { name, value, ...rest } = e
elements[e.name] = Object.defineProperty ({ __proto__:e, ...rest }, 'parent', { value: entity })
columns.push ({ ...value, as: name, cast: { type: e.type } })
}
// Disable filter and sort for hierarchy elements
entity['@Capabilities.FilterRestrictions.NonFilterableProperties'] =
entity['@Capabilities.SortRestrictions.NonSortableProperties'] =
Object.keys (Hierarchy.elements)
}
const _parent4 = entity => {
const parent = entity['@hierarchy.parent'] || entity['@hierarchy.via']
if (parent) return entity.elements [parent['=']||parent]
else for (let e of entity.elements) // use first recursive uplink association
if (e.is2one && e._target === entity) return e
}
const { Hierarchy } = cds.linked `aspect Hierarchy {
LimitedDescendantCount : Int16 = null;
DistanceFromRoot : Int16 = null;
DrillState : String = null;
LimitedRank : Int16 = null;
}`.definitions

View File

@@ -1,82 +0,0 @@
@bookshop = http://localhost:4004
@reviews-service = {{bookshop}}/reviews
# Uncomment this when running a separate reviews service
# @reviews-service = http://localhost:4005/reviews
#################################################
#
# Reviews Service
#
GET {{reviews-service}}/Reviews
Authorization: Basic me:
###
POST {{reviews-service}}/Reviews
Authorization: Basic me:
Content-Type: application/json
{"subject":"201", "title":"boo", "rating":3 }
#################################################
#
# Bookshop Services
#
GET {{bookshop}}/browse/Books/201/reviews?
&$select=rating,date,title
&$top=3
###
GET {{bookshop}}/browse/Books(201)?
&$select=ID,title,rating
&$expand=reviews
###
GET {{bookshop}}/browse/Books?
&$select=title,author&$expand=currency
Accept-Language: de
#################################################
#
# Orders Service, incl. draft choreography
#
@newOrderID = e939604c-ab83-4d4f-bdb6-95fe30b3773e
GET {{bookshop}}/odata/v4/orders/Orders
### Create order, still inactive
POST {{bookshop}}/odata/v4/orders/Orders
Content-Type: application/json
{"ID": "{{newOrderID}}"}
### Get inactive order. We have to specify `IsActiveEntity`.
GET {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)
### Activate order using `.../<servicename>.draftActivate`
POST {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)/OrdersService.draftActivate
Content-Type: application/json
### Get active order
GET {{bookshop}}/odata/v4/orders/Orders(ID={{newOrderID}},IsActiveEntity=true)
### Create author
POST {{bookshop}}/admin/Authors
Content-Type: application/json
Authorization: Basic alice:
{
"ID": 200,
"name": "William Shakespeare",
"dateOfBirth": "1564-04-26",
"dateOfDeath": "1616-04-23"
}

View File

@@ -1 +0,0 @@
// dummy to auto-load the plugin

View File

@@ -1,13 +0,0 @@
using { sap } from '@sap/cds/common';
extend sap.common.Currencies with {
// Currencies.code = ISO 4217 alphabetic three-letter code
// with the first two letters being equal to ISO 3166 alphabetic country codes
// See also:
// [1] https://www.iso.org/iso-4217-currency-codes.html
// [2] https://www.currency-iso.org/en/home/tables/table-a1.html
// [3] https://www.ibm.com/support/knowledgecenter/en/SSZLC2_7.0.0/com.ibm.commerce.payments.developer.doc/refs/rpylerl2mst97.htm
numcode : Integer;
exponent : Integer; //> e.g. 2 --> 1 Dollar = 10^2 Cent
minor : String; //> e.g. 'Cent'
}

View File

@@ -1,12 +0,0 @@
code;name;descr
AU;Australia;Commonwealth of Australia
CA;Canada;Canada
CN;China;People's Republic of China (PRC)
FR;France;French Republic
DE;Germany;Federal Republic of Germany
IN;India;Republic of India
IL;Israel;State of Israel
MM;Myanmar;Republic of the Union of Myanmar
GB;United Kingdom;United Kingdom of Great Britain and Northern Ireland
US;United States;United States of America (USA)
EU;European Union;European Union
1 code name descr
2 AU Australia Commonwealth of Australia
3 CA Canada Canada
4 CN China People's Republic of China (PRC)
5 FR France French Republic
6 DE Germany Federal Republic of Germany
7 IN India Republic of India
8 IL Israel State of Israel
9 MM Myanmar Republic of the Union of Myanmar
10 GB United Kingdom United Kingdom of Great Britain and Northern Ireland
11 US United States United States of America (USA)
12 EU European Union European Union

View File

@@ -1,12 +0,0 @@
code;locale;name;descr
AU;de;Australien;Commonwealth Australien
CA;de;Kanada;Canada
CN;de;China;Volksrepublik China
FR;de;Frankreich;Republik Frankreich
DE;de;Deutschland;Bundesrepublik Deutschland
IN;de;Indien;Republik Indien
IL;de;Israel;Staat Israel
MM;de;Myanmar;Republik der Union Myanmar
GB;de;Vereinigtes Königreich;Vereinigtes Königreich Großbritannien und Nordirland
US;de;Vereinigte Staaten;Vereinigte Staaten von Amerika
EU;de;Europäische Union;Europäische Union
1 code locale name descr
2 AU de Australien Commonwealth Australien
3 CA de Kanada Canada
4 CN de China Volksrepublik China
5 FR de Frankreich Republik Frankreich
6 DE de Deutschland Bundesrepublik Deutschland
7 IN de Indien Republik Indien
8 IL de Israel Staat Israel
9 MM de Myanmar Republik der Union Myanmar
10 GB de Vereinigtes Königreich Vereinigtes Königreich Großbritannien und Nordirland
11 US de Vereinigte Staaten Vereinigte Staaten von Amerika
12 EU de Europäische Union Europäische Union

View File

@@ -1,12 +0,0 @@
code;symbol;name;descr;numcode;minor;exponent
EUR;€;Euro;European Euro;978;Cent;2
USD;$;US Dollar;United States Dollar;840;Cent;2
CAD;$;Canadian Dollar;Canadian Dollar;124;Cent;2
AUD;$;Australian Dollar;Australian Dollar;036;Cent;2
GBP;£;British Pound;Great Britain Pound;826;Penny;2
ILS;₪;Shekel;Israeli New Shekel;376;Agorat;2
INR;₹;Rupee;Indian Rupee;356;Paise;2
QAR;﷼;Riyal;Katar Riyal;356;Dirham;2
SAR;﷼;Riyal;Saudi Riyal;682;Halala;2
JPY;¥;Yen;Japanese Yen;392;Sen;2
CNY;¥;Yuan;Chinese Yuan Renminbi;156;Jiao;1
1 code symbol name descr numcode minor exponent
2 EUR Euro European Euro 978 Cent 2
3 USD $ US Dollar United States Dollar 840 Cent 2
4 CAD $ Canadian Dollar Canadian Dollar 124 Cent 2
5 AUD $ Australian Dollar Australian Dollar 036 Cent 2
6 GBP £ British Pound Great Britain Pound 826 Penny 2
7 ILS Shekel Israeli New Shekel 376 Agorat 2
8 INR Rupee Indian Rupee 356 Paise 2
9 QAR Riyal Katar Riyal 356 Dirham 2
10 SAR Riyal Saudi Riyal 682 Halala 2
11 JPY ¥ Yen Japanese Yen 392 Sen 2
12 CNY ¥ Yuan Chinese Yuan Renminbi 156 Jiao 1

View File

@@ -1,5 +0,0 @@
code;name
de;German
fr;French
en;English
en_GB;British English
1 code name
2 de German
3 fr French
4 en English
5 en_GB British English

View File

@@ -1,10 +0,0 @@
code;locale;name
de;en;German
de;de;Deutsch
de;fr;Allemande
fr;en;French
fr;de;Französisch
fr;fr;Francais
en;en;English
en;de;Englisch
en;fr;Anglais
1 code locale name
2 de en German
3 de de Deutsch
4 de fr Allemande
5 fr en French
6 fr de Französisch
7 fr fr Francais
8 en en English
9 en de Englisch
10 en fr Anglais

View File

@@ -1,2 +0,0 @@
using from './currencies';
using from './regions';

View File

@@ -1,15 +0,0 @@
{
"name": "@capire/common",
"description": "Provides a pre-built extension package for std @sap/cds/common",
"version": "1.0.0",
"dependencies": {
"@sap/cds": "*"
},
"cds": {
"requires": {
"@capire/common/data": {
"model": "@capire/common"
}
}
}
}

View File

@@ -1,22 +0,0 @@
using { sap.common } from '@sap/cds/common';
namespace sap.common.countries;
extend common.Countries {
regions : Composition of many Regions on regions._parent = $self.code;
}
entity Regions : common.CodeList {
key code : String(5); // ISO 3166-2 alpha5 codes, e.g. DE-BW
children : Composition of many Regions on children._parent = $self.code;
cities : Composition of many Cities on cities.region = $self;
_parent : String(11);
}
entity Cities : common.CodeList {
key code : String(11);
region : Association to Regions;
districts : Composition of many Districts on districts.city = $self;
}
entity Districts : common.CodeList {
key code : String(11);
city : Association to Cities;
}

Some files were not shown because too many files have changed in this diff Show More