cancel
Showing results for 
Search instead for 
Did you mean: 

Filter Offline Store in Native Android App for SMP 3

Former Member
0 Kudos

Hello,

I develop a native Android App that use a OData Gateway Service. For that I followed the guides postet by Former Member 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

Accepted Solutions (1)

Accepted Solutions (1)

claudiapacheco
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Mirco, I wonder if it's necessary to encode the defining request. I'll investigate further, but in the meantime, have you tried to set the defining request to

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

Best regards,

Claudia

Former Member
0 Kudos

Hi Claudia,

thank you for your answer. The encoded request worked fine for my first example with the full dataset returning service. That's why I never questioned. But now I have tried it and it makes no difference.

Greetings,

Mirco

claudiapacheco
Product and Topic Expert
Product and Topic Expert
0 Kudos

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?

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


Former Member
0 Kudos

Hi Claudia,

deleting the app solved the problem. I always cleaned the app data in the device settings and thought that this also deletes the database. Looks as if I was wrong.

Thank you very much!

Greetings,

Mirco

Former Member
0 Kudos

Hi Claudia,

We have a similar issue with our application. Adding filter values while defining request for offline store  as you mentioned does work fine for us.

But if we need to pass the filter values dynalically, how do we handle it in case of offline? Like if we have to pass a value from a drop down selection as a filter to the collection, that needs to be accessed in offline, how can we pass this value to the filter for the request in offline store?

Please suggest on this.

Thanks,

Narasimha

Former Member
0 Kudos

Good Morning Narasimha,

I have the same use case. The problem is that you can not re-initialize the offline store. If you want to use a dynamic filter, you have to delte and create the offline store by every change. That means in your case with the drop down selection: For every selection in the box check if the offline store is created. If it is, delete the store. Then create a new one with the actual filter from the box.

But what is the reason to use this solution? Why is it not possible for you to synchronise all dataset from the drop down box to the offline store. For example if your drop down box has 10 options, fill the offline store with a filter for all this 10 options. If the user select one option in the box, go and get this one from your offline store with a normal query.

The other think that comes me in mind: The solution to re-create the offline store needs a online connection. So what is the benefit of the offline store if you can use it only with your actual selection? The user must be sure about the right selection befor he goes offline and are not able to change this option until he is back online.

Greetings,

Mirco

Answers (0)