Compare commits
35 Commits
openSAP-we
...
openSAP-we
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a1a7b1f2b | ||
|
|
a560e12106 | ||
|
|
3dccfc30f0 | ||
|
|
cc0be09341 | ||
|
|
175a183f27 | ||
|
|
a1d663a717 | ||
|
|
e75cc7a0a5 | ||
|
|
37ed881102 | ||
|
|
a3ab8cd51f | ||
|
|
6c1f06a06c | ||
|
|
e9a18c9938 | ||
|
|
eb5334cafc | ||
|
|
d54b16bd94 | ||
|
|
ba054305a6 | ||
|
|
e89fc1d9bb | ||
|
|
659fe52509 | ||
|
|
4ad21a47d6 | ||
|
|
7b5b2210ae | ||
|
|
c20c1609a7 | ||
|
|
ffc9fbd5f5 | ||
|
|
11957c93d8 | ||
|
|
2ca71b0f7d | ||
|
|
452b442246 | ||
|
|
bf21d0220c | ||
|
|
b65be0cb41 | ||
|
|
c3c778b2be | ||
|
|
c38c5d832c | ||
|
|
5929d22f98 | ||
|
|
4030173bbc | ||
|
|
74ce1a5fd1 | ||
|
|
cbb27132ec | ||
|
|
72a17ffcf7 | ||
|
|
0e2218a5f1 | ||
|
|
fa8a7861d5 | ||
|
|
ceb5487e75 |
@@ -6,7 +6,7 @@
|
|||||||
"jest": true
|
"jest": true
|
||||||
},
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 2018
|
"ecmaVersion": 2017
|
||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
"SELECT": true,
|
"SELECT": true,
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -13,3 +13,5 @@ target/
|
|||||||
connection.properties
|
connection.properties
|
||||||
default-env.json
|
default-env.json
|
||||||
packages/messageBox
|
packages/messageBox
|
||||||
|
*.db
|
||||||
|
|
||||||
|
|||||||
2
.npmrc
2
.npmrc
@@ -1 +1 @@
|
|||||||
registry=https://registry.npmjs.org
|
@sap:registry=https://npm.sap.com
|
||||||
|
|||||||
36
.vscode/launch.json
vendored
36
.vscode/launch.json
vendored
@@ -5,27 +5,7 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "bookshop",
|
"name": "cds run",
|
||||||
"request": "launch",
|
|
||||||
"type": "node",
|
|
||||||
"runtimeExecutable": "npx",
|
|
||||||
"runtimeArgs": [
|
|
||||||
"-n"
|
|
||||||
],
|
|
||||||
"args": [
|
|
||||||
"--",
|
|
||||||
"cds",
|
|
||||||
"run",
|
|
||||||
"--in-memory"
|
|
||||||
],
|
|
||||||
"cwd": "${workspaceFolder}/packages/bookshop",
|
|
||||||
"console": "integratedTerminal",
|
|
||||||
"skipFiles": [
|
|
||||||
"<node_internals>/**"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "cds run ...",
|
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"runtimeExecutable": "npx",
|
"runtimeExecutable": "npx",
|
||||||
@@ -37,10 +17,15 @@
|
|||||||
"cds",
|
"cds",
|
||||||
"run",
|
"run",
|
||||||
"--with-mocks",
|
"--with-mocks",
|
||||||
"--in-memory?"
|
"--in-memory"
|
||||||
],
|
], // the leading "--" arg ensures it works with as well as without debugging
|
||||||
"cwd": "${workspaceFolder}/packages/${input:service}",
|
"cwd": "${workspaceFolder}/packages/${input:service}",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
|
"serverReadyAction": {
|
||||||
|
"pattern": "server listening on (https?://\\S+|[0-9]+)",
|
||||||
|
"uriFormat": "http://localhost:%s",
|
||||||
|
"action": "openExternally"
|
||||||
|
},
|
||||||
"skipFiles": [
|
"skipFiles": [
|
||||||
"<node_internals>/**"
|
"<node_internals>/**"
|
||||||
]
|
]
|
||||||
@@ -56,7 +41,10 @@
|
|||||||
"bookstore",
|
"bookstore",
|
||||||
"media-server",
|
"media-server",
|
||||||
"office-supplies",
|
"office-supplies",
|
||||||
"reviews-service"
|
"orders-service",
|
||||||
|
"products-service",
|
||||||
|
"reviews-service",
|
||||||
|
"user-service"
|
||||||
],
|
],
|
||||||
"default": "bookshop"
|
"default": "bookshop"
|
||||||
}
|
}
|
||||||
|
|||||||
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"files.exclude": {
|
"files.exclude": {
|
||||||
"**/.gitignore": true,
|
"**/.gitignore": false,
|
||||||
"**/.vscode": true
|
"**/.git": false,
|
||||||
|
"**/.vscode": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
.vscode/tasks.json
vendored
19
.vscode/tasks.json
vendored
@@ -4,14 +4,23 @@
|
|||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"type": "npm", "script": "watch", "path": "packages/bookshop/",
|
"type": "shell", "label": "cds run bookshop",
|
||||||
"options": { "env": { "PORT": "4004" }},
|
"command": "npx", "args": [ "cds", "watch", "packages/bookshop" ],
|
||||||
"presentation": { "group": "A" }
|
"presentation": { "group": "A" },
|
||||||
|
"problemMatcher": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "npm", "script": "watch", "path": "packages/reviews-service/",
|
"type": "shell", "label": "cds run bookshop-enhanced",
|
||||||
|
"command": "npx", "args": [ "cds", "watch", "packages/bookshop-enhanced" ],
|
||||||
|
"presentation": { "group": "A" },
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell", "label": "cds run reviews-service",
|
||||||
|
"command": "npx", "args": [ "cds", "watch", "packages/reviews-service" ],
|
||||||
"options": {"env": { "PORT":"5005" }},
|
"options": {"env": { "PORT":"5005" }},
|
||||||
"presentation": { "group": "A" }
|
"presentation": { "group": "A" },
|
||||||
|
"problemMatcher": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
88
README.md
88
README.md
@@ -11,7 +11,7 @@ In SAP Business Application Studio, open a terminal.
|
|||||||
Then clone the repo with this specific branch:
|
Then clone the repo with this specific branch:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week3-unit5
|
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week2-unit4567
|
||||||
cd projects/cloud-cap-samples
|
cd projects/cloud-cap-samples
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -20,92 +20,26 @@ In the `cloud-cap-samples` folder run:
|
|||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Cloud Foundry Login
|
||||||
|
This is required later in the demo. In Studio's terminal, execute:
|
||||||
|
```sh
|
||||||
|
cf login
|
||||||
|
```
|
||||||
|
As input, provide
|
||||||
|
- The Cloud Foundry API endpoint, which is usally `https://api.cf.eu10.hana.ondemand.com`. It can be obtained from the Overview page of your Subaccount in Cloud Cockpit.
|
||||||
|
- Your user's email address and password
|
||||||
|
- The name of your trial organization and space
|
||||||
|
|
||||||
## Run
|
## Run
|
||||||
|
|
||||||
Now you're ready to run the samples, for example:
|
Now you're ready to run the samples, for example:
|
||||||
```sh
|
```sh
|
||||||
cd packages/bookshop
|
cd packages/bookshop
|
||||||
cds deploy
|
|
||||||
cds watch
|
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.
|
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
|
## Get Support
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "deploy",
|
|
||||||
"dependencies": {
|
|
||||||
"@sap/hdi-deploy": "^3.8.2"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "^8"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "node node_modules/@sap/hdi-deploy/deploy.js"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
6191
package-lock.json
generated
6191
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@@ -5,21 +5,22 @@
|
|||||||
"author": "daniel.hutzel@sap.com",
|
"author": "daniel.hutzel@sap.com",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lerna": "npx --no-install lerna -v > /dev/null || npm i lerna --no-save",
|
|
||||||
"install": "(npm -s run lerna) && lerna bootstrap --hoist",
|
|
||||||
"cleanup": "lerna clean -y && rm -fr node_modules",
|
"cleanup": "lerna clean -y && rm -fr node_modules",
|
||||||
|
"install": "(npm -s run lerna) && lerna bootstrap --hoist",
|
||||||
|
"lerna": "npx --no-install lerna -v > /dev/null || npm i lerna --no-save",
|
||||||
|
"test": "jest",
|
||||||
"bookshop": "cds watch packages/bookshop"
|
"bookshop": "cds watch packages/bookshop"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": "^4",
|
"@sap/cds": "^3",
|
||||||
"express": "^4"
|
"express": "^4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"sqlite3": "*"
|
|
||||||
},
|
|
||||||
"--add-these-to-devDependencies-for-tests": {
|
|
||||||
"@types/jest": "*",
|
"@types/jest": "*",
|
||||||
"jest": "*"
|
"sqlite3": "*",
|
||||||
|
"jest": "*",
|
||||||
|
"supertest": "^4.0.2",
|
||||||
|
"@sap/hdi-deploy": "3.7.0"
|
||||||
},
|
},
|
||||||
"license": "SAP SAMPLE CODE LICENSE"
|
"license": "SAP SAMPLE CODE LICENSE"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
{
|
|
||||||
"odata": {
|
|
||||||
"version": "v4"
|
|
||||||
},
|
|
||||||
"build": {
|
|
||||||
"target": "gen",
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"src": "db",
|
|
||||||
"for": "hana",
|
|
||||||
"options": {
|
|
||||||
"model": [
|
|
||||||
"db",
|
|
||||||
"srv"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "srv",
|
|
||||||
"for": "node-cf",
|
|
||||||
"options": {
|
|
||||||
"model": [
|
|
||||||
"db",
|
|
||||||
"srv",
|
|
||||||
"app"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "app",
|
|
||||||
"for": "fiori",
|
|
||||||
"options": {
|
|
||||||
"model": [
|
|
||||||
"app"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"passport": {
|
|
||||||
"strategy": "mock",
|
|
||||||
"users": {
|
|
||||||
"alice": {
|
|
||||||
"password": "123",
|
|
||||||
"ID": "alice",
|
|
||||||
"roles": [
|
|
||||||
"admin",
|
|
||||||
"authenticated-user"
|
|
||||||
],
|
|
||||||
"xs.user.attributes": {
|
|
||||||
"currency": [
|
|
||||||
"USD"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"bob": {
|
|
||||||
"password": "123",
|
|
||||||
"ID": "bob",
|
|
||||||
"roles": [
|
|
||||||
"authenticated-user"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
2
packages/bookshop/.vscode/launch.json
vendored
2
packages/bookshop/.vscode/launch.json
vendored
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "capire-bookshop-approuter",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"description": "",
|
|
||||||
"dependencies": {
|
|
||||||
"@sap/approuter": "^8"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "node node_modules/@sap/approuter/approuter.js"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"welcomeFile": "/fiori.html",
|
|
||||||
"authenticationMethod": "route",
|
|
||||||
"routes": [
|
|
||||||
{
|
|
||||||
"source": "^/.*(html|js)$",
|
|
||||||
"localDir": "."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "^/sapui5/.*",
|
|
||||||
"localDir": "."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "^/.*/webapp/.*",
|
|
||||||
"localDir": "."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"source": "/",
|
|
||||||
"destination": "srv-binding"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "deploy",
|
|
||||||
"dependencies": {
|
|
||||||
"@sap/hdi-deploy": "^3.8.2"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": "^12"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "node node_modules/@sap/hdi-deploy/deploy.js"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
{
|
|
||||||
"file_suffixes": {
|
|
||||||
"csv": {
|
|
||||||
"plugin_name": "com.sap.hana.di.tabledata.source"
|
|
||||||
},
|
|
||||||
"hdbafllangprocedure": {
|
|
||||||
"plugin_name": "com.sap.hana.di.afllangprocedure"
|
|
||||||
},
|
|
||||||
"hdbanalyticprivilege": {
|
|
||||||
"plugin_name": "com.sap.hana.di.analyticprivilege"
|
|
||||||
},
|
|
||||||
"hdbcalculationview": {
|
|
||||||
"plugin_name": "com.sap.hana.di.calculationview"
|
|
||||||
},
|
|
||||||
"hdbcollection": {
|
|
||||||
"plugin_name": "com.sap.hana.di.collection"
|
|
||||||
},
|
|
||||||
"hdbconstraint": {
|
|
||||||
"plugin_name": "com.sap.hana.di.constraint"
|
|
||||||
},
|
|
||||||
"hdbdropcreatetable": {
|
|
||||||
"plugin_name": "com.sap.hana.di.dropcreatetable"
|
|
||||||
},
|
|
||||||
"hdbflowgraph": {
|
|
||||||
"plugin_name": "com.sap.hana.di.flowgraph"
|
|
||||||
},
|
|
||||||
"hdbfunction": {
|
|
||||||
"plugin_name": "com.sap.hana.di.function"
|
|
||||||
},
|
|
||||||
"hdbgraphworkspace": {
|
|
||||||
"plugin_name": "com.sap.hana.di.graphworkspace"
|
|
||||||
},
|
|
||||||
"hdbhadoopmrjob": {
|
|
||||||
"plugin_name": "com.sap.hana.di.virtualfunctionpackage.hadoop"
|
|
||||||
},
|
|
||||||
"hdbindex": {
|
|
||||||
"plugin_name": "com.sap.hana.di.index"
|
|
||||||
},
|
|
||||||
"hdblibrary": {
|
|
||||||
"plugin_name": "com.sap.hana.di.library"
|
|
||||||
},
|
|
||||||
"hdbmigrationtable": {
|
|
||||||
"plugin_name": "com.sap.hana.di.table.migration"
|
|
||||||
},
|
|
||||||
"hdbprocedure": {
|
|
||||||
"plugin_name": "com.sap.hana.di.procedure"
|
|
||||||
},
|
|
||||||
"hdbprojectionview": {
|
|
||||||
"plugin_name": "com.sap.hana.di.projectionview"
|
|
||||||
},
|
|
||||||
"hdbprojectionviewconfig": {
|
|
||||||
"plugin_name": "com.sap.hana.di.projectionview.config"
|
|
||||||
},
|
|
||||||
"hdbreptask": {
|
|
||||||
"plugin_name": "com.sap.hana.di.reptask"
|
|
||||||
},
|
|
||||||
"hdbresultcache": {
|
|
||||||
"plugin_name": "com.sap.hana.di.resultcache"
|
|
||||||
},
|
|
||||||
"hdbrole": {
|
|
||||||
"plugin_name": "com.sap.hana.di.role"
|
|
||||||
},
|
|
||||||
"hdbroleconfig": {
|
|
||||||
"plugin_name": "com.sap.hana.di.role.config"
|
|
||||||
},
|
|
||||||
"hdbsearchruleset": {
|
|
||||||
"plugin_name": "com.sap.hana.di.searchruleset"
|
|
||||||
},
|
|
||||||
"hdbsequence": {
|
|
||||||
"plugin_name": "com.sap.hana.di.sequence"
|
|
||||||
},
|
|
||||||
"hdbstatistics": {
|
|
||||||
"plugin_name": "com.sap.hana.di.statistics"
|
|
||||||
},
|
|
||||||
"hdbstructuredprivilege": {
|
|
||||||
"plugin_name": "com.sap.hana.di.structuredprivilege"
|
|
||||||
},
|
|
||||||
"hdbsynonym": {
|
|
||||||
"plugin_name": "com.sap.hana.di.synonym"
|
|
||||||
},
|
|
||||||
"hdbsynonymconfig": {
|
|
||||||
"plugin_name": "com.sap.hana.di.synonym.config"
|
|
||||||
},
|
|
||||||
"hdbsystemversioning": {
|
|
||||||
"plugin_name": "com.sap.hana.di.systemversioning"
|
|
||||||
},
|
|
||||||
"hdbtable": {
|
|
||||||
"plugin_name": "com.sap.hana.di.table"
|
|
||||||
},
|
|
||||||
"hdbtabledata": {
|
|
||||||
"plugin_name": "com.sap.hana.di.tabledata"
|
|
||||||
},
|
|
||||||
"hdbtabletype": {
|
|
||||||
"plugin_name": "com.sap.hana.di.tabletype"
|
|
||||||
},
|
|
||||||
"hdbtrigger": {
|
|
||||||
"plugin_name": "com.sap.hana.di.trigger"
|
|
||||||
},
|
|
||||||
"hdbview": {
|
|
||||||
"plugin_name": "com.sap.hana.di.view"
|
|
||||||
},
|
|
||||||
"hdbvirtualfunction": {
|
|
||||||
"plugin_name": "com.sap.hana.di.virtualfunction"
|
|
||||||
},
|
|
||||||
"hdbvirtualfunctionconfig": {
|
|
||||||
"plugin_name": "com.sap.hana.di.virtualfunction.config"
|
|
||||||
},
|
|
||||||
"hdbvirtualpackagehadoop": {
|
|
||||||
"plugin_name": "com.sap.hana.di.virtualpackage.hadoop"
|
|
||||||
},
|
|
||||||
"hdbvirtualpackagesparksql": {
|
|
||||||
"plugin_name": "com.sap.hana.di.virtualpackage.sparksql"
|
|
||||||
},
|
|
||||||
"hdbvirtualprocedure": {
|
|
||||||
"plugin_name": "com.sap.hana.di.virtualprocedure"
|
|
||||||
},
|
|
||||||
"hdbvirtualprocedureconfig": {
|
|
||||||
"plugin_name": "com.sap.hana.di.virtualprocedure.config"
|
|
||||||
},
|
|
||||||
"hdbvirtualtable": {
|
|
||||||
"plugin_name": "com.sap.hana.di.virtualtable"
|
|
||||||
},
|
|
||||||
"hdbvirtualtableconfig": {
|
|
||||||
"plugin_name": "com.sap.hana.di.virtualtable.config"
|
|
||||||
},
|
|
||||||
"properties": {
|
|
||||||
"plugin_name": "com.sap.hana.di.tabledata.properties"
|
|
||||||
},
|
|
||||||
"tags": {
|
|
||||||
"plugin_name": "com.sap.hana.di.tabledata.properties"
|
|
||||||
},
|
|
||||||
"txt": {
|
|
||||||
"plugin_name": "com.sap.hana.di.copyonly"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
####### Generated mta.yaml based on template version 0.2.0
|
|
||||||
####### appName = capire-bookshop
|
|
||||||
####### language=nodejs; multiTenant=
|
|
||||||
####### approuter=
|
|
||||||
_schema-version: '3.1'
|
|
||||||
ID: sap.capire-bookshop
|
|
||||||
version: 1.0.0
|
|
||||||
description: "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages."
|
|
||||||
|
|
||||||
build-parameters:
|
|
||||||
before-all:
|
|
||||||
- builder: custom
|
|
||||||
commands:
|
|
||||||
- npm install
|
|
||||||
- cds build/all
|
|
||||||
|
|
||||||
parameters:
|
|
||||||
enable-parallel-deployments: true
|
|
||||||
|
|
||||||
modules:
|
|
||||||
############## SERVER MODULE ##########################
|
|
||||||
- name: capire-bookshop-srv
|
|
||||||
type: nodejs
|
|
||||||
path: gen/srv
|
|
||||||
properties:
|
|
||||||
EXIT: 1 # required by deploy.js task to terminate
|
|
||||||
|
|
||||||
|
|
||||||
requires:
|
|
||||||
#### Resources extracted from CAP configuration ####
|
|
||||||
- name: capire-bookshop-db
|
|
||||||
- name: capire-bookshop-uaa
|
|
||||||
|
|
||||||
provides:
|
|
||||||
- name: srv-binding # required by consumers of CAP services (e.g. approuter)
|
|
||||||
properties:
|
|
||||||
srv-url: ${default-url}
|
|
||||||
|
|
||||||
############################################################
|
|
||||||
|
|
||||||
############## SIDECAR MODULE #########################
|
|
||||||
- name: db
|
|
||||||
|
|
||||||
type: hdb
|
|
||||||
path: gen/db
|
|
||||||
parameters:
|
|
||||||
app-name: capire-bookshop-db
|
|
||||||
requires:
|
|
||||||
#### Hana and xsuaa resources extracted from CAP configuration ####
|
|
||||||
- name: capire-bookshop-db
|
|
||||||
- name: capire-bookshop-uaa
|
|
||||||
############################################################
|
|
||||||
|
|
||||||
############## 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}
|
|
||||||
|
|
||||||
############## RESOURCES ##################################
|
|
||||||
resources:
|
|
||||||
##### Services extracted from CAP configuration ####
|
|
||||||
##### 'service-plan' can be configured via 'cds.requires.<name>.vcap.plan'
|
|
||||||
- name: capire-bookshop-db
|
|
||||||
type: com.sap.xs.hdi-container
|
|
||||||
|
|
||||||
parameters:
|
|
||||||
service: hanatrial
|
|
||||||
properties:
|
|
||||||
hdi-service-name: ${service-name} # required for Java case
|
|
||||||
- name: capire-bookshop-uaa
|
|
||||||
|
|
||||||
type: org.cloudfoundry.managed-service
|
|
||||||
parameters:
|
|
||||||
##### Path to xs-security.json to add roles and scopes ####
|
|
||||||
path: ./xs-security.json
|
|
||||||
service: xsuaa
|
|
||||||
service-plan: application
|
|
||||||
config:
|
|
||||||
xsappname: capire-bookshop-${space} # name + space dependency
|
|
||||||
tenant-mode: dedicated
|
|
||||||
############################################################
|
|
||||||
@@ -4,26 +4,15 @@
|
|||||||
"description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.",
|
"description": "A simple bookshop application, build in a self-contained all-in-one fashion, i.e. w/o reusing other packages.",
|
||||||
"license": "SAP SAMPLE CODE LICENSE",
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": "^4",
|
"@sap/cds": "^3",
|
||||||
"express": "^4",
|
"express": "^4",
|
||||||
"hdb": "^0.18.1",
|
"hdb": "^0.17.1"
|
||||||
"passport": "^0.4.1"
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"jest": "*"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "cds run --in-memory?",
|
"start": "npx cds run",
|
||||||
"watch": "cds watch"
|
"test": "jest"
|
||||||
},
|
|
||||||
"cds": {
|
|
||||||
"requires": {
|
|
||||||
"db": {
|
|
||||||
"kind": "sql",
|
|
||||||
"[production]": {
|
|
||||||
"kind": "hana"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"uaa": {
|
|
||||||
"kind": "xsuaa"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -8,13 +8,8 @@ service AdminService @(_requires:'authenticated-user') {
|
|||||||
|
|
||||||
// Enable Fiori Draft for Orders
|
// Enable Fiori Draft for Orders
|
||||||
annotate AdminService.Orders with @odata.draft.enabled;
|
annotate AdminService.Orders with @odata.draft.enabled;
|
||||||
// annotate AdminService.Books with @odata.draft.enabled;
|
|
||||||
|
|
||||||
// Temporary workaround -> https://github.wdf.sap.corp/cap/issues/issues/3121
|
// Temporary workaround -> cap/issues#3121
|
||||||
extend service AdminService with {
|
extend service AdminService with {
|
||||||
entity OrderItems as select from my.OrderItems;
|
entity OrderItems as select from my.OrderItems;
|
||||||
}
|
}
|
||||||
// Restrict access to orders to users with role "admin"
|
|
||||||
annotate AdminService.Orders with @(restrict: [
|
|
||||||
{ grant: 'READ', to: 'admin' }
|
|
||||||
]);
|
|
||||||
@@ -1,10 +1,22 @@
|
|||||||
|
const cds = require('@sap/cds')
|
||||||
|
|
||||||
/** Service implementation for AdminService */
|
/** Service implementation for AdminService */
|
||||||
module.exports = cds.service.impl(function() {
|
module.exports = cds.service.impl(srv => {
|
||||||
this.before ('CREATE', 'Orders', _checkOrderCreateAuth)
|
const { OrderItems } = srv.entities ('sap.capire.bookshop')
|
||||||
})
|
|
||||||
|
|
||||||
|
srv.after (['READ','EDIT'], 'Orders', _calculateTotals)
|
||||||
|
|
||||||
/** Check authorization */
|
// on-the-fly calculate the total Order price based on the OrderItems' netAmounts
|
||||||
function _checkOrderCreateAuth (req) {
|
async function _calculateTotals (orders, req) {
|
||||||
req.user.currency[0] === req.data.currency_code || req.reject(403)
|
const ordersByID = Array.isArray(orders)
|
||||||
|
? orders.reduce ((all,o) => { (all[o.ID] = o).total=0; return all },{})
|
||||||
|
: { [orders.ID]: orders }
|
||||||
|
return cds.transaction(req) .run (
|
||||||
|
SELECT.from(OrderItems) .columns ('parent_ID', 'netAmount')
|
||||||
|
.where ({ parent_ID: {in: Object.keys(ordersByID)} })
|
||||||
|
) .then (items =>
|
||||||
|
items.forEach (item => ordersByID [item.parent_ID] .total += item.netAmount)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using { sap.capire.bookshop as my } from '../db/schema';
|
using { sap.capire.bookshop as my } from '../db/schema';
|
||||||
|
|
||||||
@path:'/browse'
|
@path:'/browse'
|
||||||
|
// @impl: './cat-service.js'
|
||||||
service CatalogService {
|
service CatalogService {
|
||||||
|
|
||||||
@readonly entity Books as SELECT from my.Books {*,
|
@readonly entity Books as SELECT from my.Books {*,
|
||||||
@@ -8,10 +9,6 @@ service CatalogService {
|
|||||||
} excluding { createdBy, modifiedBy };
|
} excluding { createdBy, modifiedBy };
|
||||||
|
|
||||||
@requires_: 'authenticated-user'
|
@requires_: 'authenticated-user'
|
||||||
entity Orders as projection on my.Orders;
|
@insertonly entity Orders as projection on my.Orders;
|
||||||
|
|
||||||
}
|
}
|
||||||
// Example for an instance restriction
|
|
||||||
annotate CatalogService.Orders with @(restrict: [
|
|
||||||
{ grant: 'READ', where: 'currency_code = $user.currency' }
|
|
||||||
]);
|
|
||||||
@@ -2,32 +2,27 @@ const cds = require('@sap/cds')
|
|||||||
const { Books } = cds.entities
|
const { Books } = cds.entities
|
||||||
|
|
||||||
/** Service implementation for CatalogService */
|
/** Service implementation for CatalogService */
|
||||||
module.exports = cds.service.impl(function() {
|
module.exports = cds.service.impl(srv => {
|
||||||
this.after ('READ', 'Books', each => each.stock > 111 && _addDiscount2(each,11))
|
srv.after ('READ', 'Books', each => each.stock > 111 && _addDiscount2(each,11))
|
||||||
this.before ('CREATE', 'Orders', _reduceStock)
|
srv.before ('CREATE', 'Orders', _reduceStock)
|
||||||
|
// srv.before ('*', (req) => { console.debug ('>>>', req.method, req.target.name) })
|
||||||
})
|
})
|
||||||
|
|
||||||
/** Add some discount for overstocked books */
|
/** Add some discount for overstocked books */
|
||||||
function _addDiscount2 (each,discount) {
|
function _addDiscount2 (each,discount) {
|
||||||
each.title += ` -- ${discount}% discount!`
|
each.title += ` -- ${discount}% discount!`
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reduce stock of ordered books if available stock suffices */
|
/** Reduce stock of ordered books if available stock suffices */
|
||||||
async function _reduceStock (req) {
|
async function _reduceStock (req) {
|
||||||
const { Items: orderItems } = req.data
|
const { Items: orderItems } = req.data
|
||||||
if (!Array.isArray(orderItems)) return
|
|
||||||
|
|
||||||
const all = await cds.transaction(req).run(orderItems.map(item =>
|
return cds.transaction(req) .run (()=> orderItems.map (item =>
|
||||||
UPDATE (Books)
|
UPDATE (Books)
|
||||||
.set ('stock -=', item.amount)
|
.set ('stock -=', item.amount)
|
||||||
.where ('ID =', item.book_ID) .and ('stock >=', item.amount)
|
.where ('ID =', item.book_ID) .and ('stock >=', item.amount)
|
||||||
))
|
)).then (all => all.forEach ((affectedRows,i) => {
|
||||||
all.forEach((affectedRows, i) => {
|
|
||||||
if (affectedRows === 0) {
|
if (affectedRows === 0) {
|
||||||
req.error (409, `${orderItems[i].amount} exceeds stock for book #${orderItems[i].book_ID}`)
|
req.error (409, `${orderItems[i].amount} exceeds stock for book #${orderItems[i].book_ID}`)
|
||||||
}
|
}
|
||||||
})
|
}))
|
||||||
|
|
||||||
return all
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
79
packages/bookshop/tests/bookshop.test.js
Normal file
79
packages/bookshop/tests/bookshop.test.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
|
||||||
|
const cds = require('@sap/cds')
|
||||||
|
|
||||||
|
describe('Bookshop: OData Protocol Level Testing', () => {
|
||||||
|
jest.setTimeout(20*1000)
|
||||||
|
const app = require('express')()
|
||||||
|
const request = require('supertest')(app)
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await cds.deploy(__dirname + '/../srv/cat-service').to('sqlite::memory:')
|
||||||
|
await cds.serve('CatalogService').from(__dirname + '/../srv/cat-service').in(app)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Service $metadata document', async () => {
|
||||||
|
const response = await request
|
||||||
|
.get('/browse/$metadata')
|
||||||
|
.expect('Content-Type', /^application\/xml/)
|
||||||
|
.expect(200)
|
||||||
|
|
||||||
|
const expectedVersion = '<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">'
|
||||||
|
const expectedBooksEntitySet = '<EntitySet Name="Books" EntityType="CatalogService.Books">'
|
||||||
|
expect(response.text.includes(expectedVersion)).toBeTruthy()
|
||||||
|
expect(response.text.includes(expectedBooksEntitySet)).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it('Get with select, expand and localized', async () => {
|
||||||
|
const response = await request
|
||||||
|
.get('/browse/Books?$select=title,author&$expand=currency')
|
||||||
|
.set('Accept-Language', 'de')
|
||||||
|
.expect('Content-Type', /^application\/json/)
|
||||||
|
.expect(200)
|
||||||
|
|
||||||
|
expect(response.body.value).toMatchObject([
|
||||||
|
{
|
||||||
|
ID: 201, title: "Sturmhöhe", author: "Emily Brontë",
|
||||||
|
currency: { name: "Pfund", descr: "Britische Pfund", code: "GBP", symbol: "£" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 207, title: "Jane Eyre", author: "Charlotte Brontë",
|
||||||
|
currency: { name: "Pfund", descr: "Britische Pfund", code: "GBP", symbol: "£" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 251, title: "The Raven", author: "Edgar Allen Poe",
|
||||||
|
currency: { name: "US-Dollar", descr: "United States Dollar", code: "USD", symbol: "$" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 252, title: "Eleonora", author: "Edgar Allen Poe",
|
||||||
|
currency: { name: "US-Dollar", descr: "United States Dollar", code: "USD", symbol: "$" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 271, title: "Catweazle", author: "Richard Carpenter",
|
||||||
|
currency: { name: "Euro", descr: "European Euro", code: "EUR", symbol: "€" }
|
||||||
|
}
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Bookshop: CDS Service Level Testing', () => {
|
||||||
|
let srv, Books
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
srv = await cds.serve('CatalogService').from(__dirname + '/../srv/cat-service')
|
||||||
|
Books = srv.entities.Books
|
||||||
|
expect(Books).toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('GETs all books', async () => {
|
||||||
|
const books = await srv.read(Books, b => { b.title })
|
||||||
|
|
||||||
|
expect(books).toMatchObject([
|
||||||
|
{ title: 'Wuthering Heights' },
|
||||||
|
{ title: 'Jane Eyre' },
|
||||||
|
{ title: 'The Raven' },
|
||||||
|
{ title: 'Eleonora' },
|
||||||
|
{ title: 'Catweazle' }
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
{
|
|
||||||
"xsappname": "capire-bookshop",
|
|
||||||
"tenant-mode": "dedicated",
|
|
||||||
"scopes": [
|
|
||||||
{
|
|
||||||
"name": "$XSAPPNAME.admin",
|
|
||||||
"description": "admin"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"attributes": [
|
|
||||||
{
|
|
||||||
"name": "currency",
|
|
||||||
"description": "currency",
|
|
||||||
"valueType": "s",
|
|
||||||
"valueRequired": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"role-templates": [
|
|
||||||
{
|
|
||||||
"name": "admin",
|
|
||||||
"description": "generated",
|
|
||||||
"scope-references": [
|
|
||||||
"$XSAPPNAME.admin"
|
|
||||||
],
|
|
||||||
"attribute-references": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "userattributes",
|
|
||||||
"description": "generated",
|
|
||||||
"default-role-name": "Attributes of a User",
|
|
||||||
"scope-references": [],
|
|
||||||
"attribute-references": [
|
|
||||||
"currency"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user