Writing the Logic to Initiate Download Requests
Your mobile application should include logic to download backend data from the server to the mobile device. This logic is needed to accomplish the following:
Populate the mobile device’s local database with data when the mobile application receives a response for the download request.
Overwrite the mobile device’s local data with backend data from the server when needed in the following situations:
When you specify or change filters to download a subset of data
When you receive a “success” status from the server (status code
40) indicating that the download request was processed successfully
When the device’s data becomes corrupted
Include the following:
If you want to define a filter that specifies a subset of data to download from the backend application (for example, to reduce the amount of data synchronized over a cellular network or to restrict downloaded data to a particular project), invoke the
add method from the
com.softwareag.mobile.data.sync.Filter class. Keep the following points in mind:
Invoke the
add method once for each filter key that the business integration developer specifies in the corresponding mobile sync component.
If a particular filter key is defined in the mobile sync component and you do not want that key to be applied, set the value for the key to null.
If you pass more than one filter key,
Mobile Support returns a record to the mobile application only if the record matches all of the specified filter keys.
You can specify multiple values for a filter key. If you do so,
Mobile Support returns records that match any of the values.
If you change a filter’s key or values later, you must invoke the
download method from the
com.softwareag.mobile.data.sync.DataSynchronization class, as described later in this procedure, to download data that meets the revised filter criteria.
You can invoke the
getKeys method in the
com.softwareag.mobile.data.sync.Filter class to see a list of filter keys you previously added. To see the values that are set for a specified filter key, invoke the
get method. To see the number of filter key/value pairs defined, invoke the
size method.
Invoke the
download method from the
com.softwareag.mobile.data.sync.DataSynchronization class. This method passes the following parameters:
Mobile sync component alias. Obtain this alias from the business integration developer who created the mobile sync component.
Filter. If you used the
add method as described previously to define a filter, pass the filter instance to the
download method.
If you did not define a filter using the add method, set the filter instance to null.
The
com.softwareag.mobile.data.sync.ResponseSet class encapsulates the response from the synchronization request. The response includes records from the server (filtered, if a filter was supplied with the request). Use the
getRowStructures and
getStatus methods in this class to process the response further.
Mobile Support returns the following status codes:
Status Code | Meaning |
30 | An error occurred in the configuration or state of the mobile sync component associated with the mobile application. To resolve this error, work with the server administrator to ensure that the association between the mobile application version and the mobile sync component is valid and that the mobile sync component is enabled. If appropriate for your business need, have the mobile application provide the user with feedback about the error and instructions for resubmitting the data. |
31 | The mobile application passed a filter with the request, and a filter validation error occurred. To resolve this error, ensure that the mobile application passes the expected number of filter keys and that the filter key names match those specified in the mobile sync component’s filter definition. |
40 | Mobile Support processed the synchronization request successfully. Clear the data corresponding to the mobile sync component from the mobile device’s local database. Then, process the response set to write the new data received from the server to the local database. Including this logic in the application helps prevent data inconsistencies by providing the application with a fresh set of records. Note: Clear and refresh the mobile device’s local database only when the server returns a status code of 40. |
50 | Mobile Support encountered an internal error while processing the synchronization request. Work with the server administrator to resolve this error. If appropriate for your business need, have the mobile application provide the user with feedback about the error and instructions for resubmitting the data. |
Include logic to handle user interface messages based on the status messages received from
Mobile Support.
Important:
If a mobile application user changes data on the device and then performs a “download” action (instead of a “sync” action), the user’s local changes will be lost when Mobile Support returns data from the backend application to the device.
Invoke any of the other methods in the
Mobile Support Client library as needed for your business needs. For details on these methods, see
webMethods Mobile Support Client Java API Reference.