Exemple #1
0
 @GET
 @Produces("application/json")
 @Path(value = "startDownloads")
 public String startDownloads(@QueryParam("pkgList") String pkgList) {
   if (RequestHelper.isInternalLink(getContext())) {
     if (pkgList != null) {
       String[] pkgs = pkgList.split("/");
       PackageManager pm = Framework.getLocalService(PackageManager.class);
       try {
         log.info("Starting download for packages " + Arrays.toString(pkgs));
         pm.download(Arrays.asList(pkgs));
       } catch (ConnectServerError e) {
         log.error(e, e);
       }
       // here we generate a fake progress report so that if some
       // download are very fast, they will still be visible on the
       // client side
       StringBuffer sb = new StringBuffer();
       sb.append("[");
       for (int i = 0; i < pkgs.length; i++) {
         if (i > 0) {
           sb.append(",");
         }
         sb.append("{ \"pkgid\" : ");
         sb.append("\"" + pkgs[i] + "\",");
         sb.append(" \"progress\" : 0}");
       }
       sb.append("]");
       return sb.toString();
     }
   }
   return "[]";
 }
Exemple #2
0
 /** @since 5.6 */
 @GET
 @Path(value = "cancel/{pkgId}")
 public Object cancelDownload(
     @PathParam("pkgId") String pkgId, @QueryParam("source") String source) {
   PackageManager pm = Framework.getLocalService(PackageManager.class);
   pm.cancelDownload(pkgId);
   return redirect(getPrevious().getPath() + "/packages/" + source);
 }
Exemple #3
0
 @GET
 @Produces("text/html")
 @Path(value = "start/{pkgId}")
 public Object startDownload(
     @PathParam("pkgId") String pkgId,
     @QueryParam("source") String source,
     @QueryParam("install") Boolean install,
     @QueryParam("depCheck") Boolean depCheck,
     @QueryParam("type") String pkgType,
     @QueryParam("onlyRemote") Boolean onlyRemote,
     @QueryParam("filterOnPlatform") Boolean filterOnPlatform) {
   PackageManager pm = Framework.getLocalService(PackageManager.class);
   // flag to start install after download
   if (install == null) {
     install = false;
   }
   if (depCheck == null) {
     depCheck = true;
   }
   if (!RequestHelper.isInternalLink(getContext())) {
     DownloadablePackage pkg = pm.getPackage(pkgId);
     return getView("confirmDownload").arg("pkg", pkg).arg("source", source);
   }
   try {
     pm.download(pkgId);
   } catch (ConnectServerError e) {
     return getView("downloadError").arg("e", e);
   }
   return getView("downloadStarted")
       .arg("pkg", getDownloadingPackage(pkgId))
       .arg("source", source)
       .arg("over", false)
       .arg("install", install)
       .arg("depCheck", depCheck)
       .arg("filterOnPlatform", filterOnPlatform.toString())
       .arg("type", pkgType.toString())
       .arg("onlyRemote", onlyRemote.toString());
 }
Exemple #4
0
 @GET
 @Produces("text/html")
 @Path(value = "progressPage/{pkgId}")
 public Object getDownloadProgressPage(
     @PathParam("pkgId") String pkgId,
     @QueryParam("source") String source,
     @QueryParam("install") Boolean install,
     @QueryParam("depCheck") Boolean depCheck,
     @QueryParam("type") String pkgType,
     @QueryParam("onlyRemote") Boolean onlyRemote,
     @QueryParam("filterOnPlatform") Boolean filterOnPlatform) {
   DownloadablePackage pkg = getDownloadingPackage(pkgId);
   boolean downloadOver = false;
   // flag to start install after download
   if (install == null) {
     install = false;
   }
   if (depCheck == null) {
     depCheck = true;
   }
   if (pkg == null) {
     PackageManager pm = Framework.getLocalService(PackageManager.class);
     pkg = pm.getPackage(pkgId);
     if (pkg.getPackageState() != PackageState.DOWNLOADING) {
       downloadOver = true;
     }
   }
   return getView("downloadStarted")
       .arg("pkg", pkg)
       .arg("source", source)
       .arg("over", downloadOver)
       .arg("install", install)
       .arg("depCheck", depCheck)
       .arg("filterOnPlatform", filterOnPlatform.toString())
       .arg("type", pkgType.toString())
       .arg("onlyRemote", onlyRemote.toString());
 }