SAP / cloud-sdk-js

Use the SAP Cloud SDK for JavaScript / TypeScript to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
162 stars 55 forks source link

The OData generated client has no way to add the new dependent entity if it is defined in the EDMX as not creatable #1667

Closed yurecz closed 2 months ago

yurecz commented 2 years ago

Hello,

I need to add the new dependent entity to the root entity. In the EDMX file the dependent entity is flagged as not creatable:

`

//Root //Child

` According to the documentation: https://sap.github.io/cloud-sdk/docs/js/features/odata/use-odata-v2-type-safe-client-for-javascript-typescript#create-as-child-of It can be done like this:

CustomerVisit.requestBuilder() .create(visit) .asChildOf( route, Route.TO_CUSTOMER_VISIT ) .execute(myDestination) The problem is that the OData client-generated coding does not have create method. So it is not clear how to add a new entity to the root.

Used workaround: manually change the EDMX file to make entity CustomerVisit creatable: `

//Root //Child

` Regenerate the OData client and it works.

Still very inconvenient always to remember that you need to change the EDMX file to make it work.

artemkovalyov commented 2 years ago

This sounds to me like a correct behavior if the entity is marked as sap:creatable="false". Your workaround also proves it. Where have you got a specification? If the service allows the creation of that entity then the specification is incorrect. As far as I remember we respect some vendor properties and sap:creatable is one of them.

I think it would be a good idea to clarify with the service owner what is the real intended behavior and ask them to fix the specification. Let us know what service that is.

yurecz commented 2 years ago

Hello,

The service definition is created from the ABAP side using the SAP RAP managed model. In this case, it is not allowed to define the child entity as creatable. This is taken from SAP standard help: create create is a modifying operation that creates new instances of a business object entity. ◾In a managed RAP BO, create can only be declared for root nodes. Child nodes are implicitly create-enabled for internal usage. That means an external consumer can only create a new instance of a child entity via its parent, see create-by-association operation. A direct creation can only take place from the BO's own implementation in the ABAP behavior pool.

But the association itself is enabled for creating/insert in the service definition file. See EDMX content snippet: `

` So it is either the SAP cloud SDK test client needs to react on the create by association annotation or the SAP managed RAP generate incorrect EDMX service definition.

Any ideas what is the correct way? Maybe for "create by the association" in the SAP SDK there are other ways to do it? But still would prefer to stay with generated proxy/client coding and not to do the freestyle OData service call.

If necessary, I could upload the whole EDMX file but it is rather long.

Best regards, Yuri

marikaner commented 2 years ago

Hey @yurecz,

you're opening up a very interesting point here. We currently do not support annotations yet. This might be the first step to a solution. Do you have any documentation that would allow us to learn about the rules of those? The reason I am asking is, that I would like to understand whether this is the case for all SAP system or only yours, whether this is a rule or a convention to better design an API around this.

For now, I have to admit that you probably will have to keep adding the "sap:creatable" attribute.

yurecz commented 2 years ago

Hello marikaner,

I think we should first understand if the service definition generated by the SAP RAP(EDMX) conforms to the OData V2 specification regarding creating the sub-entities. Two options are possible:

  1. RAP BO conforms, when we need simply fix it in the Cloud SDK
  2. RAP BO does conform when I open the SAP internal incident for RAP colleagues to properly generate the service definition(from ABAP side) and this issue can be closed. Do you know the source to be checked for the OData specification? I am not familiar with this topic.

Best regards, Yuri

marikaner commented 2 years ago

Hey @yurecz,

I found some more details on annotations. I would like to implement this, however this is a bigger chunk and will definitely take a lot of time until it will be available for you. I hope for now you can work with the workaround.

jjtang1985 commented 2 months ago

Due to the current priority, we won't work on this.