Search in sources :

Example 6 with UpdateHeader

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

the class ApplicationManagementServiceImpl method connectionOpen.

public ConnectionOpenResponse connectionOpen(ConnectionOpenRequest request) throws WebServiceException {
    String reqAppArchHashVal = StringUtils.trimToNull(request.getApplication().getHashValue());
    String reqAppVerId = StringUtils.trimToNull(request.getApplication().getVersionId());
    String reqAppName = StringUtils.trimToNull(request.getApplication().getName());
    ConnectionOpenResponse response = new ConnectionOpenResponse();
    GlobalSettings settings = modelManager.getGlobalSettings();
    if (StringUtils.isBlank(settings.getExternalServiceUrlPrefix()) && logger.isWarnEnabled()) {
        logger.warn("The external service url prefix configured in the admin interface is blank.  " + "This will probably cause issues downloading application archives.");
    }
    Application application = getApplication(reqAppName, reqAppVerId);
    // Generate a new auth token for the device to present to the proxy
    String authToken;
    try {
        authToken = AuthTokenProvider.newAuthToken(application.getProxyAuthSalt());
    } catch (DigestException e) {
        throw new GenericRuntimeException(e);
    }
    response.setAuthToken(authToken);
    // If there is a deployment, 
    // and the version of that deployment differs in hash value or identifier
    // then return an update in the response
    Deployment lastDeployment = modelManager.getModelService().getLastDeployment(application);
    Boolean reqAppVerDiffers = lastDeployment != null && !lastDeployment.getVersionIdentifier().equals(reqAppVerId);
    Boolean reqAppArchHashValDiffers = lastDeployment != null && reqAppArchHashVal != null && !lastDeployment.getApplicationArchive().getHash().equals(reqAppArchHashVal);
    //   the app hash value is different than reported
    if (reqAppVerDiffers || reqAppArchHashValDiffers) {
        // TODO: I'm not happy with the discrepancies between the model and schema
        // ...besides, this update header should be encapsulated somewhere else
        ApplicationArchive currentVersionArchive = lastDeployment.getApplicationArchive();
        UpdateHeader uh = new UpdateHeader();
        uh.setVersionIdentifier(lastDeployment.getVersionIdentifier());
        uh.setInstallNeeds(Long.valueOf(currentVersionArchive.getBytesLength() + currentVersionArchive.getBytesLengthUncompressed()));
        uh.setStorageNeeds(Long.valueOf(currentVersionArchive.getBytesLengthUncompressed()));
        uh.setType(UpdateType.fromValue(lastDeployment.getType().toString()));
        uh.setUpdateUrl(currentVersionArchive.getDownloadUrl(settings));
        uh.setHash(new Hash());
        uh.getHash().setAlgorithm(HashAlgorithm.fromValue(currentVersionArchive.getHashAlgorithm()));
        uh.getHash().setValue(currentVersionArchive.getHash());
        response.setUpdate(uh);
    }
    return response;
}
Also used : DigestException(com.openmeap.digest.DigestException) Deployment(com.openmeap.model.dto.Deployment) UpdateHeader(com.openmeap.protocol.dto.UpdateHeader) GlobalSettings(com.openmeap.model.dto.GlobalSettings) ConnectionOpenResponse(com.openmeap.protocol.dto.ConnectionOpenResponse) GenericRuntimeException(com.openmeap.util.GenericRuntimeException) Hash(com.openmeap.protocol.dto.Hash) Application(com.openmeap.model.dto.Application) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive)

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