cancel
Showing results for 
Search instead for 
Did you mean: 

Need help on SMP 3.0 in defining multiple request for SODataOfflineStoreOptions

Former Member
0 Kudos

Hi,

Can someone help me on solving below issue. Thanks in advance.

I am using OData service to download  data in my iOS native application. We have customer and order data on server. On initial launch of application, i am downloading all customers data in my offlineStore. Now the problem what I am facing is If I want to download specific orders for a particular customer as both has relationship. Its not downloading the orders data. Below is the piece of code for definingRequest for downloading orders.

     SODataOfflineStoreOptions * storeOptions = [self OfflineStoreOptionsSharedInstance];

   

     NSLog(@"orders storeOptions : %@", storeOptions);

   

    NSString *keyValue = [NSString stringWithFormat:@"Orders?$filter=CustomerID eq '%@'", @"VINET"];

   

    storeOptions.definingRequests[@"req"] = keyValue;

If someone provide me the code snippet or any link where I can find anything. It will be very helpful.

Thanks,

Ashish jha

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Below is the OData service which we are using. If you will go through it, it has number of collections. In my application, I want to download only customer data which I am populated in first screen. On selecting  any customer from list, I want to download orders related to that customer. I think now I have given you clear picture of my problem.

http://services.odata.org/V4/Northwind/Northwind.svc/

Looking for your response.

Thanks.

midhun_vp
Active Contributor
0 Kudos

Hi Ashish,

If you want to get the list of orders based on a customer, you need to use FILTER query. This makes it possible to filter sets of resources based on the expression.

Example: http://services.odata.org/Northwind/Northwind.svc/Orders?$filter=CustomerID eq 'VINET'

If you want to use the orders list offline you need to delete the offline store each time when you are changing the query. Ex. from Orders?$filter=CustomerID eq 'VINET' to Orders?$filter=CustomerID eq 'AAAA' but this is too expensive.

So if possible define the requests for both Customers and Orders in a single offline store(hence you have all customers and Orders in offline store) and then do the query as needed.

Ex.

options.definingRequests[@"req1"] = @"/Customers"; 

options.definingRequests[@"req2"] = @"/Orders"; 


Also you could have a look at the expand query. If this query is implemented with Customer and orders it should be fine.


One more point to note is that when you are using the configuring Odata service you need to use http://services.odata.org/V2/Northwind/Northwind.svc/ instead of http://services.odata.org/V4/Northwind/Northwind.svc/ because offline supports only version 2.


Regards,Midhun

SAP Technology RIG

Former Member
0 Kudos

Hi Midhun,

Thanks for your reply. If we will have 10 collections in our OData Service, then you mean to say we should download all 10 collections in a single shot and then query as needed ?

In above comment where you explained "So if possible define the requests for both Customers and Orders in a single offline store(hence you have all customers and Orders in offline store) and then do the query as needed." You don't think so its useless to download all orders in device DB when we are not going to use all ? Each time I want to download orders data for a specific customerID. How can i do that ?

Thanks,

Ashish jha

midhun_vp
Active Contributor
0 Kudos

Hi Ashish,

The problem is that the offline store requests that you are defining are static, you can't change it later unless you delete the offline store and recreate it. And this process is expensive.

And you are right that the 2nd workaround I given (create request without filters) stores unwanted data in your device. But that's how offline works at present.

Regards,Midhun

SAP Technology RIG

Former Member
0 Kudos

Hi Midhun,

I'm not getting to set multiple requests. Only with one request.

Is there any parameter i must to set for multiple requests?

The offlineStore try to open 2 times and presents the error: "Store Open failed Error Domain=NetworkDomain Code=3 "[-10210] The operation failed due to an error on the server."


Any ideia?

My code:

- (void)open {

    _appDelegate = [[UIApplication sharedApplication] delegate];

    NSError *error = nil;

    SODataOfflineStore *offlineStore = [[SODataOfflineStore alloc] init];

   

    [offlineStore setOfflineStoreDelegate: self];

    [offlineStore setRequestErrorDelegate: self];

   

    _store = offlineStore;

    [(SODataOfflineStore *)_store openStoreWithOptions: [self storeOptions] error: &error];

}

- (SODataOfflineStoreOptions*)storeOptions {

    SODataOfflineStoreOptions* options = [[SODataOfflineStoreOptions alloc] init];

    NSError *error = nil;

    MAFLogonCore *logonCore = _appDelegate.logonCore;

    HttpConversationManager* httpConvManager = [[HttpConversationManager alloc] init];

    MAFLogonContext *context;

   

    if ([logonCore unlockSecureStore: kRegisterPersistToken error:&error]) {

        context = [logonCore getContext:&error];

    }

   

    MAFLogonRegistrationContext *regContext = context.registrationContext;

    options.enableHttps = regContext.isHttps;

    options.host = regContext.serverHost;

    options.port = regContext.serverPort;

    options.storeEncryptionKey = kRegisterPersistToken;

    options.serviceRoot = [NSString stringWithFormat:@"/%@",   regContext.applicationId];

    options.definingRequests[@"req"] = @"/Cliente";

    options.definingRequests[@"req2"] = @"/Usuario";

    options.storeName = @"Store1";

    options.enableRepeatableRequests = NO;

    options.conversationManager = httpConvManager;

   

    return options;

}

Att,

Ederich, Allan

It's Mobile SAP Partner

Former Member
0 Kudos

Hi Ashish,

Can you please share the code inside selfOfflineStoreOptionsSharedInstance ??

As definingRequests is NSMutableDictionary, you can add as many defining requests as you like. The value is OData URLs, relative to the service root.


SODataOfflineStore *offlineStore = [[SODataOfflineStore alloc] init];

SODataOfflineStoreOptions *options = [[SODataOfflineStoreOptions alloc] init];

options.host = serverHost;

options.port = serverPort;

options.serviceRoot = [NSString stringWithFormat:@"/%@", applicationId];

options.conversationManager = myConversationManager;

options.storeEncryptionKey = @"MyEncryptionKey";

options.definingRequests[@"req1"] = @"/Customers";

options.definingRequests[@"req2"] = @"/Orders";

[offlineStore setOfflineStoreDelegate:self];

  [offlineStore openStoreWithOptions:options error:&error];


Regards,

Dhani

Former Member
0 Kudos

Thanks for your reply.

But I don't want to download all orders as what you are doing in above code snippet. We have relationship between customer and orders, so I want to download customer specific orders by passing CustomerId as filter. Initially I am downloading only customers. On selecting any customer, I want to download orders related to it.

Former Member
0 Kudos

Hi Ashish,

Are you getting any errors? Is network connectivity available while making the request?

Regards,

Dhani

Former Member
0 Kudos

No, I am not getting any error. Since I have already downloaded customer data, so next time when I am trying to download customer specific orders, its opening the store and refreshing. But nothing getting downloaded. Can you tell me the steps what need to do to download customers and then based on CustomerID , download orders.

Thanks,