cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Cloud SDK - Get and Convert Filter Expression not working

Hi all,

we've created a CDS based OData service in Cloud Foundry with CAP to call an OData exposed by a SAP ECC and as we read on this blog:

https://blogs.sap.com/2019/02/28/sap-s4hana-cloud-sdk-version-2.12.0-is-available/

we should be able to convert the filter expression retrieved from the QueryRequest object into the filter expression that can be used in the filter method of the ODataQueryBuilder object.

We've modified the following dependency version in the pom.xml file:

<dependency>

<groupId>com.sap.cloud.s4hana</groupId>

<artifactId>sdk-modules-bom</artifactId>

<version>2.18.0</version>

<scope>import</scope>

<type>pom</type>

</dependency>

So when we start our service and try to invoke GET method with filter property set as show:

/odata/v2/Search1LService/Mmain?$filter=('Maufnr' eq '0001')

we get an exception because of the filter format.

Apparently the queryRequest.getQueryExpression() provides the right filter data but when we try to convert this object into the FilterExpression object something goes wrong.

As you can see the String value is: " eq %27Maufnr%27" instead of "%27Maufnr%27%20eq%20%270001%27".

The FilterExpression object (fe2) has obviously the same issue, so the execute call ends with an exception, because the OData filter we are passing to the backend system has a wrong format.

In the blog the author passes the FilterExpressionConverter.queryRequest.getQueryExpression() object to UncheckedFilterExpression costructor to buid the filter input parameter:

myService.getAllSomething()

.filter(new UncheckedFilterExpression<>(

FilterExpressionConverter.convertTo(

queryRequest.getQueryExpression())))

.execute();

In our class this code causes a syntax error because the filter doesn't accept this UncheckedFilterExpression object as input:

The method filter(FilterExpression) in the type ODataQueryBuilder is not applicable for the arguments (new UncheckedFilterExpression<>(FilterExpressionConverter.convertTo(queryRequest.getQueryExpression())))Java Debug

Can someone please help with the issue? Is there something wrong to get the expression or is there a bug in the Cloud SDK to convert the Expression?

Best regards

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Christoph,

we found the solution for the problem.

-> the filter expression was wrong

The question can be closed.

Answers (3)

Answers (3)

0 Kudos

Hi Marvin,

how did you solve it?

thanks

Johannes

0 Kudos

Hi Christoph,

thank you for your help. You're right the second use case was just a try to make it work. The real problem here is we call the first OData service with a Filter:

$filter=('Maufnr' eq '0001')

Then we want to extract this Filter Value Maufnr eq 0001, so we use queryRequest.getQueryExpression(), that returns the object with correct value.

As next step we try to call the next OData service with the filter value, here we need a FilterExpression Object but the method FilterExpressionConverter.convertTo(queryRequest.getQueryExpression()))

- returns only 'eq Maufnr' instead of something like 'Maufnr eq 0001'

Is this correct it looks like there is only the key but where is the value 0001?

There is no stack trace from the Java App -> because there is only an exception thrown from the backend service like -> wrong filter expression

Thanks

Marvin

cschubert
Participant
0 Kudos

Hi Marvin,

in your first described use case, can you please add the stack trace of the exception you received? My assumption would be that the escaping should take place later in the call chain, not in the toString() method.

Regarding the second use case: The UncheckedFilterExpression is intended to be used with the OData VDM of the "SAP Cloud SDK", which is built on top of e.g. the ODataQueryBuilder of the "SAP Cloud Platform SDK for service development" that you are using. This means you cannot use our UncheckedFilterExpression within the ODataQueryBuilder (and shouldn't need to).

Using our OData VDM you can hide all those String properties into a type-safe facade that does all the heavy lifting for you. For further details have a look here and here.

Greetings

Chris