Search in sources :

Example 1 with UpdateStatus

use of com.openmeap.thinclient.update.UpdateStatus in project OpenMEAP by OpenMEAP.

the class JsApiCoreImpl method performUpdate.

/**
 * @param header JSON of the update header
 * @param statusCallBack a status change callback
 */
public void performUpdate(final String header, final String statusCallBack) {
    // needs to immediately return control to the calling javascript,
    // and pass back download status information via the callback function.
    JsUpdateHeader jsUpdateHeader = null;
    try {
        jsUpdateHeader = new JsUpdateHeader(header);
    } catch (JSONException e) {
        throw new GenericRuntimeException(e);
    }
    UpdateHeader reloadedHeader = jsUpdateHeader.getWrappedObject();
    if (reloadedHeader != null) {
        updateHandler.handleUpdate(reloadedHeader, new UpdateHandler.StatusChangeHandler() {

            public void onStatusChange(UpdateStatus update) {
                try {
                    JSONObject js = new JSONObject("{update:" + header + "}");
                    UpdateException error = update.getError();
                    js.put("bytesDownloaded", update.getBytesDownloaded());
                    js.put("complete", update.getComplete());
                    js.put("error", error != null ? new JsError(error.getUpdateResult().toString(), error.getMessage()).toJSONObject() : null);
                    webView.executeJavascriptFunction(statusCallBack, new String[] { js.toString() });
                } catch (JSONException e) {
                    throw new GenericRuntimeException(e);
                }
            }
        });
    }
}
Also used : UpdateHandler(com.openmeap.thinclient.update.UpdateHandler) UpdateStatus(com.openmeap.thinclient.update.UpdateStatus) JsError(com.openmeap.protocol.json.JsError) JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) JsUpdateHeader(com.openmeap.protocol.json.JsUpdateHeader) JSONException(com.openmeap.thirdparty.org.json.me.JSONException) JsUpdateHeader(com.openmeap.protocol.json.JsUpdateHeader) UpdateHeader(com.openmeap.protocol.dto.UpdateHeader) UpdateException(com.openmeap.thinclient.update.UpdateException) GenericRuntimeException(com.openmeap.util.GenericRuntimeException)

Aggregations

UpdateHeader (com.openmeap.protocol.dto.UpdateHeader)1 JsError (com.openmeap.protocol.json.JsError)1 JsUpdateHeader (com.openmeap.protocol.json.JsUpdateHeader)1 UpdateException (com.openmeap.thinclient.update.UpdateException)1 UpdateHandler (com.openmeap.thinclient.update.UpdateHandler)1 UpdateStatus (com.openmeap.thinclient.update.UpdateStatus)1 JSONException (com.openmeap.thirdparty.org.json.me.JSONException)1 JSONObject (com.openmeap.thirdparty.org.json.me.JSONObject)1 GenericRuntimeException (com.openmeap.util.GenericRuntimeException)1