diff --git a/suppliers/monkey-patch.js b/suppliers/monkey-patch.js index 5b24936a..139502ad 100644 --- a/suppliers/monkey-patch.js +++ b/suppliers/monkey-patch.js @@ -1,5 +1,7 @@ const deploy = require("@sap/cds/lib/deploy"); +// TODO: https://github.wdf.sap.corp/cdx/cds/pull/1949 + const DEBUG = (...args) => console.log(...args); deploy.exclude_external_entities_in = function (csn, _bound) { @@ -12,8 +14,6 @@ deploy.exclude_external_entities_in = function (csn, _bound) { DEBUG && DEBUG("excluding external entities for", service, "..."); const prefix = service + "."; for (let each in csn.definitions) { - const def = csn.definitions[each]; - if (def["@cds.persistence.table"] === true) continue; if (each.startsWith(prefix)) { DEBUG && DEBUG("excluding external entity", each); _exclude(each); diff --git a/suppliers/requests.http b/suppliers/requests.http index 5a28c19d..b6678750 100644 --- a/suppliers/requests.http +++ b/suppliers/requests.http @@ -20,7 +20,14 @@ Content-Type: application/json "supplier_ID": "PNG" } +### +PATCH {{bpServer}}/api-business-partner/A_BusinessPartner('PNG') +Content-Type: application/json + +{ + "BusinessPartnerFullName": "Penguin Books (Changed)" +} ### diff --git a/suppliers/srv/external/API_BUSINESS_PARTNER.js b/suppliers/srv/external/API_BUSINESS_PARTNER.js index dcb2e7b6..325e75cc 100644 --- a/suppliers/srv/external/API_BUSINESS_PARTNER.js +++ b/suppliers/srv/external/API_BUSINESS_PARTNER.js @@ -1,11 +1,10 @@ const cds = require('@sap/cds'); module.exports = cds.service.impl(async function (srv) { - const messaging = await cds.connect.to('messaging') const { A_BusinessPartner } = this.entities; srv.after('UPDATE', A_BusinessPartner, data => { console.log(`>>> BusinessPartner updated ${data.BusinessPartner}`); - messaging.emit("BusinessPartners/Changed", { businessPartners: [ data.BusinessPartner ] }); + srv.emit("A_BusinessPartner.Changed", { businessPartners: [ data.BusinessPartner ] }); }); }); diff --git a/suppliers/srv/mashup.cds b/suppliers/srv/mashup.cds index 173f5ab4..d1648bc7 100644 --- a/suppliers/srv/mashup.cds +++ b/suppliers/srv/mashup.cds @@ -66,3 +66,11 @@ extend service AdminService with { extend projection CatalogService.ListOfBooks with { supplier } + +// Extend S4 service with not modelled event +extend service S4 { + @topic: 'BusinessPartners/Changed' + event A_BusinessPartner.Changed { + BusinessPartners: array of S4.A_BusinessPartner:BusinessPartner; + } +} \ No newline at end of file diff --git a/suppliers/srv/mashup.js b/suppliers/srv/mashup.js index 5c70556e..84d4ea9a 100644 --- a/suppliers/srv/mashup.js +++ b/suppliers/srv/mashup.js @@ -10,7 +10,6 @@ module.exports = async()=>{ // called by server.js 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 - const messaging = await cds.connect.to('messaging'); // Reflect CDS definition of the Suppliers entity const Suppliers = db.entities["sap.capire.bookshop.Suppliers"]; @@ -41,7 +40,8 @@ module.exports = async()=>{ // called by server.js // Subscribe to changes in the S4 origin of Suppliers data // REVISIT: cds context is still from the UPDATE method when running in same programm, but should // be a separate - messaging.on ('BusinessPartners/Changed', async msg => { //> would be great if we had batch events from S/4 + // https://github.wdf.sap.corp/cap/matters/projects/44#card-196556 + S4bupa.on ('A_BusinessPartner.Changed', async msg => { //> would be great if we had batch events from S/4 await new Promise( resolve => setTimeout( resolve, 1000 )); const tx = cds.db.tx(msg); let replicas = await tx.run(SELECT('ID').from (Suppliers) .where ('ID in', msg.data.businessPartners)); @@ -81,24 +81,24 @@ module.exports = async()=>{ // called by server.js } + // TODO: remove test code { - // one server: returns AdminSuppliers - // two servers: returns A_BusinessPartner + // one server: returns AdminService.Suppliers + // two servers: returns API_BUSINESS_PARTNER.A_BusinessPartner const tx = S4bupa.tx({}); let result = await tx.run(SELECT('*').from ('AdminService.Suppliers') .where ('ID =', 'ACME')); tx.commit(); console.log(result); } + // TODO: remove test code { - // one server: returns AdminSuppliers - // two servers: returns AdminSuppliers + // one server: returns AdminService.Suppliers + // two servers: returns AdminService.Suppliers const tx = db.tx({}); let result = await db.run(SELECT('*').from ('AdminService.Suppliers') .where ('ID =', 'ACME')); tx.commit(); console.log(result); } - //process.exit(0); - }