demo -> done
This commit is contained in:
1
done/.cdsrc.json
Normal file
1
done/.cdsrc.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
24
done/.eslintrc
Normal file
24
done/.eslintrc
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2017
|
||||
},
|
||||
"globals": {
|
||||
"SELECT": true,
|
||||
"INSERT": true,
|
||||
"UPDATE": true,
|
||||
"DELETE": true,
|
||||
"CREATE": true,
|
||||
"DROP": true,
|
||||
"cds": true
|
||||
},
|
||||
"rules": {
|
||||
"no-console": "off",
|
||||
"require-atomic-updates": "off"
|
||||
}
|
||||
}
|
||||
29
done/.gitignore
vendored
Normal file
29
done/.gitignore
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# CAP demo
|
||||
_out
|
||||
*.db
|
||||
connection.properties
|
||||
default-*.json
|
||||
gen/
|
||||
node_modules/
|
||||
target/
|
||||
|
||||
# Web IDE, App Studio
|
||||
.che/
|
||||
.gen/
|
||||
|
||||
# MTA
|
||||
*_mta_build_tmp
|
||||
*.mtar
|
||||
mta_archives/
|
||||
|
||||
# Other
|
||||
.DS_Store
|
||||
*.orig
|
||||
*.log
|
||||
|
||||
*.iml
|
||||
*.flattened-pom.xml
|
||||
|
||||
# IDEs
|
||||
# .vscode
|
||||
# .idea
|
||||
20
done/.vscode/extensions.json
vendored
Normal file
20
done/.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
|
||||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
|
||||
|
||||
// List of extensions which should be recommended for users of this workspace.
|
||||
"recommendations": [
|
||||
// >>>>>>>> Add CDS Editor here as soon it is available of vscode marketplace!,
|
||||
"dbaeumer.vscode-eslint",
|
||||
"esbenp.prettier-vscode",
|
||||
"mechatroner.rainbow-csv",
|
||||
"humao.rest-client",
|
||||
"alexcvzz.vscode-sqlite",
|
||||
"hbenl.vscode-mocha-test-adapter",
|
||||
"sdras.night-owl"
|
||||
],
|
||||
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
|
||||
"unwantedRecommendations": [
|
||||
|
||||
]
|
||||
}
|
||||
15
done/.vscode/launch.json
vendored
Normal file
15
done/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
// 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": [
|
||||
{
|
||||
"command": "cds run --with-mocks --in-memory?",
|
||||
"name": "cds run",
|
||||
"request": "launch",
|
||||
"type": "node-terminal",
|
||||
"skipFiles": [ "<node_internals>/**" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
7
done/.vscode/settings.json
vendored
Normal file
7
done/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files.exclude": {
|
||||
"**/.gitignore": true,
|
||||
"**/.git": true,
|
||||
"**/.vscode": true
|
||||
}
|
||||
}
|
||||
25
done/.vscode/tasks.json
vendored
Normal file
25
done/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "cds watch",
|
||||
"command": "cds",
|
||||
"args": ["watch"],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "cds run",
|
||||
"command": "cds",
|
||||
"args": ["run", "--with-mocks", "--in-memory?"],
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
||||
25
done/README.md
Normal file
25
done/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Getting Started
|
||||
|
||||
Welcome to your new project.
|
||||
|
||||
It contains these folders and files, following our recommended project layout:
|
||||
|
||||
File or Folder | Purpose
|
||||
---------|----------
|
||||
`app/` | content for UI frontends goes here
|
||||
`db/` | your domain models and data go here
|
||||
`srv/` | your service models and code go here
|
||||
`package.json` | project metadata and configuration
|
||||
`readme.md` | this getting started guide
|
||||
|
||||
|
||||
## Next Steps
|
||||
|
||||
- Open a new terminal and run `cds watch`
|
||||
- (in VS Code simply choose _**Terminal** > Run Task > cds watch_)
|
||||
- Start adding content, for example, a [db/schema.cds](db/schema.cds).
|
||||
|
||||
|
||||
## Learn More
|
||||
|
||||
Learn more at https://cap.cloud.sap/docs/get-started/.
|
||||
0
done/app/vue/index.html
Normal file
0
done/app/vue/index.html
Normal file
30
done/package.json
Normal file
30
done/package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "demo",
|
||||
"version": "1.0.0",
|
||||
"description": "A simple CAP project.",
|
||||
"repository": "<Add your repository here>",
|
||||
"license": "UNLICENSED",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@capire/bookshop": "^1.0.0",
|
||||
"@capire/common": "^1.0.0",
|
||||
"@capire/orders": "^1.0.0",
|
||||
"@capire/reviews": "^1.0.0",
|
||||
"@sap/cds": "^4",
|
||||
"express": "^4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"sqlite3": "5.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "cds run"
|
||||
},
|
||||
"cds": {
|
||||
"requires": {
|
||||
"API_BUSINESS_PARTNER": {
|
||||
"kind": "odata",
|
||||
"model": "srv/external/API_BUSINESS_PARTNER"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
67
done/server.js
Normal file
67
done/server.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const cds = require('@sap/cds')
|
||||
module.exports = cds.server
|
||||
|
||||
|
||||
cds.once('bootstrap',(app)=>{
|
||||
app.use('/vue',_from('@capire/bookshop/app/vue'))
|
||||
})
|
||||
|
||||
|
||||
|
||||
cds.once('served', async ()=>{
|
||||
|
||||
// Connect to services we want to mashup below...
|
||||
const S4bupa = await cds.connect.to('API_BUSINESS_PARTNER') //> external S4 service
|
||||
const admin = await cds.connect.to('AdminService') //> local domain service
|
||||
const db = await cds.connect.to('db') //> our primary database
|
||||
|
||||
// Reflect CDS definition of the Suppliers entity
|
||||
const Suppliers = S4bupa.entities
|
||||
|
||||
// admin.prepend (()=>{
|
||||
|
||||
// Delegate Value Help reads for Suppliers to S4 backend
|
||||
admin.on ('READ', 'Suppliers', req => {
|
||||
console.log ('>> delegating to S4 service...')
|
||||
return S4bupa.read(Suppliers) .where (req.query.where)
|
||||
})
|
||||
|
||||
|
||||
// Replicate Supplier data when Books are edited
|
||||
admin.on (['CREATE','UPDATE'], 'Books', async req => {
|
||||
const { supplier } = req.data
|
||||
if (supplier) {
|
||||
let cached = await db.read (Suppliers, supplier)
|
||||
if (!cached) await replicate (supplier,'initial')
|
||||
}
|
||||
})
|
||||
|
||||
// })
|
||||
|
||||
// Subscribe to changes in the S4 origin of Suppliers data
|
||||
S4bupa.on ('BusinessPartner/Changed', async msg => {
|
||||
const ID = msg.businessPartner.KEYS
|
||||
const cached = await db.read (Suppliers, sup => sup.ID) .where ({ ID })
|
||||
for (let each of cached) replicate (each, 'update')
|
||||
})
|
||||
|
||||
// Helper function to replicate Suppliers data
|
||||
async function replicate (ID,_initial) {
|
||||
let data = await S4bupa.read (Suppliers, ID)
|
||||
if (_initial) return db.insert (data) .into (Suppliers)
|
||||
else return db.update (Suppliers,ID) .with (data)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Helper for serving static content from npm-installed packages
|
||||
const {static} = require('express')
|
||||
const {dirname} = require('path')
|
||||
const _from = target => static (dirname (require.resolve(`${target}/index.html`)))
|
||||
2425
done/srv/external/API_BUSINESS_PARTNER.csn
vendored
Normal file
2425
done/srv/external/API_BUSINESS_PARTNER.csn
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3261
done/srv/external/API_BUSINESS_PARTNER.edmx
vendored
Normal file
3261
done/srv/external/API_BUSINESS_PARTNER.edmx
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5
done/srv/external/data/API_BUSINESS_PARTNER-Suppliers.csv
vendored
Normal file
5
done/srv/external/data/API_BUSINESS_PARTNER-Suppliers.csv
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
ID;name;city
|
||||
ACME;A Company Making Everything;Massachusetts
|
||||
B4U;Books for You;Philadelphia
|
||||
S&C;Shakespeare & Co.;Paris
|
||||
WSL;Waterstones;London
|
||||
|
55
done/srv/services.cds
Normal file
55
done/srv/services.cds
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Optionally add projections to external entities, to capture what
|
||||
you actually want to use from there.
|
||||
*/
|
||||
|
||||
using { API_BUSINESS_PARTNER as S4 } from './external/API_BUSINESS_PARTNER.csn';
|
||||
extend service S4 with {
|
||||
entity Suppliers as projection on S4.A_BusinessPartner {
|
||||
key BusinessPartner as ID,
|
||||
BusinessPartnerFullName as name,
|
||||
to_BusinessPartnerAddress.CityName as city
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
You can mashup entities from external services, or projections
|
||||
thereof, with your project's own entities
|
||||
*/
|
||||
using { sap.capire.bookshop.Books } from '@capire/bookshop';
|
||||
extend Books with {
|
||||
supplier : Association to S4.Suppliers;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
You can also expose external entities through your own services
|
||||
For this to work, you need to delegate the respective calls
|
||||
addressed to your services into calls to the external service.
|
||||
*/
|
||||
extend service AdminService with {
|
||||
entity Suppliers as projection on S4.Suppliers;
|
||||
}
|
||||
|
||||
/*
|
||||
Optionally add a local persistence to keep replicas of external
|
||||
entities to have data in fast access locally; much like a cache.
|
||||
*/
|
||||
annotate S4.Suppliers with @cds.persistence:{table,skip:false};
|
||||
|
||||
/**
|
||||
Having locally cached replicas also allows us to display supplier
|
||||
data in lists of books, which otherwise would generate unwanted
|
||||
traffic on S4 backends.
|
||||
*/
|
||||
extend projection CatalogService.ListOfBooks with {
|
||||
supplier
|
||||
}
|
||||
|
||||
/*
|
||||
The following using directives activate imported reuse packages.
|
||||
*/
|
||||
using from '@capire/common';
|
||||
using from '@capire/orders';
|
||||
using from '@capire/reviews';
|
||||
Reference in New Issue
Block a user