/** {@inheritDoc} */ public ActionForward execute( ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) { RequestContext requestContext = new RequestContext(request); User user = requestContext.getLoggedInUser(); // If this is an easy one and we have the pid if (request.getParameter("pid") != null) { long pid = requestContext.getRequiredParam("pid"); Package pkg = PackageFactory.lookupByIdAndUser(pid, user); // show permission error if pid is invalid like we did before if (pkg == null) { throw new PermissionException("Invalid pid"); } if (pkg instanceof Patch) { request.setAttribute("type", "patch"); request.setAttribute(PACKAGE_NAME, pkg.getPackageName().getName()); request.setAttribute( "readme_url", DownloadManager.getPatchReadmeDownloadPath((Patch) pkg, user)); } else if (pkg instanceof PatchSet) { request.setAttribute("type", "patchset"); request.setAttribute(PACKAGE_NAME, pkg.getNameEvra()); request.setAttribute( "readme_url", DownloadManager.getPatchSetReadmeDownloadPath((PatchSet) pkg, user)); } else { request.setAttribute("type", "rpm"); request.setAttribute(PACKAGE_NAME, pkg.getFilename()); if (!pkg.getPackageKeys().isEmpty()) { request.setAttribute(PACKAGE_KEY, pkg.getPackageKeys().iterator().next().getKey()); } boolean isDebug = pkg.getPackageName().getName().contains("debuginfo"); request.setAttribute("isDebuginfo", isDebug); if (!isDebug) { Package debugPkg = PackageManager.findDebugInfo(user, pkg); String ftpUrl = PackageManager.generateFtpDebugPath(pkg); if (debugPkg != null) { request.setAttribute( "debugUrl", DownloadManager.getPackageDownloadPath(debugPkg, user)); } else if (ftpUrl != null) { request.setAttribute("debugUrl", ftpUrl); request.setAttribute("debugFtp", true); } } } if (DownloadManager.isFileAvailable(pkg.getPath())) { request.setAttribute("url", DownloadManager.getPackageDownloadPath(pkg, user)); } List<PackageSource> src = PackageFactory.lookupPackageSources(pkg); if (!src.isEmpty() && DownloadManager.isFileAvailable(src.get(0).getPath())) { request.setAttribute( "srpm_url", DownloadManager.getPackageSourceDownloadPath(pkg, src.get(0), user)); request.setAttribute("srpm_path", src.get(0).getFile()); } request.setAttribute("pack", pkg); // description can be null. if (pkg.getDescription() != null) { request.setAttribute("description", pkg.getDescription().replace("\n", "<BR>\n")); } else { request.setAttribute("description", pkg.getDescription()); } request.setAttribute("packArches", PackageFactory.findPackagesWithDifferentArch(pkg)); request.setAttribute("pid", pid); return mapping.findForward("default"); } else { // we have to guess PackageListItem item = PackageListItem.parse(request.getParameter("id_combo")); Package pkg; long nameId = item.getIdOne(); long evrId = item.getIdTwo(); long archId = 0; if (item.getIdThree() != null) { archId = item.getIdThree(); } Long cid = requestContext.getParamAsLong("cid"); Long sid = requestContext.getParamAsLong("sid"); if (cid != null) { pkg = PackageManager.guestimatePackageByChannel(cid, nameId, evrId, user.getOrg()); } else if (sid != null) { pkg = PackageManager.guestimatePackageBySystem(sid, nameId, evrId, archId, user.getOrg()); } else { throw new BadParameterException("pid, cid, or sid"); } // show permission error if pid is invalid like we did before if (pkg == null) { throw new NoSuchPackageException(); } Map params = new HashMap(); params.put("pid", pkg.getId()); return getStrutsDelegate().forwardParams(mapping.findForward("package"), params); } }
private void setupForm(HttpServletRequest request, DynaActionForm form) { RequestContext ctx = new RequestContext(request); prepDropdowns(ctx); Long cid = ctx.getParamAsLong("cid"); if (cid != null) { Channel c = ChannelManager.lookupByIdAndUser(cid, ctx.getCurrentUser()); if (!UserManager.verifyChannelAdmin(ctx.getCurrentUser(), c)) { throw new PermissionException(RoleFactory.CHANNEL_ADMIN); } form.set("name", c.getName()); form.set("summary", c.getSummary()); form.set("description", c.getDescription()); form.set("org_sharing", c.getAccess()); form.set("gpg_key_url", c.getGPGKeyUrl()); form.set("gpg_key_id", c.getGPGKeyId()); form.set("gpg_key_fingerprint", c.getGPGKeyFp()); form.set("maintainer_name", c.getMaintainerName()); form.set("maintainer_phone", c.getMaintainerPhone()); form.set("maintainer_email", c.getMaintainerEmail()); form.set("support_policy", c.getSupportPolicy()); if (c.getChecksumTypeLabel() == null) { form.set("checksum", null); } else { form.set("checksum", c.getChecksumTypeLabel()); } if (c.isGloballySubscribable(ctx.getCurrentUser().getOrg())) { form.set("per_user_subscriptions", "all"); } else { form.set("per_user_subscriptions", "selected"); } if (c.getParentChannel() != null) { request.setAttribute("parent_name", c.getParentChannel().getName()); request.setAttribute("parent_id", c.getParentChannel().getId()); } else { request.setAttribute( "parent_name", LocalizationService.getInstance().getMessage("generic.jsp.none")); } if (c.getSources().isEmpty()) { request.setAttribute("last_sync", ""); } else { String lastSync = LocalizationService.getInstance().getMessage("channel.edit.repo.neversynced"); if (c.getLastSynced() != null) { lastSync = LocalizationService.getInstance().formatCustomDate(c.getLastSynced()); } request.setAttribute("last_sync", lastSync); if (!ChannelManager.getLatestSyncLogFiles(c).isEmpty()) { request.setAttribute( "log_url", DownloadManager.getChannelSyncLogDownloadPath(c, ctx.getCurrentUser())); } } request.setAttribute("channel_label", c.getLabel()); request.setAttribute("channel_name", c.getName()); request.setAttribute("channel_arch", c.getChannelArch().getName()); request.setAttribute("channel_arch_label", c.getChannelArch().getLabel()); } else { // default settings String channelName = LocalizationService.getInstance().getMessage("frontend.actions.channels.manager.create"); request.setAttribute("channel_name", channelName); form.set("org_sharing", "private"); form.set("per_user_subscriptions", "all"); form.set("checksum", "sha1"); } }