Run your mobile app in offline and best practices-openSAP-Developing mobile apps with HCP-Week 5
Hello Developers,
Jeff Gebo started week 5 openSAP course Developing Mobile Apps with SAP HANA Cloud Platform with
- Overview of Offline OData and it’s 3 important sections: Initial Download, Flush & Refresh
- What important steps to be considered to implement for offline OData : server side paging, delta query, delta tracking
- How to use ‘Kapsel offline‘ template in Web IDE for developing an offline OData based hybrid application
- Deploying and testing it on device (most preferable than emulator/simulator)
- Various properties to be known while defining a ‘defining request’ in HCPms for offline capabilities
(Did he again has hair cut? 😉 )
IMO, Any enterprise level mobile application is incomplete without features like Push Notifications and Offline capabilities. As he mentioned, Business doesn’t always happen where networks exist. Its really important to such capabilities in your mobile app.
My findings:
- Client database that gets downloaded in offline OData scenario is called as UltraLite-type Database.
- OData V2 is supported for offline capabilities (Also V4 but for delta queries)
- If you have downloaded huge amount of data on your device and now you want to make a REFRESH call, its better to enable delta queries on your OData service, so that rather than refreshing all the data , it will bring only the data which has modified after a particular ‘timestamp‘
- HCPms supports middle-tier support for OData service that doesn’t have delta-enabled query capabilities.Here in this case, you will get complete data from backend to HCPms and then HCPms will compute delta based on cache keys (were stored during initial download on HCPms database) and send it to device. Not a recommended approach since it will not bring good performance
- It always better to enable middle-tier CACHING for generic OData collections (MASTER DATA) Check here for more info
- Communication from UltraLite DB to HCPms happens via Mobilink protocol over HTTP
- ETags: used to determine if there are any conflicts or not. Reference1
- OData service that doesnt support delta token use $expand to load entities and their relationships
“definingRequests” : { “req1” : “/Products?$expand=Suppliers” }
- You can also add OData URI primitives like $select, $filter to reduce the overall data transmitted to the client. Best approach to build an offline store for collections with $expand and delta queries?
9. applyHTTPClient() method is used to call local database for requests that are mapped to the offline store.
10. Server side enforced paging ($skiptoken) and Delta-tracking/query are important features to be implemented to bring great performance in an offline OData mobile application.
Delta Tracking: maintain the delta data at backend system (like SAP Gateway, Syclo Agentry xChange Framework) during CUD operations
Query: Fetch the delta via query operation with providing deltatoken (timestamp) value
Example: http://services.odata.org/V2/Northwind/Northwind.svc/Products
When to use delta tracking and when not
11. Offline OData constraints:
OData version 2 is supported for the offline OData feature, with several exceptions.
- There is no support for these OData concepts:
- Function imports.
- ETags when using the if-match/if-none-match headers when performing LOCAL reads.
- Modifying properties or complex type properties by addressing them in the URL.
- Metadata annotations are not populated in the Metadata object.
- Modifying entity relationships through entity bindings in entities.
- The Offline OData feature has the following limitations:
- The maximum length (MaxLength) of Edm.String key properties is 512 characters.
- The maximum length (MaxLength) of Edm.Binary key properties is 1536 bytes.
- The Android offline store does not support mutual authentication using X509Certificates loaded from the System KeyStore/KeyChain. It does support X509Certificates which are provided from a secure file store. The secure file store may be an SAP component, or 3rd party component, so long as the X509Certificate is supplied to the X509KeyManager when required.
- The navigation property used for the deep insert must refer to at most one entity.
-
- If you have an odata collection with a primary key which is a string, you need to make sure that maxlength field is defined for it. ( from Midhun’s comment)
12. All the collections selected for ‘Offline OData entities’ during creation of a ‘kapsel offline’ project in webide have its information within Application constructor area in dev/devapp.js file.
13. There is always a room to modify CREATE/UPDATE UI by navigating to DetailEditMode.fragment.xml file
14. While modifying a record in the app on the android phone, keyboard doesn’t appear while tapping on Name, description, release date but when i tapped on Rating Field, it appeared and could able to modify other inputs as well.
15. Defining requests are key to loading the data you need on your device.
16. Application configure initialization (.ini) file has two main sections:
-
- End point configuration : determines how backend system (OData producer) should be processed by HCPms to retrieve and store the offline data, how offline DB can be prepopulated before its downloaded to client, indexing …
[endpoint]
name=YourConnectionName
prepopulate_offline_db=Y|N|SHARED-ONLY
prepopulate_offline_db_interval=NNN
indexed_type=<namespace>.<entity type name1>: Property1A [ASC|DESC][, Property1B [ASC|DESC], …]
indexed_type=<namespace>.<entity type name2>: Property2A [ASC|DESC][, Property2B [ASC|DESC], …]
request_format=application/json;q=1,application/atom+xml;q=0.5
delta_request_format=application/atom+xml
offline_db_collation=UTF8BIN
case_sensitive_offline_db=Y|N
-
-
- default interval for prepopulate offline DB is 1440 mins (1 day)
- To find ‘namespace’ value for indexed_type, look into OData service metadata document
-
-
- Defining requests configuration : define various characteristics of how the retrieved data for a given endpoint is managed by HCPms: data sharing, delta tracking, refresh interval,
[defining_request]
name=DefiningRequestName
is_shared_data=N|Y
refresh_interval=NNN
track_deltas=AUTO|ALWAYS|NEVER
delta_token_lifetime=NNN
-
-
- Default value for ‘refresh_interval’ : 15 mins
- Default value for ‘delta_token_lifetime’: 72000 mins (50 days)
- Use this .ini file only if you dont want default behavior.
-
17. On SAP Gateway, delta only supports passing the data back as xml when it comes to delta requests.
18. Never use $top & $skip in defining requests
19. You can have multiple offline stores in a single application, for best practice there should be one offline store per service (OData end point URL). Check here for Additional Best practices
20. Flush and Refresh activities are not performed automatically, application must explicitly call the relevant Harmonized API methods to perform these tasks.
21. Offline store supports deep insert but with limitation. Navigation property used for the deep insert must be refer to at most one entity not to a set of entities.
22. By default, an OData offline store doesn’t encrypt the data it collects and stores on the device. How to enable it then?
23. Change ‘Offline’ Log level settings to DEBUG for more troubleshooting
Open HCPms cockpit > Logs >Log settings
Access the application, check logs under ‘Logs and Traces’ tab:
24. The offline store has a 16 GB limit.
25. For an offline app it is important that the URI’s are routed through HCPms.
26. Offline OData plugin doesn’t support Android Intel Atom emulators, use ARM one.
27. in Mobile SDK SP10, maximum of 4 offline stores can be opened at the same time.
For every other and all info check Getting Started with Kapsel – Part 10 — Offline OData (SP09+)
You can ask your queries in discussion section of this course.
For more info,follow
SMP and HCPms: SMP Developer Center
SAP Web IDE, SAP HAT : SAPUI5 Developer Center
SAP HCP : SAP HANA Cloud Platform Developer Center
SAP HANA Cloud portal: SAP HANA Cloud Portal
Week 1: SAP Mobile strategy -openSAP-Developing mobile apps with HCP-Week 1
Week 2: SAP Web IDE deep dive-openSAP-Developing mobile apps with HCP-Week 2
Week 3: Its all about SAP Fiori Client -openSAP-Developing mobile apps with HCP-Week 3
Week 4: #HCPms helps you in mobilizing Fiori Apps -openSAP-Developing mobile apps with HCP-Week 4
Week 6: Secure your mobile-openSAP-Developing mobile apps with HCP-Week 6
Hello
Jeff Gebo's Profile | SCN
Jitendra Kansal
Point #7 and #8
If we define etags and delta in backend can offline HCP template automatically create relevant code or code has to be written to take care of this.
Regards
Manish
Hello Manish,
I dont think you will get everything in code generated files/folders(within project) from web ide template (kapsel offline).
For ETags,
if OData producer supports it, then during Flush/Refresh, you have to send its value (retrieved during GET request in downloading the data) in a header section (yes, coding required). If there is a conflict/match then you will an error/success message, its upto you how you will handle it. (coding required)
For Delta queries:
If Delta is enabled, after making a GET call, you will see below link at the end of the document
<link rel="delta" href=”https://server:port.../TheBigCollection?!deltatoken=2015-09-10 20:47:29"/>
next time when you make a REFRESH call, you have to call this link. (no coding required)
Regards,
JK
hello jitendra Kansal ,
I need deploy the Offline application for 1000 users.
So I can deploy the Offline application ?How can manage my app with Hcp ?
Thanks & Regard
Hello,
I try to develop a mobile App (with offline option) to approve Travel Expenses.
We used to use Function Import to validate or rejet a workitem.
Is it possible to use this kind of function for this kind off application ?
Thanks & regard
Hi,
I have created an offline Kapsel app with read write OData service and deployed and run the same on Android emulator. The app is rendering fine. Now i am adding one record and its getting saved successfully. After saving when i am refreshing the app, getting below error:
Could you please help me out why this error is coming when refreshing?
Regards
Subodh
Hi Subodh,
Unless you are asking for clarification/correction of some part of the Document, please create a new Discussion marked as a Question. The Comments section of a Blog (or Document) is not the right vehicle for asking questions as the results are not easily searchable. Once your issue is solved, a Discussion with the solution (and marked with Correct Answer) makes the results visible to others experiencing a similar problem. If a blog or document is related, put in a link. Read the Getting Started documents (link at the top right) including the Rules of Engagement.
NOTE: Getting the link is easy enough for both the author and Blog. Simply MouseOver the item, Right Click, and select Copy Shortcut. Paste it into your Discussion. You can also click on the url after pasting. Click on the A to expand the options and select T (on the right) to Auto-Title the url.
Thanks, Mike (Moderator)
SAP Technology RIG
Hi Jitendra,
Could you please check the URL Best approach to build an offline store for collections with $expand and delta queries? It's broken. Thanks!
Regards,
Shilpi
Shilpi Agarwal Its working for me (atleast now), please check