on 2023 Oct 11 8:37 PM
Dear community,
we are connecting one cap service to another to access and also maintain their entities. this works fine by
1) following the setup steps as documented in capire Consuming Services | CAPire (cloud.sap) (-> For a Remote CAP Service)
2) doing as follows in service.js file:
const externalService = await cds.connect.to('esternalService');
srv.on('READ', 'EXTERNAL_ENTITY', async (req) => {
const response = await externalService (req.query);
}
like this we can retrieve and access entities from another remote cap service. Still, in case we have compositions associated with our external target entities we are not allowed to access / maintain them. Does anyone know how we can achieve this?
we implemented the on READ logic as suggested here : BTP App external service (Step 2) but there we always end up with a
"Entity \"EXTERNAL_ENTITY\" is annotated with \"@cds.persistence.skip\" and cannot be served generically." error
Best Regards
Request clarification before answering.
Hi Max,
we had the same problems and started to write our own implementation of a "generic" extend logic similar to the logic used in the tutorial, then we stumbled upon this npm package: https://www.npmjs.com/package/@sap/external-service-mashup.
Although undocumented, that seems to work really well in our scenarios (READ when expanding from local to remote entities).
Basic steps: create a MashupHandler instance (let's call it mashupHandler), call mashupHandler.init(<remote-entity>) for all your remote entities and simply register an on-READ handler like:
this.on('READ', [your, remote, entities], async (req, next) => {
return mashupHandler.handle({req, next});
})
Best Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @martin-kl,
I am in the process of adding an external service to my CAP project to retrieve a list of our suppliers. To do this, I have added an association that refers to a supplier.
My problem now is that the association cannot be resolved by the standard implementation. Your comment seemed very interesting and also the package itself seems to be able to solve my problem with the navigation to an external association, but unfortunately the implementation is not sufficiently documented for me so that I can't get it installed.
Can you by chance share some more information on how I can implement the handler from the NPM package?
Hi @t00707,
you require the @sap/external-service-mashup via
const MashupHandler = require('@sap/external-service-mashup');
at the beginning of a service. To use it, you have to instantiate it and tell it what entities are expanded and where it should run. A complete setup can look like this:
module.exports = class MyCapSrv extends cds.ApplicationService {
async init() {
const { ExternalEntity } = this.entities;
// 1.: initiate mashup_handler and register external entities
const mashup_handler = new MashupHandler(this);
mashup_handler.init(ExternalEntity);
// 2.: invoke mashup_handler on all local entities that you want to expand from
this.on('READ', LocalEntityA, async (req, next) => {
const ret = await mashup_handler.handle(req, next);
return ret;
});
super.init();
}
};
where ExternalEntity is a projection on an entity from an external service. LocalEntityA on the other hand is one of your locally used entities, i.e. an entity that you model and use only in your CAP application.
Best, Martin
User | Count |
---|---|
31 | |
10 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.