Offline OData Plugin

(Supports OData V2 for Android, iOS, Windows 8.1, and Windows 10). Provides offline OData support to Hybrid SDK (Kapsel) applications.

The plugin provides the client with the ability to define offline stores for an OData producer. The clients can perform (create, update, or delete) operations without internet connectivity and then flush the changes when internet is available. When an offline store is first opened, it synchronizes with the OData producer. OData requests made against this plugin use the available open offline stores.

The plugin uses the OData component from the SAP Mobile Platform SDK.

Offline functionality requires that your application registers with a SAP HCP, mobile service for development and operations or SAP Mobile Platform server. For more information, see Logon Plugin.

Custom OData httpclient

The Offline OData plugin provides a OData httpclient based on datajs, a cross-browser JavaScript library. The httpclient resolves requests with the Offline OData plugin if the service root of the request matches one of the open stores. The httpclient defaults to using the original OData.defaultHttpClient if the requests service root does not match any of the currently open stores.

You must explicitly apply the custom httpclient in the JavaScript.


OData Requests outside datajs

An OData request may be made directly with an XMLHttpRequest, or a library other than datajs may be used. For these cases, you must use the sap.OData.request method to perform the request. This method is used by the custom httpclient, which can be used as a reference.

Flushing Offline Outbound Queue

You must explicitly call the flush method on a store to send modifications to the OData producter. Events are provided in the JavaScript for when a flush starts, error occurs, and flush ends.

Refreshing Data

You must explicitly refresh your stores to get changes from the OData producer. The plugin provides a refresh method that you can call to refresh the whole store or a subset of it.

Background Synchronization

The plugin enables execution in the background. Flush and refresh operations that were started while the mobile application was in the foreground might continue the execution even after the application is sent into the background.

In order to schedule a refresh or flush operation that should continue when the application goes into the background, you need to explicitly call the respective Javascript APIs.

The functionality that allows the continued execution of flush and refresh operations comes with a feature that allows for automatic synchronization with the server. The Kapsel Offline Plugin is notified about lifecycle changes of the applications. These callbacks are used to trigger the flush and the refresh operations. The onPause method is called when the application is sent to background. The onResume method is called when the activity comes back to foreground and will trigger a refresh.

Both of these operations are configurable. When a store is opened, then the following code is performed in the user interface (Javascript) part of the application:

var options = { "autoRefresh": true, //enables automatic refresh when the application enters foreground     
                "autoFlush": true //enables automatic flush when the application goes into the background };, errorCallback, options);

The options object contains the flags for turning on the automatic refresh and the flush operations. The settings are available for each store separately. These setting do not persist, so they must be specified each time a store is opened. The default values for each option are false, so automatic synchronization is turned off by default.

You can find additional details about background synchronization on the SAP Community Network (SCN) Getting Started with Kapsel - Part 15 -- Offline OData (New in SP05)Information published on SAP site , and the OData API documentation that is bundled with the SAP Mobile Platform SDK.

Error Recovery

The event onrequesterror is fired if a request fails against the OData producer.

You can provide detailed information about errors through the ErrorArchive. The ErrorArchive logs business logic errors and ETag mismatch errors. You can configure an offline application to access the ErrorArchive so that end users can read and delete logged errors. See Designing an Offline Application to Handle Conflicts and Errors in Developer < Native OData Application Development.