@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 "[]"; }
@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()); }