/** {@inheritDoc} */
  public List getResult(RequestContext context) {
    User user = context.getLoggedInUser();
    Channel chan =
        ChannelManager.lookupByIdAndUser(context.getRequiredParam(RequestContext.CID), user);

    return ChannelManager.listErrataNeedingResync(chan, user);
  }
Example #2
0
  private void setPageSize() {
    int tmp = -1;
    RequestContext rctx = new RequestContext((HttpServletRequest) pageContext.getRequest());
    User user = rctx.getLoggedInUser();
    if (user != null) {
      tmp = user.getPageSize();
      if (tmp > 0) {
        pageSize = tmp;
      }
    }
    if (pageSize < 1) {
      pageSize = 10;
    }

    HttpServletRequest httpRequest = (HttpServletRequest) pageContext.getRequest();

    if (PageSizeDecorator.pageWidgetSelected(httpRequest, getUniqueName())) {
      int size = PageSizeDecorator.getSelectedPageSize(httpRequest, getUniqueName());
      List<Integer> pageSizes = PageSizeDecorator.getPageSizes();
      if (size < 1 || size > pageSizes.get(pageSizes.size() - 1)) {
        return;
      } else {
        pageSize = size;
      }
    }
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext rc = new RequestContext(request);
    User user = rc.getLoggedInUser();

    Channel chan = ChannelManager.lookupByIdAndUser(rc.getRequiredParam(RequestContext.CID), user);

    try {
      ChannelManager.verifyChannelAdmin(user, chan.getId());
    } catch (InvalidChannelRoleException e) {
      addMessage(request, e.getMessage());
      return mapping.findForward("default");
    }

    ListRhnSetHelper helper =
        new ListRhnSetHelper(this, request, RhnSetDecl.ERRATA_TO_SYNC.createCustom(chan.getId()));

    helper.execute();
    if (helper.isDispatched()) {
      Map params = new HashMap();
      params.put(RequestContext.CID, chan.getId());
      return getStrutsDelegate().forwardParams(mapping.findForward("submit"), params);
    }

    request.setAttribute("channel_name", chan.getName());
    request.setAttribute(RequestContext.CID, chan.getId());
    return mapping.findForward("default");
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getLoggedInUser();
    DataList result = OrgManager.activeOrgs(user);

    request.setAttribute(ListTagHelper.PAGE_LIST, result);
    request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI());

    return mapping.findForward("default");
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

    StrutsDelegate strutsDelegate = getStrutsDelegate();

    ActionForward forward = null;
    DynaActionForm f = (DynaActionForm) form;
    RequestContext requestContext = new RequestContext(request);
    Long sid = requestContext.getRequiredParam("sid");
    User user = requestContext.getLoggedInUser();
    Server server = SystemManager.lookupByIdAndUser(sid, user);
    request.setAttribute("system", server);

    DynaActionForm dynaForm = (DynaActionForm) form;
    DatePicker picker =
        getStrutsDelegate()
            .prepopulateDatePicker(request, dynaForm, "date", DatePicker.YEAR_RANGE_POSITIVE);

    request.setAttribute("date", picker);

    if (!isSubmitted(f)) {
      setup(request, f);
      forward =
          strutsDelegate.forwardParams(mapping.findForward("default"), request.getParameterMap());
    } else {
      ActionMessages msgs = processForm(user, server, f, request);
      strutsDelegate.saveMessages(request, msgs);

      String mode = (String) f.get("mode");
      forward =
          strutsDelegate.forwardParams(
              mapping.findForward(getForward(mode)), request.getParameterMap());
    }

    return forward;
  }
  /** Custom Handler for HibernateLookupExceptions {@inheritDoc} */
  public ActionForward execute(
      Exception ex,
      ExceptionConfig exConfig,
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException {
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    request.setAttribute("error", ex);
    Logger log = Logger.getLogger(PermissionExceptionHandler.class);
    log.error("Permission Error", ex);

    TraceBackEvent evt = new TraceBackEvent();
    RequestContext requestContext = new RequestContext(request);
    User usr = requestContext.getLoggedInUser();
    evt.setUser(usr);
    evt.setRequest(request);
    evt.setException(ex);
    MessageQueue.publish(evt);

    return super.execute(ex, exConfig, mapping, form, request, response);
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);

    User user = requestContext.getLoggedInUser();
    String countStr = request.getParameter(SERVER_COUNT);
    Long count;
    if (countStr == null) {
      count = DEFAULT_COUNT;
      /**
       * Long sysPercent = new Long(UserManager.visibleSystemsAsDto(user).size()/10);
       *
       * <p>for (Long l : preSetCounts) { if (l.longValue() < sysPercent.longValue()) { count = l; }
       * } if (count == null) { count = 500L; } *
       */
    } else {
      count = Long.parseLong(countStr);
    }

    List<Map> preSetList = new ArrayList<Map>();
    for (Long l : preSetCounts) {
      Map countMap = new HashMap();
      countMap.put("count", l);
      countMap.put("selected", l.equals(count));
      preSetList.add(countMap);
    }

    request.setAttribute("count", count); // passing to get dataresult
    request.setAttribute(COUNTS, preSetList);
    request.setAttribute(SERVER_COUNT, count);
    return super.execute(mapping, formIn, request, response);
  }
