Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Filter Offline Store in Native Android App for SMP 3

Hello,

I develop a native Android App that use a OData Gateway Service. For that I followed the guides postet by @Claudia Pacheco for the offline store.

Everything works fine for the following example:

My OData Service http://hostname:port/sap/servicename.srv/ returns for a unfilterted request of ProductSet all Products

In my code:

[...]

ODataOfflineStoreOptions options = new ODataOfflineStoreOptions();

options.addDefiningRequest("ProductSet", "ProductSet", false);

offlineStore.openStoreSync(options);

[...]

String resourcePath = "ProductSet?$filter=Manufactor%20eq%20%27ABC%27%20;
ODataRequestParamSingle request = new ODataRequestParamSingleDefaultImpl();
request.setMode(ODataRequestParamSingle.Mode.Read);
request.setResourcePath(resourcePath);
ODataResponseSingle response = (ODataResponseSingle) offlineStore.executeRequest(request);

So if the unfiltered service return 20 Products, the filtered returns 3 Products. Everything is fine.

My Problem is now that the OData Gateway Service return 0 Products for unfiltered Requests. Thats because of to large Data and security reasons.

So http://hostname:port/sap/servicename.srv/ProductSet return 0

     http://hostname:port/sap/servicename.srv/ProductSet?$filter=Manufactor eq 'ABC' return 3

That means for my Code snippet above an empty offline store and my filtered request is useless. I have to fill the offline store with a filter. So I tried

[...]

ODataOfflineStoreOptions options = new ODataOfflineStoreOptions();

options.addDefiningRequest("ProductSet", "ProductSet?$filter=Manufactor%20eq%20%27ABC%27%20", false);

offlineStore.openStoreSync(options);

[...]

But that also leads to an empty store. How can I get a Offline Store with pre-filtered Data?

Thanks in advance,

Mirco

Tags:
replied

Hi Mirco,

From the code perspective, setting the defining request the way you are doing it, should work

options.addDefiningRequest("ProductSet", "ProductSet?$filter=Manufactor eq 'ABC'", false);

When you test in your emulator or android device, do you delete the app and test again? just want to make sure you are deleting the local database before you re test.

Can you also test to send a GET request to ProductSet?$filter=Manufactor eq 'ABC'  through the SMP server as explain in this blog? SMP 3.0 : REST API Application Development

With this test we'll make sure the security configuration in your SMP server is not causing the backend to return 0 items.


Best regards,

Claudia


1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question