cloud-sdk-js icon indicating copy to clipboard operation
cloud-sdk-js copied to clipboard

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

Open yurecz opened this issue 4 years ago • 5 comments

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:

<EntityContainer Name="cds_lmd_route_Entities" m:IsDefaultEntityContainer="true"> <EntitySet Name="Route" EntityType="cds_lmd_route.RouteType" /> //Root <EntitySet Name="CustomerVisit" EntityType="cds_lmd_route.CustomerVisitType" sap:creatable="false"> //Child </EntityContainer> 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: <EntityContainer Name="cds_lmd_route_Entities" m:IsDefaultEntityContainer="true"> <EntitySet Name="Route" EntityType="cds_lmd_route.RouteType" /> //Root <EntitySet Name="CustomerVisit" EntityType="cds_lmd_route.CustomerVisitType" sap:creatable="true"> //Child </EntityContainer> 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.

yurecz avatar Oct 11 '21 09:10 yurecz

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.

artemkovalyov avatar Oct 11 '21 10:10 artemkovalyov

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: <Annotations Target="cds_lmd_route.cds_lmd_route_Entities/Route" xmlns="http://docs.oasis-open.org/odata/ns/edm"> <Annotation Term="Capabilities.NavigationRestrictions"> <Record> <PropertyValue Property="RestrictedProperties"> <Collection> <Record> <PropertyValue Property="NavigationProperty" NavigationPropertyPath="to_CustomerVisit" /> <PropertyValue Property="InsertRestrictions"> <Record> <PropertyValue Property="Insertable" Bool="true" /> </Record> </PropertyValue> </Record> </Collection> </PropertyValue> </Record> </Annotation> </Annotations> 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

yurecz avatar Oct 12 '21 11:10 yurecz

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.

marikaner avatar Apr 07 '22 15:04 marikaner

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

yurecz avatar May 30 '22 11:05 yurecz

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.

marikaner avatar Jul 18 '22 13:07 marikaner