Example #8
0
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

    if (CertificateManager.getInstance().isSatelliteCertExpired()) {
      addMessage(request, "satellite.expired");
      request.setAttribute(LoginSetupAction.HAS_EXPIRED, new Boolean(true));
      return mapping.findForward("failure");
    }

    ActionForward ret = null;
    DynaActionForm f = (DynaActionForm) form;

    // Validate the form
    ActionErrors errors = RhnValidationHelper.validateDynaActionForm(this, f);
    if (!errors.isEmpty()) {
      performGracePeriodCheck(request);
      addErrors(request, errors);
      return mapping.findForward("failure");
    }
    String username = (String) f.get("username");
    String password = (String) f.get("password");
    String urlBounce = (String) f.get("url_bounce");

    ActionErrors e = new ActionErrors();
    User user = loginUser(username, password, request, response, e);
    RequestContext ctx = new RequestContext(request);

    if (e.isEmpty()) {
      if (urlBounce == null || urlBounce.trim().equals("")) {
        if (log.isDebugEnabled()) {
          log.debug("2 - url bounce is empty using [" + DEFAULT_URL_BOUNCE + "]");
        }
        urlBounce = DEFAULT_URL_BOUNCE;
      }
      if (urlBounce.trim().endsWith("Logout.do")) {
        if (log.isDebugEnabled()) {
          log.debug(" - handling special case of url_bounce=Logout.do");
        }
        urlBounce = DEFAULT_URL_BOUNCE;
      }
      if (user != null) {
        try {
          publishUpdateErrataCacheEvent(user.getOrg());
        } catch (ConstraintViolationException ex) {
          log.error(ex);
          User loggedInUser = ctx.getLoggedInUser();
          if (loggedInUser != null) {
            request.setAttribute("loggedInUser", loggedInUser.getLogin());
          }
          ret = mapping.findForward("error");
          return ret;
        }
      }

      if (log.isDebugEnabled()) {
        log.debug("5 - redirecting to [" + urlBounce + "]");
      }
      if (user != null) {
        pxtDelegate.updateWebUserId(request, response, user.getId());

        try {
          response.sendRedirect(urlBounce);
          return null;
        } catch (IOException ioe) {
          throw new RuntimeException("Exception while trying to redirect: " + ioe);
        }
      }
    } else {
      if (log.isDebugEnabled()) {
        log.debug("6 - forwarding to failure");
      }

      performGracePeriodCheck(request);

      addErrors(request, e);
      request.setAttribute("url_bounce", urlBounce);
      ret = mapping.findForward("failure");
    }
    if (log.isDebugEnabled()) {
      log.debug("7 - returning");
    }
    return ret;
  }
  /** {@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);
    }
  }