Пример #1
0
  private AppFileEntity allocateAppFile(AllocateWebPackageRequest req) throws IOException {
    AppFileEntity appFile = new AppFileEntity();
    String token = UUID.randomUUID().toString();

    appFile.setAppId(req.getAppId());
    appFile.setAppVersion(req.getAppVersion());
    appFile.setLocalPath(
        new File(configManager.getLocalRepositoryBaseDir(), token).getCanonicalPath());
    appFile.setMd5(req.getMd5());
    appFile.setToken(token);
    appFile.setDownloadUrl(configManager.getRepositoryDownloadUrl(token));
    appFile.setUploadUrl(configManager.getRepositoryUploadUrl(token));
    appFile.setBackupStatus(PkgBackUpStatus.NOT_BACKUPED.getCode());
    appFile.setCreationDate(new Date());

    return appFile;
  }
Пример #2
0
  public AllocateWebPackageResponse allocate(AllocateWebPackageRequest request) {

    AllocateWebPackageResponse response = new AllocateWebPackageResponse();

    try {
      logger.info(String.format("begin allocate WebPackage: %s", request));

      AppFileEntity appFile = allocateAppFile(request);
      appFileDal.insert(appFile);

      String repositoryUploadUrl = WebPackageUtil.generateUploadUrl(appFile.getToken());
      response.setUploadUrl(repositoryUploadUrl);
      response.success();
    } catch (Exception e) {
      response.fail(e.toString());
      logger.error(String.format("error when allocate WebPackage: %s", request), e);
    }

    logger.info(String.format("end allocate WebPackage: %s", response));

    return response;
  }
Пример #3
0
  private void saveOrUpdateAppVersion(String token) {
    AppFileEntity appFile = appFileDal.findAppFileByToken(token);

    AppVersionEntity appVersion = new AppVersionEntity();
    appVersion.setAppId(appFile.getAppId());
    appVersion.setVersion(appFile.getAppVersion());
    appVersion.setAppFileId(appFile.getId());

    AppVersionEntity oldVersion =
        appVersionDal.findByAppIdAndVersion(appFile.getAppId(), appFile.getAppVersion());

    if (oldVersion == null) {
      appVersion.setCreationDate(new Date());
      appVersion.setLastModifiedDate(new Date());
      appVersionDal.insert(appVersion);
    } else {
      appVersion.setId(oldVersion.getId());
      appVersion.setLastModifiedDate(new Date());
      appVersionDal.update(appVersion);
    }
  }