Compare commits
10 Commits
openSAP-we
...
CAA265-nod
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
926a3eaa9a | ||
|
|
de871e11cb | ||
|
|
b5684841e6 | ||
|
|
00f118deed | ||
|
|
fb8f6acac7 | ||
|
|
1e28cb217f | ||
|
|
2fc2cea260 | ||
|
|
bfaaf36e14 | ||
|
|
33b24c8d96 | ||
|
|
387b25b1bf |
@@ -6,7 +6,7 @@
|
|||||||
"jest": true
|
"jest": true
|
||||||
},
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 2018
|
"ecmaVersion": 2017
|
||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
"SELECT": true,
|
"SELECT": true,
|
||||||
|
|||||||
3
.npmrc
3
.npmrc
@@ -1 +1,2 @@
|
|||||||
registry=https://registry.npmjs.org
|
@sap:registry=https://npm.sap.com
|
||||||
|
package-lock=false
|
||||||
|
|||||||
64
.vscode/launch.json
vendored
64
.vscode/launch.json
vendored
@@ -1,64 +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": "bookshop",
|
|
||||||
"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",
|
|
||||||
"type": "node",
|
|
||||||
"runtimeExecutable": "npx",
|
|
||||||
"runtimeArgs": [
|
|
||||||
"-n"
|
|
||||||
],
|
|
||||||
"args": [
|
|
||||||
"--",
|
|
||||||
"cds",
|
|
||||||
"run",
|
|
||||||
"--with-mocks",
|
|
||||||
"--in-memory?"
|
|
||||||
],
|
|
||||||
"cwd": "${workspaceFolder}/packages/${input:service}",
|
|
||||||
"console": "integratedTerminal",
|
|
||||||
"skipFiles": [
|
|
||||||
"<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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"files.exclude": {
|
|
||||||
"**/.gitignore": true,
|
|
||||||
"**/.vscode": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
17
.vscode/tasks.json
vendored
17
.vscode/tasks.json
vendored
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
// 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" }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
119
README.md
119
README.md
@@ -1,118 +1,3 @@
|
|||||||
# Welcome to SAP Cloud Application Programming model samples
|
# Final state of exercise 4 for CAA265 - Rapid Service Development with SAP Cloud Application Programming Model
|
||||||
|
|
||||||
Find here the samples for the openSAP course [Building Applications with the SAP Cloud Application Programming Model](https://open.sap.com/courses/cp7).
|
**DO NOT MERGE IN MASTER**
|
||||||
|
|
||||||
## 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.
|
|
||||||
|
|||||||
@@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +1,7 @@
|
|||||||
{"packages":["packages/*"],"version":"1.0.0"}
|
{
|
||||||
|
"packages": [
|
||||||
|
"packages/*",
|
||||||
|
"shared/*"
|
||||||
|
],
|
||||||
|
"version": "0.0.0"
|
||||||
|
}
|
||||||
2164
package-lock.json
generated
2164
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@@ -1,25 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "@sap/capire-samples",
|
"name": "@sap/capire-samples",
|
||||||
"description": "The umbrella project for all samples to easily setup for local development and tests.",
|
"description": "The umbrella project for all samples to easily setup for local development and tests.",
|
||||||
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
|
"repository": "https://github.wdf.sap.corp/capire/samples.git",
|
||||||
"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": "(npx --no-install lerna -v || npm i lerna --no-save) && lerna bootstrap --hoist --ignore tests-env --loglevel warn",
|
||||||
"install": "(npm -s run lerna) && lerna bootstrap --hoist",
|
"reset": "lerna clean -y && rm -fr node_modules",
|
||||||
"cleanup": "lerna clean -y && rm -fr node_modules",
|
"test": "jest",
|
||||||
"bookshop": "cds watch packages/bookshop"
|
"bookstore": "cds run packages/bookstore --in-memory",
|
||||||
|
"products-service": "cds run packages/products-service --in-memory",
|
||||||
|
"reviews-service": "cds run packages/reviews-service --in-memory"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"license": "ISC"
|
||||||
"@sap/cds": "^4",
|
|
||||||
"express": "^4"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"sqlite3": "*"
|
|
||||||
},
|
|
||||||
"--add-these-to-devDependencies-for-tests": {
|
|
||||||
"@types/jest": "*",
|
|
||||||
"jest": "*"
|
|
||||||
},
|
|
||||||
"license": "SAP SAMPLE CODE LICENSE"
|
|
||||||
}
|
}
|
||||||
|
|||||||
3
packages/.cdsrc.json
Normal file
3
packages/.cdsrc.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"cds_version": "^3.17.4"
|
||||||
|
}
|
||||||
@@ -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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
29
packages/bookshop/.vscode/launch.json
vendored
29
packages/bookshop/.vscode/launch.json
vendored
@@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Run bookshop",
|
|
||||||
"request": "launch",
|
|
||||||
"type": "node",
|
|
||||||
"cwd": "/home/user/projects/cloud-cap-samples/packages/bookshop",
|
|
||||||
"runtimeExecutable": "npx",
|
|
||||||
"runtimeArgs": [
|
|
||||||
"-n"
|
|
||||||
],
|
|
||||||
"args": [
|
|
||||||
"--",
|
|
||||||
"cds",
|
|
||||||
"run",
|
|
||||||
"--in-memory?"
|
|
||||||
],
|
|
||||||
"console": "internalConsole",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart",
|
|
||||||
"skipFiles": [
|
|
||||||
"<node_internals>/**"
|
|
||||||
],
|
|
||||||
"env": {
|
|
||||||
"run.config": "{\"handlerId\":\"cap_run_config_handler_id\",\"runnableId\":\"/home/user/projects/cloud-cap-samples/packages/bookshop\"}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
Books = Books
|
|
||||||
Book = Book
|
|
||||||
ID = ID
|
|
||||||
Title = Title
|
|
||||||
Author = Author
|
|
||||||
AuthorID = Author ID
|
|
||||||
Stock = Stock
|
|
||||||
Name = Name
|
|
||||||
AuthorName = Author's Name
|
|
||||||
Authors = Authors
|
|
||||||
Order = Order
|
|
||||||
Orders = Orders
|
|
||||||
Price = Price
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
Books = Bücher
|
|
||||||
Book = Buch
|
|
||||||
ID = ID
|
|
||||||
Title = Titel
|
|
||||||
Authors = Autoren
|
|
||||||
Author = Autor
|
|
||||||
AuthorID = ID des Autors
|
|
||||||
AuthorName = Name des Autors
|
|
||||||
Name = Name
|
|
||||||
Stock = Bestand
|
|
||||||
Order = Bestellung
|
|
||||||
Orders = Bestellungen
|
|
||||||
Price = Preis
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
using AdminService from '../../srv/admin-service';
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Books Object Page
|
|
||||||
//
|
|
||||||
annotate AdminService.Books with @(
|
|
||||||
UI: {
|
|
||||||
Facets: [
|
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>General}', Target: '@UI.FieldGroup#General'},
|
|
||||||
{$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: 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}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
sap.ui.define(["sap/fe/AppComponent"], ac => ac.extend("admin.Component", {
|
|
||||||
metadata:{ manifest:'json' }
|
|
||||||
}))
|
|
||||||
|
|
||||||
// sap.ui.define (["sap/ui/core/UIComponent"], ui5 => ui5.extend("bookshop.Component", {
|
|
||||||
// metadata: { manifest: "json" }
|
|
||||||
// }))
|
|
||||||
// sap.ui.define (["sap/ui/generic/app/AppComponent"], ui5 => ui5.extend("bookshop.Component", {
|
|
||||||
// metadata: { manifest: "json" }
|
|
||||||
// }))
|
|
||||||
|
|
||||||
// jQuery.sap.declare("bookshop.Component");
|
|
||||||
// sap.ui.getCore().loadLibrary("sap.ui.generic.app");
|
|
||||||
// jQuery.sap.require("sap.ui.generic.app.AppComponent");
|
|
||||||
|
|
||||||
// sap.ui.generic.app.AppComponent.extend("bookshop.Component", {
|
|
||||||
// metadata: {
|
|
||||||
// manifest: "json"
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
/* eslint no-undef:0 */
|
|
||||||
@@ -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=Bookshop Sample
|
|
||||||
|
|
||||||
# JCI app descriptor contains lower case DESCRIPTION
|
|
||||||
appSubTitle=CAP Sample Application
|
|
||||||
|
|
||||||
# JCI app descriptor contains lower case DESCRIPTION
|
|
||||||
appDescription=CDS Sample Service
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
using CatalogService from '../../srv/cat-service';
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Books Object Page
|
|
||||||
//
|
|
||||||
annotate CatalogService.Books with @(
|
|
||||||
UI: {
|
|
||||||
HeaderInfo: {
|
|
||||||
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 Object Page
|
|
||||||
//
|
|
||||||
annotate CatalogService.Books with @(
|
|
||||||
UI: {
|
|
||||||
SelectionFields: [ ID, price, currency_code ],
|
|
||||||
LineItem: [
|
|
||||||
{Value: title},
|
|
||||||
{Value: author, Label:'{i18n>Author}'},
|
|
||||||
{Value: price},
|
|
||||||
{Value: currency.symbol, Label:' '},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
);
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
sap.ui.define(["sap/fe/AppComponent"], ac => ac.extend("bookshop.Component", {
|
|
||||||
metadata:{ manifest:'json' }
|
|
||||||
}))
|
|
||||||
|
|
||||||
// sap.ui.define (["sap/ui/core/UIComponent"], ui5 => ui5.extend("bookshop.Component", {
|
|
||||||
// metadata: { manifest: "json" }
|
|
||||||
// }))
|
|
||||||
// sap.ui.define (["sap/ui/generic/app/AppComponent"], ui5 => ui5.extend("bookshop.Component", {
|
|
||||||
// metadata: { manifest: "json" }
|
|
||||||
// }))
|
|
||||||
|
|
||||||
// jQuery.sap.declare("bookshop.Component");
|
|
||||||
// sap.ui.getCore().loadLibrary("sap.ui.generic.app");
|
|
||||||
// jQuery.sap.require("sap.ui.generic.app.AppComponent");
|
|
||||||
|
|
||||||
// sap.ui.generic.app.AppComponent.extend("bookshop.Component", {
|
|
||||||
// metadata: {
|
|
||||||
// manifest: "json"
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
/* eslint no-undef:0 */
|
|
||||||
@@ -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=Bookshop Sample
|
|
||||||
|
|
||||||
# JCI app descriptor contains lower case DESCRIPTION
|
|
||||||
appSubTitle=CAP Sample Application
|
|
||||||
|
|
||||||
# JCI app descriptor contains lower case DESCRIPTION
|
|
||||||
appDescription=CDS Sample Service
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
{
|
|
||||||
"_version": "1.8.0",
|
|
||||||
"sap.app": {
|
|
||||||
"id": "bookshop",
|
|
||||||
"type": "application",
|
|
||||||
"title": "Browse Books",
|
|
||||||
"description": "Sample Application",
|
|
||||||
"i18n": "i18n/i18n.properties",
|
|
||||||
"dataSources": {
|
|
||||||
"CatalogService": {
|
|
||||||
"uri": "/browse/",
|
|
||||||
"type": "OData",
|
|
||||||
"settings": {
|
|
||||||
"odataVersion": "4.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"-sourceTemplate": {
|
|
||||||
"id": "ui5template.basicSAPUI5ApplicationProject",
|
|
||||||
"-id": "ui5template.smartTemplate",
|
|
||||||
"-version": "1.40.12"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sap.ui5": {
|
|
||||||
"dependencies": {
|
|
||||||
"libs": {
|
|
||||||
"sap.fe": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"models": {
|
|
||||||
"i18n": {
|
|
||||||
"type": "sap.ui.model.resource.ResourceModel",
|
|
||||||
"uri": "i18n/i18n.properties"
|
|
||||||
},
|
|
||||||
"": {
|
|
||||||
"dataSource": "CatalogService",
|
|
||||||
"settings": {
|
|
||||||
"synchronizationMode": "None",
|
|
||||||
"operationMode": "Server",
|
|
||||||
"autoExpandSelect": true,
|
|
||||||
"earlyRequests": true,
|
|
||||||
"groupProperties": {
|
|
||||||
"default": {
|
|
||||||
"submit": "Auto"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"routing": {
|
|
||||||
"routes": [
|
|
||||||
{
|
|
||||||
"pattern": ":?query:",
|
|
||||||
"name": "BooksList",
|
|
||||||
"target": "BooksList"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"pattern": "Books({key}):?query:",
|
|
||||||
"name": "BooksDetails",
|
|
||||||
"target": "BooksDetails"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"targets": {
|
|
||||||
"BooksList": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "BooksList",
|
|
||||||
"name": "sap.fe.templates.ListReport",
|
|
||||||
"options": {
|
|
||||||
"settings": {
|
|
||||||
"entitySet": "Books",
|
|
||||||
"navigation": {
|
|
||||||
"Books": {
|
|
||||||
"detail": {
|
|
||||||
"route": "BooksDetails"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"BooksDetails": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "BooksDetailsList",
|
|
||||||
"name": "sap.fe.templates.ObjectPage",
|
|
||||||
"options": {
|
|
||||||
"settings": {
|
|
||||||
"entitySet": "Books"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"contentDensities": {
|
|
||||||
"compact": true,
|
|
||||||
"cozy": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sap.ui": {
|
|
||||||
"technology": "UI5",
|
|
||||||
"fullWidth": false
|
|
||||||
},
|
|
||||||
"sap.fiori": {
|
|
||||||
"registrationIds": [],
|
|
||||||
"archeType": "transactional"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
Common Annotations shared by all apps
|
|
||||||
*/
|
|
||||||
|
|
||||||
using { sap.capire.bookshop as my } from '../db/schema';
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Books Lists
|
|
||||||
//
|
|
||||||
annotate my.Books with @(
|
|
||||||
UI: {
|
|
||||||
Identification: [{Value:title}],
|
|
||||||
SelectionFields: [ ID, author_ID, price, currency_code ],
|
|
||||||
LineItem: [
|
|
||||||
{Value: ID},
|
|
||||||
{Value: title},
|
|
||||||
{Value: author.name, Label:'{i18n>Author}'},
|
|
||||||
{Value: stock},
|
|
||||||
{Value: price},
|
|
||||||
{Value: currency.symbol, Label:' '},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
author @ValueList.entity:'Authors';
|
|
||||||
};
|
|
||||||
|
|
||||||
annotate my.Authors with @(
|
|
||||||
UI: {
|
|
||||||
Identification: [{Value:name}],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// 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}' @UI.HiddenFilter;
|
|
||||||
title @title:'{i18n>Title}';
|
|
||||||
author @title:'{i18n>AuthorID}';
|
|
||||||
price @title:'{i18n>Price}';
|
|
||||||
stock @title:'{i18n>Stock}';
|
|
||||||
descr @UI.MultiLineText;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Authors Elements
|
|
||||||
//
|
|
||||||
annotate my.Authors with {
|
|
||||||
ID @title:'{i18n>ID}' @UI.HiddenFilter;
|
|
||||||
name @title:'{i18n>AuthorName}';
|
|
||||||
}
|
|
||||||
@@ -1,55 +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: {
|
|
||||||
"browse-books": {
|
|
||||||
title: "Browse Books",
|
|
||||||
description: "... testing FE v42",
|
|
||||||
additionalInformation: "SAPUI5.Component=bookshop",
|
|
||||||
applicationType : "URL",
|
|
||||||
url: "/browse/webapp",
|
|
||||||
navigationMode: "embedded"
|
|
||||||
},
|
|
||||||
"manage-books": {
|
|
||||||
title: "Manage Books",
|
|
||||||
description: "... testing FE v42",
|
|
||||||
additionalInformation: "SAPUI5.Component=admin",
|
|
||||||
applicationType : "URL",
|
|
||||||
url: "/admin/webapp",
|
|
||||||
navigationMode: "embedded"
|
|
||||||
},
|
|
||||||
"manage-orders": {
|
|
||||||
title: "Manage Orders",
|
|
||||||
description: "... testing FE v42",
|
|
||||||
additionalInformation: "SAPUI5.Component=orders",
|
|
||||||
applicationType : "URL",
|
|
||||||
url: "/orders/webapp",
|
|
||||||
navigationMode: "embedded"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script src="https://sapui5.hana.ondemand.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
|
|
||||||
<script src="https://sapui5.hana.ondemand.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_fiori_3"
|
|
||||||
data-sap-ui-frameOptions="allow"
|
|
||||||
></script>
|
|
||||||
<script>
|
|
||||||
sap.ui.getCore().attachInit(()=> sap.ushell.Container.createRenderer().placeAt("content"))
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body class="sapUiBody" id="content"></body>
|
|
||||||
</html>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
/*
|
|
||||||
This model controls what gets served to Fiori frontends...
|
|
||||||
*/
|
|
||||||
|
|
||||||
using from './admin/fiori-service';
|
|
||||||
using from './browse/fiori-service';
|
|
||||||
using from './orders/fiori-service';
|
|
||||||
using from './common';
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
using AdminService from '../../srv/admin-service';
|
|
||||||
|
|
||||||
annotate AdminService.Books with {
|
|
||||||
price @Common.FieldControl: #ReadOnly;
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Common
|
|
||||||
//
|
|
||||||
annotate AdminService.OrderItems with {
|
|
||||||
book @(
|
|
||||||
Common: {
|
|
||||||
Text: book.title,
|
|
||||||
FieldControl: #Mandatory
|
|
||||||
},
|
|
||||||
ValueList.entity:'Books',
|
|
||||||
);
|
|
||||||
amount @(
|
|
||||||
Common.FieldControl: #Mandatory
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
annotate AdminService.Orders with @(
|
|
||||||
UI: {
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Lists of Orders
|
|
||||||
//
|
|
||||||
SelectionFields: [ createdAt, createdBy ],
|
|
||||||
LineItem: [
|
|
||||||
{Value: createdBy, Label:'Customer'},
|
|
||||||
{Value: createdAt, Label:'Date'}
|
|
||||||
],
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Order Details
|
|
||||||
//
|
|
||||||
HeaderInfo: {
|
|
||||||
TypeName: 'Order', TypeNamePlural: 'Orders',
|
|
||||||
Title: {
|
|
||||||
Label: 'Order number ', //A label is possible but it is not considered on the ObjectPage yet
|
|
||||||
Value: OrderNo
|
|
||||||
},
|
|
||||||
Description: {Value: createdBy}
|
|
||||||
},
|
|
||||||
Identification: [ //Is the main field group
|
|
||||||
{Value: createdBy, Label:'Customer'},
|
|
||||||
{Value: createdAt, Label:'Date'},
|
|
||||||
{Value: OrderNo },
|
|
||||||
],
|
|
||||||
HeaderFacets: [
|
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Created}', Target: '@UI.FieldGroup#Created'},
|
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Modified}', Target: '@UI.FieldGroup#Modified'},
|
|
||||||
],
|
|
||||||
Facets: [
|
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'},
|
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>OrderItems}', Target: 'Items/@UI.LineItem'},
|
|
||||||
],
|
|
||||||
FieldGroup#Details: {
|
|
||||||
Data: [
|
|
||||||
{Value: currency_code, Label:'Currency'}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
FieldGroup#Created: {
|
|
||||||
Data: [
|
|
||||||
{Value: createdBy},
|
|
||||||
{Value: createdAt},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
FieldGroup#Modified: {
|
|
||||||
Data: [
|
|
||||||
{Value: modifiedBy},
|
|
||||||
{Value: modifiedAt},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
createdAt @UI.HiddenFilter:false;
|
|
||||||
createdBy @UI.HiddenFilter:false;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//The enity types name is AdminService.my_bookshop_OrderItems
|
|
||||||
//The annotations below are not generated in edmx WHY?
|
|
||||||
annotate AdminService.OrderItems with @(
|
|
||||||
UI: {
|
|
||||||
HeaderInfo: {
|
|
||||||
TypeName: 'Order Item', TypeNamePlural: ' ',
|
|
||||||
Title: {
|
|
||||||
Value: book.title
|
|
||||||
},
|
|
||||||
Description: {Value: book.descr}
|
|
||||||
},
|
|
||||||
// There is no filterbar for items so the selctionfileds is not needed
|
|
||||||
SelectionFields: [ book_ID ],
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Lists of OrderItems
|
|
||||||
//
|
|
||||||
LineItem: [
|
|
||||||
{Value: book_ID, Label:'Book'},
|
|
||||||
//The following entry is only used to have the assoication followed in the read event
|
|
||||||
{Value: book.price, Label:'Book Price'},
|
|
||||||
{Value: amount, Label:'Quantity'},
|
|
||||||
],
|
|
||||||
Identification: [ //Is the main field group
|
|
||||||
//{Value: ID, Label:'ID'}, //A guid shouldn't be on the UI
|
|
||||||
{Value: book_ID, Label:'Book'},
|
|
||||||
{Value: amount, Label:'Amount'},
|
|
||||||
],
|
|
||||||
Facets: [
|
|
||||||
{$Type: 'UI.ReferenceFacet', Label: '{i18n>OrderItems}', Target: '@UI.Identification'},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
);
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
sap.ui.define(["sap/fe/AppComponent"], ac => ac.extend("orders.Component", {
|
|
||||||
metadata:{ manifest:'json' }
|
|
||||||
}))
|
|
||||||
|
|
||||||
// sap.ui.define (["sap/ui/core/UIComponent"], ui5 => ui5.extend("bookshop.Component", {
|
|
||||||
// metadata: { manifest: "json" }
|
|
||||||
// }))
|
|
||||||
// sap.ui.define (["sap/ui/generic/app/AppComponent"], ui5 => ui5.extend("bookshop.Component", {
|
|
||||||
// metadata: { manifest: "json" }
|
|
||||||
// }))
|
|
||||||
|
|
||||||
// jQuery.sap.declare("bookshop.Component");
|
|
||||||
// sap.ui.getCore().loadLibrary("sap.ui.generic.app");
|
|
||||||
// jQuery.sap.require("sap.ui.generic.app.AppComponent");
|
|
||||||
|
|
||||||
// sap.ui.generic.app.AppComponent.extend("bookshop.Component", {
|
|
||||||
// metadata: {
|
|
||||||
// manifest: "json"
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
/* eslint no-undef:0 */
|
|
||||||
@@ -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=Bookshop Sample
|
|
||||||
|
|
||||||
# JCI app descriptor contains lower case DESCRIPTION
|
|
||||||
appSubTitle=CAP Sample Application
|
|
||||||
|
|
||||||
# JCI app descriptor contains lower case DESCRIPTION
|
|
||||||
appDescription=CDS Sample Service
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
{
|
|
||||||
"_version": "1.8.0",
|
|
||||||
"sap.app": {
|
|
||||||
"id": "orders",
|
|
||||||
"type": "application",
|
|
||||||
"title": "Manage Orders",
|
|
||||||
"description": "Sample Application",
|
|
||||||
"i18n": "i18n/i18n.properties",
|
|
||||||
"dataSources": {
|
|
||||||
"AdminService": {
|
|
||||||
"uri": "/admin/",
|
|
||||||
"type": "OData",
|
|
||||||
"settings": {
|
|
||||||
"odataVersion": "4.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"-sourceTemplate": {
|
|
||||||
"id": "ui5template.basicSAPUI5ApplicationProject",
|
|
||||||
"-id": "ui5template.smartTemplate",
|
|
||||||
"-version": "1.40.12"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sap.ui5": {
|
|
||||||
"dependencies": {
|
|
||||||
"libs": {
|
|
||||||
"sap.fe": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"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": "OrdersList",
|
|
||||||
"target": "OrdersList"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"pattern": "Orders({key}):?query:",
|
|
||||||
"name": "OrdersDetails",
|
|
||||||
"target": "OrdersDetails"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"pattern": "Orders({boo})/Items({boo2}):?query:",
|
|
||||||
"name": "OrderItemsDetails",
|
|
||||||
"target": "OrderItemsDetails"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"pattern": "Books({key}):?query:",
|
|
||||||
"name": "BooksDetails",
|
|
||||||
"target": "BooksDetails"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"targets": {
|
|
||||||
"OrdersList": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "OrdersList",
|
|
||||||
"name": "sap.fe.templates.ListReport",
|
|
||||||
"options": {
|
|
||||||
"settings" : {
|
|
||||||
"entitySet" : "Orders",
|
|
||||||
"navigation" : {
|
|
||||||
"Orders" : {
|
|
||||||
"detail" : {
|
|
||||||
"route" : "OrdersDetails"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"OrdersDetails": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "OrdersDetails",
|
|
||||||
"name": "sap.fe.templates.ObjectPage",
|
|
||||||
"options": {
|
|
||||||
"settings" : {
|
|
||||||
"entitySet": "Orders",
|
|
||||||
"navigation" : {
|
|
||||||
"Items": {
|
|
||||||
"detail": {
|
|
||||||
"route": "OrderItemsDetails"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"book": {
|
|
||||||
"detail": {
|
|
||||||
"route": "BooksDetails"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dummy": {
|
|
||||||
"detail": {
|
|
||||||
"route": "BooksDetails"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"OrderItemsDetails": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "OrderItemsDetails",
|
|
||||||
"name": "sap.fe.templates.ObjectPage",
|
|
||||||
"options": {
|
|
||||||
"settings" : {
|
|
||||||
"entitySet": "OrderItems"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"BooksDetails": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "BooksDetails",
|
|
||||||
"name": "sap.fe.templates.ObjectPage",
|
|
||||||
"options": {
|
|
||||||
"settings" : {
|
|
||||||
"entitySet": "Books",
|
|
||||||
"navigation": {
|
|
||||||
"author": {
|
|
||||||
"detail": {
|
|
||||||
"route": "AuthorsDetails"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AuthorsDetails": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "AuthorsDetails",
|
|
||||||
"name": "sap.fe.templates.ObjectPage",
|
|
||||||
"options": {
|
|
||||||
"settings" : {
|
|
||||||
"entitySet": "Authors"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"contentDensities": {
|
|
||||||
"compact": true,
|
|
||||||
"cozy": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sap.ui": {
|
|
||||||
"technology": "UI5",
|
|
||||||
"fullWidth": false
|
|
||||||
},
|
|
||||||
"sap.fiori": {
|
|
||||||
"registrationIds": [],
|
|
||||||
"archeType": "transactional"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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,4 +0,0 @@
|
|||||||
ID;amount;parent_ID;book_ID;netAmount
|
|
||||||
58040e66-1dcd-4ffb-ab10-fdce32028b79;1;7e2f2640-6866-4dcf-8f4d-3027aa831cad;201;11.11
|
|
||||||
64e718c9-ff99-47f1-8ca3-950c850777d4;1;7e2f2640-6866-4dcf-8f4d-3027aa831cad;271;15
|
|
||||||
e9641166-e050-4261-bfee-d1e797e6cb7f;2;64e718c9-ff99-47f1-8ca3-950c850777d4;252;28
|
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
ID;modifiedAt;createdAt;createdBy;modifiedBy;OrderNo;currency_code
|
|
||||||
7e2f2640-6866-4dcf-8f4d-3027aa831cad;;2019-01-31;john.doe@test.com;;1;EUR
|
|
||||||
64e718c9-ff99-47f1-8ca3-950c850777d4;;2019-01-30;jane.doe@test.com;;2;EUR
|
|
||||||
|
@@ -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
|
|
||||||
############################################################
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@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.",
|
|
||||||
"license": "SAP SAMPLE CODE LICENSE",
|
|
||||||
"dependencies": {
|
|
||||||
"@sap/cds": "^4",
|
|
||||||
"express": "^4",
|
|
||||||
"hdb": "^0.18.1",
|
|
||||||
"passport": "^0.4.1"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "cds run --in-memory?",
|
|
||||||
"watch": "cds watch"
|
|
||||||
},
|
|
||||||
"cds": {
|
|
||||||
"requires": {
|
|
||||||
"db": {
|
|
||||||
"kind": "sql",
|
|
||||||
"[production]": {
|
|
||||||
"kind": "hana"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"uaa": {
|
|
||||||
"kind": "xsuaa"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
@@ -1,20 +0,0 @@
|
|||||||
using { sap.capire.bookshop as my } from '../db/schema';
|
|
||||||
|
|
||||||
service AdminService @(_requires:'authenticated-user') {
|
|
||||||
entity Books as projection on my.Books;
|
|
||||||
entity Authors as projection on my.Authors;
|
|
||||||
entity Orders as select from my.Orders;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable Fiori Draft for Orders
|
|
||||||
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
|
|
||||||
extend service AdminService with {
|
|
||||||
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 +0,0 @@
|
|||||||
/** Service implementation for AdminService */
|
|
||||||
module.exports = cds.service.impl(function() {
|
|
||||||
this.before ('CREATE', 'Orders', _checkOrderCreateAuth)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
/** Check authorization */
|
|
||||||
function _checkOrderCreateAuth (req) {
|
|
||||||
req.user.currency[0] === req.data.currency_code || req.reject(403)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using { sap.capire.bookshop as my } from '../db/schema';
|
|
||||||
|
|
||||||
@path:'/browse'
|
|
||||||
service CatalogService {
|
|
||||||
|
|
||||||
@readonly entity Books as SELECT from my.Books {*,
|
|
||||||
author.name as author
|
|
||||||
} excluding { createdBy, modifiedBy };
|
|
||||||
|
|
||||||
@requires_: 'authenticated-user'
|
|
||||||
entity Orders as projection on my.Orders;
|
|
||||||
|
|
||||||
}
|
|
||||||
// Example for an instance restriction
|
|
||||||
annotate CatalogService.Orders with @(restrict: [
|
|
||||||
{ grant: 'READ', where: 'currency_code = $user.currency' }
|
|
||||||
]);
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
const cds = require('@sap/cds')
|
|
||||||
const { Books } = cds.entities
|
|
||||||
|
|
||||||
/** Service implementation for CatalogService */
|
|
||||||
module.exports = cds.service.impl(function() {
|
|
||||||
this.after ('READ', 'Books', each => each.stock > 111 && _addDiscount2(each,11))
|
|
||||||
this.before ('CREATE', 'Orders', _reduceStock)
|
|
||||||
})
|
|
||||||
|
|
||||||
/** Add some discount for overstocked books */
|
|
||||||
function _addDiscount2 (each,discount) {
|
|
||||||
each.title += ` -- ${discount}% discount!`
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Reduce stock of ordered books if available stock suffices */
|
|
||||||
async function _reduceStock (req) {
|
|
||||||
const { Items: orderItems } = req.data
|
|
||||||
if (!Array.isArray(orderItems)) return
|
|
||||||
|
|
||||||
const all = await cds.transaction(req).run(orderItems.map(item =>
|
|
||||||
UPDATE(Books)
|
|
||||||
.set('stock -=', item.amount)
|
|
||||||
.where('ID =', item.book_ID).and('stock >=', item.amount)
|
|
||||||
))
|
|
||||||
all.forEach((affectedRows, i) => {
|
|
||||||
if (affectedRows === 0) {
|
|
||||||
req.error(409, `${orderItems[i].amount} exceeds stock for book #${orderItems[i].book_ID}`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return all
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
### Service Document
|
|
||||||
GET http://localhost:4004/browse
|
|
||||||
|
|
||||||
### Service $metadata document
|
|
||||||
GET http://localhost:4004/browse/$metadata
|
|
||||||
|
|
||||||
### Browsing Books
|
|
||||||
GET http://localhost:4004/browse/Books?
|
|
||||||
# &$select=title,author
|
|
||||||
# &$expand=currency
|
|
||||||
# &sap-language=de
|
|
||||||
|
|
||||||
### Browsing Authors
|
|
||||||
GET http://localhost:4004/admin/Authors?
|
|
||||||
# &$select=name,dateOfBirth,placeOfBirth
|
|
||||||
# &$expand=books($select=title;$expand=currency)
|
|
||||||
# &$filter=ID eq 101
|
|
||||||
# &sap-language=de
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
|
|
||||||
### List Books with their current stocks
|
|
||||||
GET http://localhost:4004/admin/Books?$select=ID,stock
|
|
||||||
|
|
||||||
### List all Orders
|
|
||||||
GET http://localhost:4004/admin/Orders?
|
|
||||||
&$expand=Items
|
|
||||||
|
|
||||||
### Submit Orders
|
|
||||||
POST http://localhost:4004/browse/Orders
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{ "OrderNo":"2019-09...", "Items":[
|
|
||||||
{ "book_ID":201, "amount":5 },
|
|
||||||
{ "book_ID":207, "amount":3 }
|
|
||||||
]}
|
|
||||||
|
|
||||||
# Sending this three times should result in a 409: 5 exceeds stock for book #201
|
|
||||||
@@ -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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
6
packages/bookstore/.cdsrc.json
Normal file
6
packages/bookstore/.cdsrc.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"build": {
|
||||||
|
"target": ".",
|
||||||
|
"tasks": []
|
||||||
|
}
|
||||||
|
}
|
||||||
15
packages/bookstore/.gitignore
vendored
Normal file
15
packages/bookstore/.gitignore
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
.che/
|
||||||
|
.gen/
|
||||||
|
gen/
|
||||||
|
mta_archives/
|
||||||
|
node_modules/
|
||||||
|
target/
|
||||||
|
|
||||||
|
.cds_gen.log
|
||||||
|
connection.properties
|
||||||
|
*.db
|
||||||
|
.DS_Store
|
||||||
|
*.orig
|
||||||
|
_out
|
||||||
|
default-*.json
|
||||||
|
package-lock.json
|
||||||
12
packages/bookstore/app/bookList/webapp/Component.js
Normal file
12
packages/bookstore/app/bookList/webapp/Component.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
/* global hasher */
|
||||||
|
sap.ui.define([
|
||||||
|
"sap/fe/AppComponent"
|
||||||
|
], function (AppComponent) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
return AppComponent.extend("ns.bookList.Component", {
|
||||||
|
metadata: {
|
||||||
|
"manifest": "json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
118
packages/bookstore/app/bookList/webapp/WEB-INF/web.xml
Normal file
118
packages/bookstore/app/bookList/webapp/WEB-INF/web.xml
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||||
|
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
version="2.5"
|
||||||
|
xmlns="http://java.sun.com/xml/ns/javaee">
|
||||||
|
|
||||||
|
<display-name>OData v4</display-name>
|
||||||
|
|
||||||
|
<!-- ============================================================== -->
|
||||||
|
<!-- UI5 resource servlet used to handle application resources -->
|
||||||
|
<!-- ============================================================== -->
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<display-name>ResourceServlet</display-name>
|
||||||
|
<servlet-name>ResourceServlet</servlet-name>
|
||||||
|
<servlet-class>com.sap.ui5.resource.ResourceServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>ResourceServlet</servlet-name>
|
||||||
|
<url-pattern>/resources/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>ResourceServlet</servlet-name>
|
||||||
|
<url-pattern>/test-resources/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<!-- enable CORS -->
|
||||||
|
<context-param>
|
||||||
|
<param-name>com.sap.ui5.resource.ACCEPTED_ORIGINS</param-name>
|
||||||
|
<param-value>*</param-value>
|
||||||
|
</context-param>
|
||||||
|
|
||||||
|
<!-- BEGIN: DEV MODE -->
|
||||||
|
<!-- DEV MODE switched off by default and can be switched on during development -->
|
||||||
|
<!-- but has to be switched off for productive use on a Java server! -->
|
||||||
|
<context-param>
|
||||||
|
<param-name>com.sap.ui5.resource.DEV_MODE</param-name>
|
||||||
|
<param-value>true</param-value>
|
||||||
|
</context-param>
|
||||||
|
<!-- END: DEV MODE -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ============================================================== -->
|
||||||
|
<!-- Cache Control Filter to prevent caching of any resource -->
|
||||||
|
<!-- ============================================================== -->
|
||||||
|
|
||||||
|
<filter>
|
||||||
|
<display-name>CacheControlFilter</display-name>
|
||||||
|
<filter-name>CacheControlFilter</filter-name>
|
||||||
|
<filter-class>com.sap.ui5.resource.CacheControlFilter</filter-class>
|
||||||
|
</filter>
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>CacheControlFilter</filter-name>
|
||||||
|
<url-pattern>*.html</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>CacheControlFilter</filter-name>
|
||||||
|
<url-pattern>*.js</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>CacheControlFilter</filter-name>
|
||||||
|
<url-pattern>*.css</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>CacheControlFilter</filter-name>
|
||||||
|
<url-pattern>*.json</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>CacheControlFilter</filter-name>
|
||||||
|
<url-pattern>*.xml</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>CacheControlFilter</filter-name>
|
||||||
|
<url-pattern>*.gif</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>CacheControlFilter</filter-name>
|
||||||
|
<url-pattern>*.png</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>CacheControlFilter</filter-name>
|
||||||
|
<url-pattern>*.jpg</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>CacheControlFilter</filter-name>
|
||||||
|
<url-pattern>*.properties</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>CacheControlFilter</filter-name>
|
||||||
|
<url-pattern>*.tmpl</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ============================================================== -->
|
||||||
|
<!-- UI5 proxy servlet -->
|
||||||
|
<!-- ============================================================== -->
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>SimpleProxyServlet</servlet-name>
|
||||||
|
<servlet-class>com.sap.ui5.proxy.SimpleProxyServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>SimpleProxyServlet</servlet-name>
|
||||||
|
<url-pattern>/proxy/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ============================================================== -->
|
||||||
|
<!-- Welcome file list -->
|
||||||
|
<!-- ============================================================== -->
|
||||||
|
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>test.html</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
|
||||||
|
|
||||||
|
</web-app>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# This is the resource bundle for bookList#Texts for manifest.json
|
||||||
|
|
||||||
|
#XTIT: Application name
|
||||||
|
appTitle=bookList
|
||||||
|
|
||||||
|
#YDES: Application description
|
||||||
|
appDescription=bookList
|
||||||
39
packages/bookstore/app/bookList/webapp/index.html
Normal file
39
packages/bookstore/app/bookList/webapp/index.html
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<!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>{{appTitle}}</title>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
window["sap-ushell-config"] = {
|
||||||
|
defaultRenderer: "fiori2",
|
||||||
|
applications: {
|
||||||
|
"fe-lrop-v4": {
|
||||||
|
title: "bookList",
|
||||||
|
description: "bookList",
|
||||||
|
additionalInformation: "SAPUI5.Component=ns.bookList",
|
||||||
|
applicationType : "URL",
|
||||||
|
url: "./",
|
||||||
|
navigationMode: "embedded"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script src="https://sapui5.hana.ondemand.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
|
||||||
|
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
|
||||||
|
data-sap-ui-libs="sap.m, sap.ushell"
|
||||||
|
data-sap-ui-compatVersion="edge"
|
||||||
|
data-sap-ui-theme="sap_belize"
|
||||||
|
data-sap-ui-frameOptions="allow"
|
||||||
|
></script>
|
||||||
|
<script>
|
||||||
|
sap.ui.getCore().attachInit(()=> sap.ushell.Container.createRenderer().placeAt("content"))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body class="sapUiBody" id="content"></body>
|
||||||
|
</html>
|
||||||
@@ -1,28 +1,54 @@
|
|||||||
{
|
{
|
||||||
"_version": "1.8.0",
|
"_version": "1.15.0",
|
||||||
"sap.app": {
|
"sap.app": {
|
||||||
"id": "admin",
|
"id": "ns.bookList",
|
||||||
"type": "application",
|
"type": "application",
|
||||||
"title": "Manage Books",
|
|
||||||
"description": "Sample Application",
|
|
||||||
"i18n": "i18n/i18n.properties",
|
"i18n": "i18n/i18n.properties",
|
||||||
|
"applicationVersion": {
|
||||||
|
"version": "1.0"
|
||||||
|
},
|
||||||
|
"title": "{{appTitle}}",
|
||||||
|
"description": "{{appDescription}}",
|
||||||
|
"ach": "CA-UI5-FE",
|
||||||
"dataSources": {
|
"dataSources": {
|
||||||
"AdminService": {
|
"mainService": {
|
||||||
"uri": "/admin/",
|
"uri": "catalog/",
|
||||||
"type": "OData",
|
"type": "OData",
|
||||||
"settings": {
|
"settings": {
|
||||||
"odataVersion": "4.0"
|
"odataVersion": "4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"-sourceTemplate": {
|
"offline": false,
|
||||||
"id": "ui5template.basicSAPUI5ApplicationProject",
|
"resources": "resources.json",
|
||||||
"-id": "ui5template.smartTemplate",
|
"sourceTemplate": {
|
||||||
"-version": "1.40.12"
|
"id": "ui5template.fiorielements.v4.lrop",
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sap.ui": {
|
||||||
|
"technology": "UI5",
|
||||||
|
"icons": {
|
||||||
|
"icon": "",
|
||||||
|
"favIcon": "",
|
||||||
|
"phone": "",
|
||||||
|
"phone@2": "",
|
||||||
|
"tablet": "",
|
||||||
|
"tablet@2": ""
|
||||||
|
},
|
||||||
|
"deviceTypes": {
|
||||||
|
"desktop": true,
|
||||||
|
"tablet": true,
|
||||||
|
"phone": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sap.ui5": {
|
"sap.ui5": {
|
||||||
|
"resources": {
|
||||||
|
"js": [],
|
||||||
|
"css": []
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"minUI5Version": "1.60.1",
|
||||||
"libs": {
|
"libs": {
|
||||||
"sap.fe": {}
|
"sap.fe": {}
|
||||||
}
|
}
|
||||||
@@ -33,36 +59,27 @@
|
|||||||
"uri": "i18n/i18n.properties"
|
"uri": "i18n/i18n.properties"
|
||||||
},
|
},
|
||||||
"": {
|
"": {
|
||||||
"dataSource": "AdminService",
|
"dataSource": "mainService",
|
||||||
"settings": {
|
"settings": {
|
||||||
"synchronizationMode": "None",
|
"synchronizationMode": "None",
|
||||||
"operationMode": "Server",
|
"operationMode": "Server",
|
||||||
"autoExpandSelect" : true,
|
"autoExpandSelect": true,
|
||||||
"earlyRequests": true,
|
"earlyRequests": true
|
||||||
"groupProperties": {
|
|
||||||
"default": {
|
|
||||||
"submit": "Auto"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"routing": {
|
"routing": {
|
||||||
"routes": [
|
"routes": [
|
||||||
{
|
{
|
||||||
"pattern": ":?query:",
|
"pattern": "",
|
||||||
"name": "BooksList",
|
"name": "BooksList",
|
||||||
"target": "BooksList"
|
"target": "BooksList"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pattern": "Books({key}):?query:",
|
"pattern": "Books({key})",
|
||||||
"name": "BooksDetails",
|
"name": "BooksObjectPage",
|
||||||
"target": "BooksDetails"
|
"target": "BooksObjectPage"
|
||||||
},
|
|
||||||
{
|
|
||||||
"pattern": "Books({key}/author({key2}):?query:",
|
|
||||||
"name": "AuthorsDetails",
|
|
||||||
"target": "AuthorsDetails"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"targets": {
|
"targets": {
|
||||||
@@ -73,40 +90,24 @@
|
|||||||
"options": {
|
"options": {
|
||||||
"settings" : {
|
"settings" : {
|
||||||
"entitySet" : "Books",
|
"entitySet" : "Books",
|
||||||
|
"variantManagement": "Page",
|
||||||
"navigation" : {
|
"navigation" : {
|
||||||
"Books" : {
|
"Books" : {
|
||||||
"detail" : {
|
"detail" : {
|
||||||
"route" : "BooksDetails"
|
"route" : "BooksObjectPage"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"BooksDetails": {
|
"BooksObjectPage": {
|
||||||
"type": "Component",
|
"type": "Component",
|
||||||
"id": "BooksDetailsList",
|
"id": "BooksObjectPage",
|
||||||
"name": "sap.fe.templates.ObjectPage",
|
"name": "sap.fe.templates.ObjectPage",
|
||||||
"options": {
|
"options": {
|
||||||
"settings" : {
|
"settings" : {
|
||||||
"entitySet" : "Books",
|
"entitySet" : "Books"
|
||||||
"navigation" : {
|
|
||||||
"Authors" : {
|
|
||||||
"detail" : {
|
|
||||||
"route" : "AuthorsDetails"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AuthorsDetails": {
|
|
||||||
"type": "Component",
|
|
||||||
"id": "AuthorsDetailsList",
|
|
||||||
"name": "sap.fe.templates.ObjectPage",
|
|
||||||
"options": {
|
|
||||||
"settings" : {
|
|
||||||
"entitySet" : "Authors"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,11 +118,16 @@
|
|||||||
"cozy": true
|
"cozy": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sap.ui": {
|
"sap.platform.abap": {
|
||||||
"technology": "UI5",
|
"_version": "1.1.0",
|
||||||
"fullWidth": false
|
"uri": ""
|
||||||
|
},
|
||||||
|
"sap.platform.hcp": {
|
||||||
|
"_version": "1.1.0",
|
||||||
|
"uri": ""
|
||||||
},
|
},
|
||||||
"sap.fiori": {
|
"sap.fiori": {
|
||||||
|
"_version": "1.1.0",
|
||||||
"registrationIds": [],
|
"registrationIds": [],
|
||||||
"archeType": "transactional"
|
"archeType": "transactional"
|
||||||
}
|
}
|
||||||
23
packages/bookstore/app/bookList/xs-app.json
Normal file
23
packages/bookstore/app/bookList/xs-app.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"welcomeFile": "/index.html",
|
||||||
|
"authenticationMethod": "none",
|
||||||
|
"logout": {
|
||||||
|
"logoutEndpoint": "/do/logout"
|
||||||
|
},
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"source": "^/catalog/(.*)$",
|
||||||
|
"target": "$1",
|
||||||
|
"destination": "srv-api",
|
||||||
|
"csrfProtection": false,
|
||||||
|
"authenticationType": "none"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"source": "^(.*)$",
|
||||||
|
"target": "$1",
|
||||||
|
"service": "html5-apps-repo-rt",
|
||||||
|
"authenticationType": "xsuaa"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
66
packages/bookstore/app/booksAnnotation.cds
Normal file
66
packages/bookstore/app/booksAnnotation.cds
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
using sap.capire.bookstore.CatalogService as CatalogService from '../srv/services';
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Books Lists
|
||||||
|
//
|
||||||
|
annotate CatalogService.Books with @(
|
||||||
|
UI: {
|
||||||
|
HeaderFacets: [
|
||||||
|
{$Type: 'UI.ReferenceFacet', Label: 'Description', Target: '@UI.FieldGroup#Descr'},
|
||||||
|
],
|
||||||
|
Facets: [
|
||||||
|
{$Type: 'UI.ReferenceFacet', Label: 'Details', Target: '@UI.FieldGroup#Price'},
|
||||||
|
],
|
||||||
|
FieldGroup#Descr: {
|
||||||
|
Data: [
|
||||||
|
{Value: descr},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
FieldGroup#Price: {
|
||||||
|
Data: [
|
||||||
|
{Value: price},
|
||||||
|
{Value: currency.symbol, Label: 'Currency'},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
Identification: [{Value:title}],
|
||||||
|
SelectionFields: [ ID, price, currency_code ],
|
||||||
|
LineItem: [
|
||||||
|
{Value: ID},
|
||||||
|
{Value: title},
|
||||||
|
{Value: author_ID, Label:'Author ID'},
|
||||||
|
{Value: stock},
|
||||||
|
{Value: price},
|
||||||
|
{Value: currency.symbol, Label:''},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Books Details
|
||||||
|
//
|
||||||
|
annotate CatalogService.Books with @(
|
||||||
|
UI: {
|
||||||
|
HeaderInfo: {
|
||||||
|
TypeName: 'Book',
|
||||||
|
TypeNamePlural: 'Books',
|
||||||
|
Title: {Value: title},
|
||||||
|
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Books Elements
|
||||||
|
//
|
||||||
|
annotate CatalogService.Books with {
|
||||||
|
ID @title:'ID' @UI.HiddenFilter;
|
||||||
|
title @title:'Title';
|
||||||
|
author @title:'Author ID';
|
||||||
|
price @title:'Price';
|
||||||
|
stock @title:'Stock';
|
||||||
|
descr @UI.MultiLineText;
|
||||||
|
}
|
||||||
0
packages/bookshop/db/data/sap.capire.bookshop-Authors.csv → packages/bookstore/db/csv/sap.capire.bookstore-Authors.csv
Normal file → Executable file
0
packages/bookshop/db/data/sap.capire.bookshop-Authors.csv → packages/bookstore/db/csv/sap.capire.bookstore-Authors.csv
Normal file → Executable file
4
packages/bookstore/db/csv/sap.capire.bookstore-OrderItems.csv
Executable file
4
packages/bookstore/db/csv/sap.capire.bookstore-OrderItems.csv
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
ID;amount;parent_ID;book_ID;netAmount
|
||||||
|
301;1;401;201;11.11
|
||||||
|
302;1;401;271;15
|
||||||
|
303;2;402;252;28
|
||||||
|
3
packages/bookstore/db/csv/sap.capire.bookstore-Orders.csv
Executable file
3
packages/bookstore/db/csv/sap.capire.bookstore-Orders.csv
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
ID;modifiedAt;createdAt;createdBy;modifiedBy;OrderNo;currency_code
|
||||||
|
401;;2019-01-31;john.doe@test.com;;1;EUR
|
||||||
|
402;;2019-01-30;christian.georgi@sap.com;;2;EUR
|
||||||
|
11
packages/bookstore/db/csv/sap.capire.products-Categories.csv
Executable file
11
packages/bookstore/db/csv/sap.capire.products-Categories.csv
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
ID;parent_ID;name
|
||||||
|
1;;Poetry
|
||||||
|
2;;Biography
|
||||||
|
3;;Fantasy
|
||||||
|
4;;Science Fiction
|
||||||
|
5;;Romance
|
||||||
|
6;;Mystery
|
||||||
|
7;;Thriller
|
||||||
|
8;;Dystopia
|
||||||
|
9;;Tragedy
|
||||||
|
10;;Novel
|
||||||
|
12
packages/bookshop/db/data/sap.capire.bookshop-Books.csv → packages/bookstore/db/csv/sap.capire.products-Products.csv
Normal file → Executable file
12
packages/bookshop/db/data/sap.capire.bookshop-Books.csv → packages/bookstore/db/csv/sap.capire.products-Products.csv
Normal file → Executable file
@@ -1,6 +1,6 @@
|
|||||||
ID;title;descr;author_ID;stock;price;currency_code
|
ID;title;descr;author_ID;stock;price;currency_code;category_ID
|
||||||
201;Wuthering Heights;"Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym ""Ellis Bell"". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850.";101;12;11.11;GBP
|
201;Wuthering Heights;"Wuthering Heights, Emily Brontë's only novel, was published in 1847 under the pseudonym ""Ellis Bell"". It was written between October 1845 and June 1846. Wuthering Heights and Anne Brontë's Agnes Grey were accepted by publisher Thomas Newby before the success of their sister Charlotte's novel Jane Eyre. After Emily's death, Charlotte edited the manuscript of Wuthering Heights and arranged for the edited version to be published as a posthumous second edition in 1850.";101;12;11.11;GBP;9
|
||||||
207;Jane Eyre;"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.";107;11;12.34;GBP
|
207;Jane Eyre;"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.";107;11;12.34;GBP;10
|
||||||
251;The Raven;"""The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.";150;333;13.13;USD
|
251;The Raven;"“The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.";150;333;13.13;USD;1
|
||||||
252;Eleonora;"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.";150;555;14;USD
|
252;Eleonora;"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.";150;555;14;USD;5
|
||||||
271;Catweazle;Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.;170;22;15;EUR
|
271;Catweazle;Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.;170;22;15;EUR;3
|
||||||
|
0
packages/bookshop/db/data/sap.capire.bookshop-Books_texts.csv → packages/bookstore/db/csv/sap.capire.products-Products_texts.csv
Normal file → Executable file
0
packages/bookshop/db/data/sap.capire.bookshop-Books_texts.csv → packages/bookstore/db/csv/sap.capire.products-Products_texts.csv
Normal file → Executable file
2
packages/bookshop/db/data/sap.common-Currencies.csv → packages/bookstore/db/csv/sap.common-Currencies.csv
Normal file → Executable file
2
packages/bookshop/db/data/sap.common-Currencies.csv → packages/bookstore/db/csv/sap.common-Currencies.csv
Normal file → Executable file
@@ -3,5 +3,5 @@ EUR;€;Euro;European Euro
|
|||||||
USD;$;US Dollar;United States Dollar
|
USD;$;US Dollar;United States Dollar
|
||||||
CAD;$;Canadian Dollar;Canadian Dollar
|
CAD;$;Canadian Dollar;Canadian Dollar
|
||||||
AUD;$;Australian Dollar;Australian Dollar
|
AUD;$;Australian Dollar;Australian Dollar
|
||||||
GBP;£;Pound;Great Britain Pound
|
GBP;£;Pound;Great Britian Pound
|
||||||
ILS;₪;Shekel;Israeli New Shekel
|
ILS;₪;Shekel;Israeli New Shekel
|
||||||
|
0
packages/bookshop/db/data/sap.common-Currencies_texts.csv → packages/bookstore/db/csv/sap.common-Currencies_texts.csv
Normal file → Executable file
0
packages/bookshop/db/data/sap.common-Currencies_texts.csv → packages/bookstore/db/csv/sap.common-Currencies_texts.csv
Normal file → Executable file
@@ -1,14 +1,11 @@
|
|||||||
namespace sap.capire.bookshop;
|
namespace sap.capire.bookstore;
|
||||||
using { Currency, managed, cuid } from '@sap/cds/common';
|
|
||||||
|
|
||||||
entity Books : managed {
|
// We reuse Products, which are Books in our domain
|
||||||
key ID : Integer;
|
using { sap.capire.products.Products as Books } from '@sap/capire-products';
|
||||||
title : localized String(111);
|
using { Currency, managed } from '@sap/cds/common';
|
||||||
descr : localized String(1111);
|
|
||||||
|
extend Books with {
|
||||||
author : Association to Authors;
|
author : Association to Authors;
|
||||||
stock : Integer;
|
|
||||||
price : Decimal(9,2);
|
|
||||||
currency : Currency;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entity Authors : managed {
|
entity Authors : managed {
|
||||||
@@ -21,15 +18,18 @@ entity Authors : managed {
|
|||||||
books : Association to many Books on books.author = $self;
|
books : Association to many Books on books.author = $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity Orders : cuid, managed {
|
entity Orders : managed {
|
||||||
|
key ID : Integer;
|
||||||
OrderNo : String @title:'Order Number'; //> readable key
|
OrderNo : String @title:'Order Number'; //> readable key
|
||||||
Items : Composition of many OrderItems on Items.parent = $self;
|
Items : Composition of many OrderItems on Items.parent = $self;
|
||||||
total : Decimal(9,2) @readonly;
|
total : Decimal(9,2) @readonly;
|
||||||
currency : Currency;
|
currency : Currency;
|
||||||
}
|
}
|
||||||
entity OrderItems : cuid {
|
|
||||||
|
entity OrderItems {
|
||||||
|
key ID : Integer;
|
||||||
parent : Association to Orders;
|
parent : Association to Orders;
|
||||||
book : Association to Books;
|
book : Association to Books;
|
||||||
amount : Integer;
|
amount : Integer;
|
||||||
netAmount : Decimal(9,2);
|
netAmount : Decimal(9,2);
|
||||||
}
|
}
|
||||||
32
packages/bookstore/package.json
Normal file
32
packages/bookstore/package.json
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"name": "bookstore",
|
||||||
|
"description": "Generated by cds init",
|
||||||
|
"repository": "<Add your repository here>",
|
||||||
|
"license": "ISC",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"engines": {
|
||||||
|
"node": "^8.9"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/capire-products": "^1.0.0",
|
||||||
|
"reviews-service": "file:packages/reviews-service-1.0.0.tgz",
|
||||||
|
"@sap/cds": "^3.17.4",
|
||||||
|
"express": "^4.17.1"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "cds build/all --clean",
|
||||||
|
"deploy": "cds deploy",
|
||||||
|
"start": "cds run"
|
||||||
|
},
|
||||||
|
"cds": {
|
||||||
|
"requires": {
|
||||||
|
"sap.capire.reviews.ReviewsService": {
|
||||||
|
"model": "reviews-service",
|
||||||
|
"kind": "odata",
|
||||||
|
"credentials": {
|
||||||
|
"file": "default"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
packages/bookstore/srv/services.cds
Normal file
24
packages/bookstore/srv/services.cds
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
namespace sap.capire.bookstore;
|
||||||
|
|
||||||
|
using { sap.capire.products.Products, sap.capire.bookstore as my } from '../db/schema';
|
||||||
|
|
||||||
|
service CatalogService {
|
||||||
|
@readonly entity Books as projection on Products {
|
||||||
|
*, category.name as category, author.name
|
||||||
|
} excluding { createdBy, modifiedBy };
|
||||||
|
|
||||||
|
@insertonly entity Orders as projection on my.Orders;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reuse services from @sap/capire-products...
|
||||||
|
using { sap.capire.products.AdminService } from '@sap/capire-products';
|
||||||
|
extend service AdminService with {
|
||||||
|
entity Authors as projection on my.Authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adding reviews via capire-reviews service
|
||||||
|
using { sap.capire.reviews.ReviewsService as external} from 'reviews-service';
|
||||||
|
|
||||||
|
extend service CatalogService {
|
||||||
|
@readonly entity Reviews @(cds.persistence.skip) as projection on external.Reviews;
|
||||||
|
}
|
||||||
35
packages/bookstore/srv/services.js
Normal file
35
packages/bookstore/srv/services.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
const cds = require('@sap/cds')
|
||||||
|
module.exports = async (srv) => {
|
||||||
|
|
||||||
|
const { Books } = srv.entities
|
||||||
|
// Check all amounts against stock before activating
|
||||||
|
srv.before(['CREATE', 'UPDATE'], 'Orders', (req) => {
|
||||||
|
const tx = cds.transaction(req), order = req.data
|
||||||
|
return Promise.all(order.Items.map(each => tx.run(
|
||||||
|
UPDATE(Books).where({ ID: each.book_ID })
|
||||||
|
.and(`stock >=`, each.amount)
|
||||||
|
.set(`stock -=`, each.amount)
|
||||||
|
).then(affectedRows => {
|
||||||
|
if (!affectedRows) {
|
||||||
|
req.error(409, `${each.amount} exceeds stock for book #${each.book_ID}`)
|
||||||
|
}
|
||||||
|
})))
|
||||||
|
})
|
||||||
|
|
||||||
|
const reviews_srv = await cds.connect.to('sap.capire.reviews.ReviewsService')
|
||||||
|
|
||||||
|
// react on event messages from reviews service
|
||||||
|
reviews_srv.on('reviewed', (msg) => {
|
||||||
|
console.debug('> received', msg)
|
||||||
|
})
|
||||||
|
|
||||||
|
// delegate requests to reviews service
|
||||||
|
srv.on('READ', 'Reviews', async (req) => {
|
||||||
|
const { Reviews } = reviews_srv.entities
|
||||||
|
|
||||||
|
const tx = reviews_srv.transaction(req)
|
||||||
|
const results = await tx.read(Reviews)
|
||||||
|
|
||||||
|
return results
|
||||||
|
})
|
||||||
|
}
|
||||||
12
packages/products-service/.gitignore
vendored
Normal file
12
packages/products-service/.gitignore
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
gen/
|
||||||
|
.gen/
|
||||||
|
node_modules/
|
||||||
|
target/
|
||||||
|
*.db
|
||||||
|
.DS_Store
|
||||||
|
_out
|
||||||
|
.che/
|
||||||
|
.cds_gen.log
|
||||||
|
package-lock.json
|
||||||
|
*.orig
|
||||||
|
mta_archives/
|
||||||
19
packages/products-service/db/schema.cds
Normal file
19
packages/products-service/db/schema.cds
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
namespace sap.capire.products;
|
||||||
|
|
||||||
|
using { Currency, cuid, managed, sap.common.CodeList } from '@sap/cds/common';
|
||||||
|
|
||||||
|
entity Products : cuid, managed {
|
||||||
|
key ID : String(36);
|
||||||
|
title : localized String(111);
|
||||||
|
descr : localized String(1111);
|
||||||
|
stock : Integer;
|
||||||
|
price : Decimal(9,2);
|
||||||
|
currency : Currency;
|
||||||
|
category : Association to Categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Categories : CodeList {
|
||||||
|
key ID : Integer;
|
||||||
|
parent : Association to Categories;
|
||||||
|
children : Composition of many Categories on children.parent = $self;
|
||||||
|
}
|
||||||
2
packages/products-service/index.cds
Normal file
2
packages/products-service/index.cds
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
using from './db/schema';
|
||||||
|
using from './srv/admin-service';
|
||||||
16
packages/products-service/package.json
Normal file
16
packages/products-service/package.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "@sap/capire-products",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A reuse package providing domain models and services to manage product catalogs.",
|
||||||
|
"repository": "https://github.wdf.sap.corp/caps/products-service.git",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/cds": "^3.17.4",
|
||||||
|
"express": "^4.17.1"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"db",
|
||||||
|
"srv",
|
||||||
|
"index.cds"
|
||||||
|
]
|
||||||
|
}
|
||||||
7
packages/products-service/srv/admin-service.cds
Normal file
7
packages/products-service/srv/admin-service.cds
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using { sap.capire.products as db } from '../db/schema';
|
||||||
|
namespace sap.capire.products;
|
||||||
|
|
||||||
|
service AdminService @(_requires:'admin') {
|
||||||
|
entity Products as projection on db.Products;
|
||||||
|
entity Categories as projection on db.Categories;
|
||||||
|
}
|
||||||
68
packages/products-service/tests/categories.test.js
Normal file
68
packages/products-service/tests/categories.test.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
const cds = require ('@sap/cds')
|
||||||
|
|
||||||
|
describe('reading/writing hierarchies', ()=>{
|
||||||
|
|
||||||
|
it ('should prepare to sqlite in-memory', async()=>{
|
||||||
|
await cds.deploy (__dirname+'/../db') .to ('sqlite::memory:')
|
||||||
|
expect (cds.model) .toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should insert hierarchy of categories', ()=>{
|
||||||
|
const { Categories } = cds.entities
|
||||||
|
return INSERT.into (Categories) .entries (
|
||||||
|
{ ID:100, name:'Some Sample Categories...', 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 read categories with children', async()=>{
|
||||||
|
const { Categories } = cds.entities
|
||||||
|
expect (await
|
||||||
|
|
||||||
|
SELECT.one.from (Categories, c=>{
|
||||||
|
c.ID, c.name.as('parent'), c.children (c=>{
|
||||||
|
c.name.as('child')
|
||||||
|
})
|
||||||
|
}) .where ({name:'Cat'})
|
||||||
|
|
||||||
|
) .toMatchObject (
|
||||||
|
|
||||||
|
{ ID:101, parent:'Cat', children:[
|
||||||
|
{ child:'Kitty' },
|
||||||
|
{ child:'Catwoman' },
|
||||||
|
]}
|
||||||
|
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should read hierarchy of categories', async()=>{
|
||||||
|
const { Categories } = cds.entities
|
||||||
|
expect (await
|
||||||
|
|
||||||
|
SELECT.one.from (Categories, c=>{
|
||||||
|
c.ID, c.name, c.children (c=>{ c.name },{levels:3})
|
||||||
|
}) .where ({name:'Cat'})
|
||||||
|
|
||||||
|
) .toMatchObject (
|
||||||
|
|
||||||
|
{ ID:101, name:'Cat', children:[
|
||||||
|
{ name:'Kitty', children:[
|
||||||
|
{ name:'Kitty Cat', children:[
|
||||||
|
{ name:'Aristocat' }, ]},
|
||||||
|
{ name:'Kitty Bat' }, ]},
|
||||||
|
{ name:'Catwoman', children:[
|
||||||
|
{ name:'Catalina' } ]},
|
||||||
|
]}
|
||||||
|
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
ID;parent_ID;name
|
||||||
|
0;;Some Sample Categories...
|
||||||
|
1;;Cat
|
||||||
|
2;1;Kitty
|
||||||
|
3;2;Kitty Cat
|
||||||
|
4;3;Aristocat
|
||||||
|
5;2;Kitty Bat
|
||||||
|
6;1;Catwoman
|
||||||
|
7;6;Catalina
|
||||||
|
8;;Catweazle
|
||||||
|
157
packages/products-service/tests/postman.json
Normal file
157
packages/products-service/tests/postman.json
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
{
|
||||||
|
"info": {
|
||||||
|
"_postman_id": "0f8d4e79-a1c2-47fe-aeab-0319fb4ce180",
|
||||||
|
"name": "@sap/capire-products",
|
||||||
|
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
||||||
|
},
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "Categories",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Content-Type",
|
||||||
|
"value": "application/json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{ \"ID\":0, \"name\":\"Some Sample Categories...\", \"children\":[\n { \"ID\":1, \"name\":\"Cat\", \"children\":[\n { \"ID\":2, \"name\":\"Kitty\", \"children\":[\n { \"ID\":3, \"name\":\"Kitty Cat\", \"children\":[\n { \"ID\":4, \"name\":\"Aristocat\" }\n ]},\n { \"ID\":5, \"name\":\"Kitty Bat\" }\n ]},\n { \"ID\":6, \"name\":\"Catwoman\", \"children\":[\n { \"ID\":7, \"name\":\"Catalina\" }\n ]}\n ] },\n { \"ID\":8, \"name\":\"Catweazle\" }\n]}\n"
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:4004/admin/cats",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "4004",
|
||||||
|
"path": [
|
||||||
|
"admin",
|
||||||
|
"cats"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Categories",
|
||||||
|
"request": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": ""
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:4004/admin/cats/0?$expand=children($expand=children($expand=children($expand=children)))",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "4004",
|
||||||
|
"path": [
|
||||||
|
"admin",
|
||||||
|
"cats",
|
||||||
|
"0"
|
||||||
|
],
|
||||||
|
"query": [
|
||||||
|
{
|
||||||
|
"key": "$expand",
|
||||||
|
"value": "children($expand=children($expand=children($expand=children)))"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": [
|
||||||
|
{
|
||||||
|
"name": "Categories",
|
||||||
|
"originalRequest": {
|
||||||
|
"method": "GET",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": ""
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:4004/admin/cats/0?$expand=children($expand=children($expand=children($expand=children)))",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "4004",
|
||||||
|
"path": [
|
||||||
|
"admin",
|
||||||
|
"cats",
|
||||||
|
"0"
|
||||||
|
],
|
||||||
|
"query": [
|
||||||
|
{
|
||||||
|
"key": "$expand",
|
||||||
|
"value": "children($expand=children($expand=children($expand=children)))"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": "OK",
|
||||||
|
"code": 200,
|
||||||
|
"_postman_previewlanguage": "json",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "X-Powered-By",
|
||||||
|
"value": "Express"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "OData-Version",
|
||||||
|
"value": "4.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "content-type",
|
||||||
|
"value": "application/json;odata.metadata=minimal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Date",
|
||||||
|
"value": "Tue, 21 May 2019 19:20:24 GMT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Connection",
|
||||||
|
"value": "keep-alive"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Content-Length",
|
||||||
|
"value": "767"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cookie": [],
|
||||||
|
"body": "{\n \"@odata.context\": \"$metadata#cats(children(children(children(children()))))/$entity\",\n \"@odata.metadataEtag\": \"W/\\\"+AAp4JKNOcr+OusjrdQo55RCfM+UHKpTh8EbhsxyPhM=\\\"\",\n \"name\": \"Some Sample Categories...\",\n \"descr\": null,\n \"ID\": 0,\n \"parent_ID\": null,\n \"children\": [\n {\n \"name\": \"Cat\",\n \"descr\": null,\n \"ID\": 1,\n \"parent_ID\": 0,\n \"children\": [\n {\n \"name\": \"Kitty\",\n \"descr\": null,\n \"ID\": 2,\n \"parent_ID\": 1,\n \"children\": [\n {\n \"name\": \"Kitty Cat\",\n \"descr\": null,\n \"ID\": 3,\n \"parent_ID\": 2,\n \"children\": [\n {\n \"name\": \"Aristocat\",\n \"descr\": null,\n \"ID\": 4,\n \"parent_ID\": 3\n }\n ]\n },\n {\n \"name\": \"Kitty Bat\",\n \"descr\": null,\n \"ID\": 5,\n \"parent_ID\": 2,\n \"children\": []\n }\n ]\n },\n {\n \"name\": \"Catwoman\",\n \"descr\": null,\n \"ID\": 6,\n \"parent_ID\": 1,\n \"children\": [\n {\n \"name\": \"Catalina\",\n \"descr\": null,\n \"ID\": 7,\n \"parent_ID\": 6,\n \"children\": []\n }\n ]\n }\n ]\n },\n {\n \"name\": \"Catweazle\",\n \"descr\": null,\n \"ID\": 8,\n \"parent_ID\": 0,\n \"children\": []\n }\n ]\n}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Categories",
|
||||||
|
"request": {
|
||||||
|
"method": "DELETE",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": ""
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://localhost:4004/admin/cats/0",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"localhost"
|
||||||
|
],
|
||||||
|
"port": "4004",
|
||||||
|
"path": [
|
||||||
|
"admin",
|
||||||
|
"cats",
|
||||||
|
"0"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
BIN
packages/reviews-service-1.0.0.tgz
Normal file
BIN
packages/reviews-service-1.0.0.tgz
Normal file
Binary file not shown.
6
packages/reviews-service/.cdsrc.json
Normal file
6
packages/reviews-service/.cdsrc.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"build": {
|
||||||
|
"target": ".",
|
||||||
|
"tasks": []
|
||||||
|
}
|
||||||
|
}
|
||||||
15
packages/reviews-service/.gitignore
vendored
Normal file
15
packages/reviews-service/.gitignore
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
.che/
|
||||||
|
.gen/
|
||||||
|
gen/
|
||||||
|
mta_archives/
|
||||||
|
node_modules/
|
||||||
|
target/
|
||||||
|
|
||||||
|
.cds_gen.log
|
||||||
|
connection.properties
|
||||||
|
*.db
|
||||||
|
.DS_Store
|
||||||
|
*.orig
|
||||||
|
_out
|
||||||
|
default-*.json
|
||||||
|
package-lock.json
|
||||||
16
packages/reviews-service/.vscode/launch.json
vendored
Normal file
16
packages/reviews-service/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
// 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": "cds run",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node", "runtimeExecutable": "npx","runtimeArgs": [ "-n" ],
|
||||||
|
"args": [ "--","cds","run","--in-memory?" ], // the leading "--" arg ensures it works with as well as without debugging
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"skipFiles": [ "<node_internals>/**" ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
30
packages/reviews-service/db/schema.cds
Normal file
30
packages/reviews-service/db/schema.cds
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
namespace sap.capire.reviews;
|
||||||
|
using { User } from '@sap/cds/common';
|
||||||
|
|
||||||
|
// Reviewed subjects can be any entity that is uniquely identified
|
||||||
|
type ReviewedSubject : String(111);
|
||||||
|
|
||||||
|
entity Reviews {
|
||||||
|
key ID : String(36);
|
||||||
|
subject : ReviewedSubject;
|
||||||
|
reviewer : User;
|
||||||
|
rating : Rating;
|
||||||
|
title : String(111);
|
||||||
|
text : String(1111);
|
||||||
|
date : DateTime;
|
||||||
|
likes : Composition of many Likes on likes.review = $self;
|
||||||
|
liked : Integer default 0; // counter for likes as helpful review (count of all _likes belonging to this review)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Rating : Integer enum {
|
||||||
|
Best = 5;
|
||||||
|
Good = 4;
|
||||||
|
Avg = 3;
|
||||||
|
Poor = 2;
|
||||||
|
Worst = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Likes {
|
||||||
|
key review : Association to Reviews;
|
||||||
|
key user : User;
|
||||||
|
}
|
||||||
1
packages/reviews-service/index.cds
Normal file
1
packages/reviews-service/index.cds
Normal file
@@ -0,0 +1 @@
|
|||||||
|
using from './srv/reviews-service';
|
||||||
19
packages/reviews-service/package.json
Normal file
19
packages/reviews-service/package.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "reviews-service",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Generated by cds init",
|
||||||
|
"repository": "<Add your repository here>",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/cds": "^3.17.4",
|
||||||
|
"express": "^4.17.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^8.9"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "cds build/all --clean",
|
||||||
|
"deploy": "cds deploy",
|
||||||
|
"start": "cds run"
|
||||||
|
}
|
||||||
|
}
|
||||||
26
packages/reviews-service/srv/reviews-service.cds
Normal file
26
packages/reviews-service/srv/reviews-service.cds
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
namespace sap.capire.reviews;
|
||||||
|
using { sap.capire.reviews as my } from '../db/schema';
|
||||||
|
|
||||||
|
service ReviewsService {
|
||||||
|
|
||||||
|
event reviewed : { subject:String; rating: Decimal(2,1) };
|
||||||
|
|
||||||
|
// API
|
||||||
|
entity Reviews as projection on my.Reviews excluding { likes }
|
||||||
|
action like (review:Reviews.ID);
|
||||||
|
action unlike (review:Reviews.ID);
|
||||||
|
|
||||||
|
// Input validation
|
||||||
|
annotate Reviews with {
|
||||||
|
subject @mandatory;
|
||||||
|
title @mandatory;
|
||||||
|
rating @mandatory @assert.enum;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-fill reviewers and review dates
|
||||||
|
annotate Reviews with {
|
||||||
|
reviewer @cds.on.insert:$user;
|
||||||
|
date @cds.on.insert:$now;
|
||||||
|
date @cds.on.update:$now;
|
||||||
|
}
|
||||||
|
}
|
||||||
40
packages/reviews-service/srv/reviews-service.js
Normal file
40
packages/reviews-service/srv/reviews-service.js
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
const cds = require('@sap/cds')
|
||||||
|
module.exports = cds.service.impl((srv) => {
|
||||||
|
|
||||||
|
// Get the CSN definition for Reviews from the db schema for sub-sequent queries
|
||||||
|
// ( Note: we explicitly specify the namespace to support embedded reuse )
|
||||||
|
const { Reviews, Likes } = cds.entities('sap.capire.reviews')
|
||||||
|
|
||||||
|
// Increment counter for reviews considered helpful
|
||||||
|
srv.on ('like', (req) => {
|
||||||
|
if (!req.user) return req.reject(400, 'You must be identified to like a review')
|
||||||
|
const {review} = req.data, {user} = req
|
||||||
|
const tx = cds.transaction(req)
|
||||||
|
return tx.run ([
|
||||||
|
INSERT.into (Likes) .entries ({review_ID: review, user: user.id}),
|
||||||
|
UPDATE (Reviews) .set({liked: {'+=': 1}}) .where({ID:review})
|
||||||
|
]).catch(() => req.reject(400, 'You already liked that review'))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Delete a former like by the same user
|
||||||
|
srv.on('unlike', async (req) => {
|
||||||
|
if (!req.user) return req.reject(400, 'You must be identified to remove a former like of yours')
|
||||||
|
const { review } = req.data, { user } = req
|
||||||
|
const tx = cds.transaction(req)
|
||||||
|
const affectedRows = await tx.run(DELETE.from(Likes).where({ review_ID: review, user: user.id }))
|
||||||
|
if (affectedRows === 1) return tx.run(UPDATE(Reviews).set({ liked: { '-=': 1 } }).where({ ID: review }))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Emit an event to inform subscribers about new avg ratings for reviewed subjects
|
||||||
|
// ( Note: req.on.succeeded ensures we only do that if there's no error )
|
||||||
|
srv.after(['CREATE', 'UPDATE', 'DELETE'], 'Reviews', async (_, req) => {
|
||||||
|
const { subject } = req.data
|
||||||
|
const { rating } = await cds.transaction(req).run(
|
||||||
|
SELECT.one(['avg(rating) as rating']).from(Reviews).where({ subject })
|
||||||
|
)
|
||||||
|
req.on('succeeded', () => {
|
||||||
|
srv.emit('reviewed', { subject, rating })
|
||||||
|
console.log(`Reviewed event was emitted for book "${subject}" with rating ${rating}.`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
11
shared/dev-env/package.json
Normal file
11
shared/dev-env/package.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "dev-env",
|
||||||
|
"author": "daniel.hutzel@sap.com",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/cds": "^3.17.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"sqlite3": "^4.0.7"
|
||||||
|
},
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
||||||
10
shared/tests-env/package.json
Normal file
10
shared/tests-env/package.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "tests-env",
|
||||||
|
"author": "daniel.hutzel@sap.com",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/jest": "*",
|
||||||
|
"jest": "^24.8.0",
|
||||||
|
"supertest": "^4.0.2"
|
||||||
|
},
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user