Search in sources :

Example 1 with UpdateHeader

use of com.openmeap.protocol.dto.UpdateHeader in project OpenMEAP by OpenMEAP.

the class JsApiCoreImpl method checkForUpdates.

public void checkForUpdates() {
    UpdateHeader updateHeader = null;
    WebServiceException err = null;
    try {
        try {
            updateHeader = updateHandler.checkForUpdate();
            webView.setUpdateHeader(updateHeader, err, activity.getStorage().getBytesFree());
        } catch (WebServiceException e) {
            webView.setUpdateHeader(null, e, activity.getStorage().getBytesFree());
        }
    } catch (LocalStorageException e) {
        ;
    }
}
Also used : WebServiceException(com.openmeap.protocol.WebServiceException) JsUpdateHeader(com.openmeap.protocol.json.JsUpdateHeader) UpdateHeader(com.openmeap.protocol.dto.UpdateHeader) LocalStorageException(com.openmeap.thinclient.LocalStorageException)

Example 2 with UpdateHeader

use of com.openmeap.protocol.dto.UpdateHeader in project OpenMEAP by OpenMEAP.

the class UpdateHandler method _handleUpdate.

private void _handleUpdate(UpdateStatus update, StatusChangeHandler eventHandler) throws UpdateException {
    String lastUpdateResult = config.getLastUpdateResult();
    boolean hasTimedOut = hasUpdatePendingTimedOut();
    if (!hasTimedOut && lastUpdateResult != null && lastUpdateResult.compareTo(UpdateResult.PENDING.toString()) == 0) {
        return;
    } else {
        config.setLastUpdateResult(UpdateResult.PENDING.toString());
    }
    UpdateHeader updateHeader = update.getUpdateHeader();
    // if the new version is the original version,
    // then we'll just update the app version, delete internal storage and
    // return
    String versionId = updateHeader.getVersionIdentifier();
    if (config.isVersionOriginal(versionId).booleanValue()) {
        _revertToOriginal(update, eventHandler);
        return;
    }
    if (!deviceHasEnoughSpace(update).booleanValue()) {
        // behavior. default behavior should be informative
        throw new UpdateException(UpdateResult.OUT_OF_SPACE, "Need more space to install than is available");
    }
    try {
        // behavior. default behavior should be informative
        if (!downloadToArchive(update, eventHandler).booleanValue()) {
            return;
        }
    } catch (Exception ioe) {
        // behavior. default behavior should be informative
        throw new UpdateException(UpdateResult.IO_EXCEPTION, "An issue occurred downloading the archive", ioe);
    }
    if (!archiveIsValid(update).booleanValue()) {
        throw new UpdateException(UpdateResult.HASH_MISMATCH, "The import archive integrity check failed");
    }
    installArchive(update);
    // at this point, the archive should be of no use to us
    try {
        storage.deleteImportArchive();
    } catch (LocalStorageException lse) {
        throw new UpdateException(UpdateResult.IO_EXCEPTION, "Could not delete import archive", lse);
    }
    try {
        storage.resetStorage();
    } catch (LocalStorageException lse) {
        throw new UpdateException(UpdateResult.IO_EXCEPTION, "Could not reset storage", lse);
    }
    config.setLastUpdateResult(UpdateResult.SUCCESS.toString());
    config.setApplicationVersion(update.getUpdateHeader().getVersionIdentifier());
    config.setArchiveHash(update.getUpdateHeader().getHash().getValue());
    String newPrefix = storage.getStorageRoot() + update.getUpdateHeader().getHash().getValue();
    config.setStorageLocation(newPrefix);
    config.setApplicationUpdated(Boolean.TRUE);
    if (eventHandler != null) {
        update.setComplete(true);
        eventHandler.onStatusChange(update);
    } else {
        activity.restart();
    }
}
Also used : UpdateHeader(com.openmeap.protocol.dto.UpdateHeader) LocalStorageException(com.openmeap.thinclient.LocalStorageException) LocalStorageException(com.openmeap.thinclient.LocalStorageException) WebServiceException(com.openmeap.protocol.WebServiceException) GenericRuntimeException(com.openmeap.util.GenericRuntimeException) IOException(java.io.IOException) HttpRequestException(com.openmeap.http.HttpRequestException)

Example 3 with UpdateHeader

use of com.openmeap.protocol.dto.UpdateHeader in project OpenMEAP by OpenMEAP.

the class AdminTest method testCreateDeployments.

