cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAP - Select Remote OData Entity With Primary Keys

tobiasfue
Explorer
0 Kudos
325

A stupid question...

I want to consume a remote service (oData) in SAP CAP Java and the URL/result must look like this: xyz.com/myEntity(key1='12345',key2=datetime'2022-02-01')/Results

My select looks like:

<code>SELECT.from(MyService_.CDS_NAME).columns(c -> c.Results().expand(...)).where(w -> w.key1().eq('12345').and().key2(...);

Our problem now is that this Where condition is of course implemented as $filter. But we have to address the entity via keys to get the results. And that without expand. The only examples I found always use byID and that only works with a key. Also other filter/match methods have led to the same undesired result.

The resulting URL looks like this:

<code>//xyz.com/myEntity?$filter=key eq '123' etc.

Is this possible in the Java SDK to have the URL look like described in the beginning?

Or do I have to build a HTTP client myself?

Unfortunately, I can't pull the root entity first. I have to go this way to address the keys and /Result directly. Please don't ask why.

View Entire Topic
marcbecker
Advisor
Advisor

If you want to build a URL path with CQN you need to specify the conditions and path segments in the "ref" of the Select. Please try this:

Select.from(MyEntity_.class, e -> e.filter(e.key1().eq("value1").and(e.key2().eq("value2")).Results()));

BTW: byId() is just a helper method that produces the same where condition as if you would explicitly write ".where(w -> w.myKey().eq('myId')"

tobiasfue
Explorer
0 Kudos

Thank you for your fast help! It worked.

SrijaniChat
Explorer
0 Kudos
Hi marcbecker, for CDS and NodeJS also I am facing the same issue, the Key Parameters are read as Filters in the URL and it's hitting the Get_EntitySet method instead of Get_Entity . In Capire documentation I can see byId is only mentioned in case of Java and with CQN Analyzer . will byId work in my case ? Thanks and Regards,