cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAP - Select Remote OData Entity With Primary Keys

tobiasfue
Explorer
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

marcbecker
Employee
Employee

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.

Answers (0)