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) {
;
}
}
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();
}
}
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));
}
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);
}
}
});
}
}
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");
}
Aggregations