public void testCreateDeployments() throws Exception {
    Result result = null;
    ApplicationVersion version1 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_01);
    ApplicationVersion version2 = modelManager.getModelService().findAppVersionByNameAndId(APP_NAME, VERSION_02);
    UpdateHeader update = null;
    _createDeployment(VERSION_01, Deployment.Type.IMMEDIATE);
    modelManager.getModelService().clearPersistenceContext();
    Application app = modelManager.getModelService().findApplicationByName(APP_NAME);
    Assert.assertTrue(app.getDeployments().size() == 1);
    result = helper.getConnectionOpen(version2, SLIC_VERSION);
    update = result.getConnectionOpenResponse().getUpdate();
    Assert.assertTrue(update.getType().value().equals(Deployment.Type.IMMEDIATE.name()));
    Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_01));
    Assert.assertTrue(update.getHash().getValue().equals(VERSION_01_HASH));
    Assert.assertTrue(update.getStorageNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH));
    Assert.assertTrue(update.getInstallNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH + VERSION_01_BYTES_LENGTH));
    _createDeployment(VERSION_02, Deployment.Type.REQUIRED);
    modelManager.getModelService().clearPersistenceContext();
    app = modelManager.getModelService().findApplicationByName(APP_NAME);
    Assert.assertTrue(app.getDeployments().size() == 2);
    result = helper.getConnectionOpen(version1, SLIC_VERSION);
    update = result.getConnectionOpenResponse().getUpdate();
    Assert.assertTrue(update.getType().value().equals(Deployment.Type.REQUIRED.name()));
    Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_02));
    Assert.assertTrue(update.getHash().getValue().equals(VERSION_02_HASH));
    Assert.assertTrue(update.getStorageNeeds().equals(VERSION_02_UNCOMPRESSED_BYTES_LENGTH));
    Assert.assertTrue(update.getInstallNeeds().equals(VERSION_02_UNCOMPRESSED_BYTES_LENGTH + VERSION_02_BYTES_LENGTH));
    _createDeployment(VERSION_02, Deployment.Type.REQUIRED);
    Assert.assertTrue("as this deployment is created, the archive for version01 should be removed from the deployed location", !_isVersionArchiveInDeployedLocation(VERSION_01_HASH));
    _createDeployment(VERSION_01, Deployment.Type.IMMEDIATE);
    Assert.assertTrue("as this deployment is created, the archive for version01 should be in the deployed location", _isVersionArchiveInDeployedLocation(VERSION_01_HASH));
    result = helper.getConnectionOpen(version2, SLIC_VERSION);
    update = result.getConnectionOpenResponse().getUpdate();
    Assert.assertTrue(update.getType().value().equals(Deployment.Type.IMMEDIATE.name()));
    Assert.assertTrue(update.getVersionIdentifier().equals(VERSION_01));
    Assert.assertTrue(update.getHash().getValue().equals(VERSION_01_HASH));
    Assert.assertTrue(update.getStorageNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH));
    Assert.assertTrue(update.getInstallNeeds().equals(VERSION_01_UNCOMPRESSED_BYTES_LENGTH + VERSION_01_BYTES_LENGTH));
    modelManager.getModelService().clearPersistenceContext();
    app = modelManager.getModelService().findApplicationByName(APP_NAME);
    Assert.assertTrue(app.getDeployments().size() == 2);
    Assert.assertTrue(app.getDeployments().get(0).getVersionIdentifier().equals(VERSION_02));
    Assert.assertTrue(app.getDeployments().get(1).getVersionIdentifier().equals(VERSION_01));
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) UpdateHeader(com.openmeap.protocol.dto.UpdateHeader) Application(com.openmeap.model.dto.Application) Result(com.openmeap.protocol.dto.Result)

Example 4 with UpdateHeader

use of com.openmeap.protocol.dto.UpdateHeader 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)

Example 5 with UpdateHeader

use of com.openmeap.protocol.dto.UpdateHeader in project OpenMEAP by OpenMEAP.

the class JsCoreImplHelperTest method testToJSON.

public void testToJSON() {
    ConnectionOpenResponse cor = new ConnectionOpenResponse();
    cor.setAuthToken("auth-token");
    cor.setUpdate(new UpdateHeader());
    UpdateHeader update = cor.getUpdate();
    update.setHash(new Hash());
    update.getHash().setValue("value");
    update.getHash().setAlgorithm(HashAlgorithm.MD5);
    update.setInstallNeeds(1000L);
    update.setStorageNeeds(2000L);
    update.setUpdateUrl("update-url");
    update.setVersionIdentifier("version-identifier");
}
Also used : UpdateHeader(com.openmeap.protocol.dto.UpdateHeader) ConnectionOpenResponse(com.openmeap.protocol.dto.ConnectionOpenResponse) Hash(com.openmeap.protocol.dto.Hash)

Aggregations

UpdateHeader (com.openmeap.protocol.dto.UpdateHeader)6 GenericRuntimeException (com.openmeap.util.GenericRuntimeException)3 Application (com.openmeap.model.dto.Application)2 WebServiceException (com.openmeap.protocol.WebServiceException)2 ConnectionOpenResponse (com.openmeap.protocol.dto.ConnectionOpenResponse)2 Hash (com.openmeap.protocol.dto.Hash)2 JsUpdateHeader (com.openmeap.protocol.json.JsUpdateHeader)2 LocalStorageException (com.openmeap.thinclient.LocalStorageException)2 DigestException (com.openmeap.digest.DigestException)1 HttpRequestException (com.openmeap.http.HttpRequestException)1 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)1 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)1 Deployment (com.openmeap.model.dto.Deployment)1 GlobalSettings (com.openmeap.model.dto.GlobalSettings)1 Result (com.openmeap.protocol.dto.Result)1 JsError (com.openmeap.protocol.json.JsError)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