Compare commits
19 Commits
gdpr
...
suppliers-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
175e7b554f | ||
|
|
803432b8d9 | ||
|
|
0ddd70acbc | ||
|
|
3e52a9a102 | ||
|
|
b44701ef62 | ||
|
|
c23ddc7e54 | ||
|
|
66bd2f707c | ||
|
|
3320c7e5a2 | ||
|
|
a35782e775 | ||
|
|
e5bd8ec5a5 | ||
|
|
0aa95a0a67 | ||
|
|
5015eb8c52 | ||
|
|
6d3f4c689f | ||
|
|
f0fead2bc2 | ||
|
|
f1d780d6d9 | ||
|
|
796bf62bde | ||
|
|
5f176a0b88 | ||
|
|
a5c8b5101e | ||
|
|
d72ff809b0 |
@@ -3,9 +3,10 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@capire/bookshop": "*",
|
"@capire/bookshop": "*",
|
||||||
"@capire/reviews": "*",
|
|
||||||
"@capire/orders": "*",
|
|
||||||
"@capire/common": "*",
|
"@capire/common": "*",
|
||||||
|
"@capire/orders": "*",
|
||||||
|
"@capire/reviews": "*",
|
||||||
|
"@capire/suppliers": "*",
|
||||||
"@sap/cds": "^4",
|
"@sap/cds": "^4",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"passport": "^0.4.1"
|
"passport": "^0.4.1"
|
||||||
@@ -19,6 +20,10 @@
|
|||||||
"deploy-format": "hdbtable"
|
"deploy-format": "hdbtable"
|
||||||
},
|
},
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"API_BUSINESS_PARTNER": {
|
||||||
|
"kind": "odata",
|
||||||
|
"model": "@capire/suppliers"
|
||||||
|
},
|
||||||
"auth": {
|
"auth": {
|
||||||
"strategy": "dummy"
|
"strategy": "dummy"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ cds.once('bootstrap',(app)=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
cds.once('served', require('./srv/mashup'))
|
cds.once('served', require('./srv/mashup'))
|
||||||
|
cds.once('served', require('@capire/suppliers/srv/mashup'))
|
||||||
|
|
||||||
module.exports = cds.server
|
module.exports = cds.server
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,8 @@
|
|||||||
"@capire/hello": "./hello",
|
"@capire/hello": "./hello",
|
||||||
"@capire/media": "./media",
|
"@capire/media": "./media",
|
||||||
"@capire/orders": "./orders",
|
"@capire/orders": "./orders",
|
||||||
"@capire/reviews": "./reviews"
|
"@capire/reviews": "./reviews",
|
||||||
|
"@capire/suppliers": "./suppliers"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
"sqlite3": "5.0.0"
|
"sqlite3": "5.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"fix-antlr": "sed -i -e 's/INVALID_ALT_NUMBER = require.*/INVALID_ALT_NUMBER = 0/' node_modules/antlr4/tree/Trees.js node_modules/antlr4/RuleContext.js",
|
||||||
"registry": "node .registry/server.js",
|
"registry": "node .registry/server.js",
|
||||||
"bookshop": "cds watch bookshop",
|
"bookshop": "cds watch bookshop",
|
||||||
"fiori": "cds watch fiori",
|
"fiori": "cds watch fiori",
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ service ReviewsService {
|
|||||||
action unlike (review: type of Reviews:ID);
|
action unlike (review: type of Reviews:ID);
|
||||||
|
|
||||||
// Async API
|
// Async API
|
||||||
event reviewed : {
|
event reviewed : projection on Reviews {
|
||||||
subject: type of Reviews:subject;
|
subject,
|
||||||
rating: Decimal(2,1)
|
rating
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input validation
|
// Input validation
|
||||||
|
|||||||
12
samples.md
12
samples.md
@@ -49,14 +49,22 @@ Each sub directory essentially is an individual npm package arranged in an [all-
|
|||||||
- Late-cut Micro Services
|
- Late-cut Micro Services
|
||||||
- As well as managed data, input validations, and authorization
|
- As well as managed data, input validations, and authorization
|
||||||
|
|
||||||
|
## [@capire/suppliers](suppliers)
|
||||||
|
|
||||||
|
- Shows how to integrate remote services, in this case the BusinessPartner service from SAP S/4HANA.
|
||||||
|
- Extending [@capire/bookshop](bookshop) with suppliers from SAP S/4HANA
|
||||||
|
- Providing that as a pre-built integration & extension package
|
||||||
|
- Used in [@capire/fiori](fiori)
|
||||||
|
|
||||||
|
|
||||||
## [@capire/fiori](fiori)
|
## [@capire/fiori](fiori)
|
||||||
|
|
||||||
- A [composite app, reusing and combining](https://cap.cloud.sap/docs/guides/verticalize) these packages:
|
- A [composite app, reusing and combining](https://cap.cloud.sap/docs/guides/verticalize) these packages:
|
||||||
- [@capire/bookshop](bookshop)
|
- [@capire/bookshop](bookshop)
|
||||||
- [@capire/reviews](reviews)
|
|
||||||
- [@capire/orders](orders)
|
|
||||||
- [@capire/common](common)
|
- [@capire/common](common)
|
||||||
|
- [@capire/orders](orders)
|
||||||
|
- [@capire/reviews](reviews)
|
||||||
|
- [@capire/suppliers](suppliers)
|
||||||
- [Adds an SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookshop, thereby introducing to:
|
- [Adds an SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookshop, thereby introducing to:
|
||||||
- [OData Annotations](https://cap.cloud.sap/docs/guides/fiori#adding-odata-annotations) in `.cds` files
|
- [OData Annotations](https://cap.cloud.sap/docs/guides/fiori#adding-odata-annotations) in `.cds` files
|
||||||
- Support for [Fiori Draft](https://cap.cloud.sap/docs/guides/fiori#draft)
|
- Support for [Fiori Draft](https://cap.cloud.sap/docs/guides/fiori#draft)
|
||||||
|
|||||||
1
suppliers/index.cds
Normal file
1
suppliers/index.cds
Normal file
@@ -0,0 +1 @@
|
|||||||
|
using from './srv/mashup';
|
||||||
24
suppliers/package.json
Normal file
24
suppliers/package.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "@capire/suppliers",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Shows integration with SAP S/4HANA, in turn provided as a reusable extension package to bookshop.",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@capire/common": "*",
|
||||||
|
"@sap/cds": "^4",
|
||||||
|
"express": "^4"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "cds run --in-memory?",
|
||||||
|
"watch": "cds watch",
|
||||||
|
"mocked-s4": "cds mock API_BUSINESS_PARTNER"
|
||||||
|
},
|
||||||
|
"cds": {
|
||||||
|
"requires": {
|
||||||
|
"API_BUSINESS_PARTNER": {
|
||||||
|
"kind": "odata",
|
||||||
|
"model": "srv/external/API_BUSINESS_PARTNER"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
suppliers/server.js
Normal file
3
suppliers/server.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
const cds = require ('@sap/cds')
|
||||||
|
cds.once('served', require('./srv/mashup'))
|
||||||
|
module.exports = cds.server
|
||||||
2425
suppliers/srv/external/API_BUSINESS_PARTNER.csn
vendored
Normal file
2425
suppliers/srv/external/API_BUSINESS_PARTNER.csn
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3261
suppliers/srv/external/API_BUSINESS_PARTNER.edmx
vendored
Normal file
3261
suppliers/srv/external/API_BUSINESS_PARTNER.edmx
vendored
Normal file
File diff suppressed because it is too large
Load Diff
7
suppliers/srv/external/data/API_BUSINESS_PARTNER-A_BusinessPartner.csv
vendored
Normal file
7
suppliers/srv/external/data/API_BUSINESS_PARTNER-A_BusinessPartner.csv
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
BusinessPartner;BusinessPartnerFullName
|
||||||
|
ACME;A Company Making Everything
|
||||||
|
B4U;Books for You
|
||||||
|
S&C;Shakespeare & Co.
|
||||||
|
WSL;Waterstones
|
||||||
|
TLD;Thalia
|
||||||
|
PNG;Penguin Books
|
||||||
|
5
suppliers/srv/external/data/API_BUSINESS_PARTNER-Suppliers.csv
vendored
Normal file
5
suppliers/srv/external/data/API_BUSINESS_PARTNER-Suppliers.csv
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
ID;name
|
||||||
|
ACME;A Company Making Everything
|
||||||
|
B4U;Books for You
|
||||||
|
S&C;Shakespeare & Co.
|
||||||
|
WSL;Waterstones
|
||||||
|
25
suppliers/srv/mashup.cds
Normal file
25
suppliers/srv/mashup.cds
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
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';
|
||||||
|
|
||||||
|
@cds.autoexpose // or expose explicitly in Catalog and AdminService
|
||||||
|
@cds.persistence: {table,skip:false}
|
||||||
|
entity sap.capire.bookshop.Suppliers as projection on S4.A_BusinessPartner {
|
||||||
|
key BusinessPartner as ID, BusinessPartnerFullName as name
|
||||||
|
}
|
||||||
|
|
||||||
|
using { sap.capire.bookshop.Books, CatalogService } from '@capire/bookshop';
|
||||||
|
extend Books with {
|
||||||
|
supplier: Association to sap.capire.bookshop.Suppliers;
|
||||||
|
}
|
||||||
|
|
||||||
|
extend service AdminService with { // why is AdminService visible?
|
||||||
|
entity Suppliers as projection on sap.capire.bookshop.Suppliers;
|
||||||
|
}
|
||||||
|
|
||||||
|
extend projection CatalogService.ListOfBooks with {
|
||||||
|
supplier
|
||||||
|
}
|
||||||
57
suppliers/srv/mashup.js
Normal file
57
suppliers/srv/mashup.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Mashing up provided and required services...
|
||||||
|
//
|
||||||
|
module.exports = async()=>{ // called by server.js
|
||||||
|
|
||||||
|
if (!cds.services.AdminService) return //> mocking S4 service only
|
||||||
|
|
||||||
|
// 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 (()=>{ //> to ensure our .on handlers below go before the default ones
|
||||||
|
|
||||||
|
// Delegate Value Help reads for Suppliers to S4 backend
|
||||||
|
admin.on ('READ', 'Suppliers', req => {
|
||||||
|
console.log ('>> delegating to S4 service...')
|
||||||
|
return S4bupa.run(req.query)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Replicate Supplier data when edited Books have suppliers
|
||||||
|
admin.on (['CREATE','UPDATE'], 'Books', ({data:{supplier}}, next) => {
|
||||||
|
// Using Promise.all(...) to parallelize local write, i.e. next(), and replication
|
||||||
|
if (supplier) return Promise.all ([ next(), async()=>{
|
||||||
|
let replicated = await db.exists (Suppliers, supplier)
|
||||||
|
if (!replicated) await replicate (supplier, 'initial')
|
||||||
|
}])
|
||||||
|
else return next() //> don't forget to pass down the interceptor stack
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
// Subscribe to changes in the S4 origin of Suppliers data
|
||||||
|
S4bupa.on ('BusinessPartners/Changed', async msg => { //> would be great if we had batch events from S/4
|
||||||
|
let replicas = await SELECT('ID').from (Suppliers) .where ('ID in', msg.businessPartners)
|
||||||
|
return replicate (replicas.map(each => each.ID))
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to replicate Suppliers data.
|
||||||
|
* @param {string|string[]} IDs a single ID or an array of IDs
|
||||||
|
* @param {truthy|falsy} _initial indicates whether an insert or an update is required
|
||||||
|
*/
|
||||||
|
async function replicate (IDs,_initial) {
|
||||||
|
if (!Array.isArray(IDs)) IDs = [ IDs ]
|
||||||
|
let suppliers = await S4bupa.read (Suppliers).where('ID in',IDs)
|
||||||
|
if (_initial) return db.insert (suppliers) .into (Suppliers) //> using bulk insert
|
||||||
|
else return Promise.all(suppliers.map ( //> parallelizing updates
|
||||||
|
each => db.update (Suppliers,each.ID) .with (each)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user