/** {@inheritDoc} */
  protected void render(User user, PageControl pc, HttpServletRequest request) {
    LocalizationService ls = LocalizationService.getInstance();
    DataResult<SystemOverview> isdr = SystemManager.inactiveListSortbyCheckinTime(user, pc);
    String inactiveSystemCSSTable = null;
    if (!isdr.isEmpty()) {
      for (Iterator<SystemOverview> i = isdr.iterator(); i.hasNext(); ) {
        SystemOverview so = i.next();
        StringBuilder buffer = new StringBuilder();
        Long lastCheckin = so.getLastCheckinDaysAgo();
        if (lastCheckin.compareTo(new Long(1)) < 0) {
          buffer.append(lastCheckin * 24);
          buffer.append(' ');

          buffer.append(ls.getMessage("filter-form.jspf.hours"));
        } else if (lastCheckin.compareTo(new Long(7)) < 0) {
          buffer.append(so.getLastCheckinDaysAgo().longValue());
          buffer.append(' ');
          buffer.append(ls.getMessage("filter-form.jspf.days"));
        } else if (lastCheckin.compareTo(new Long(7)) >= 0) {
          buffer.append(lastCheckin.longValue() / 7);
          buffer.append(' ');
          buffer.append(ls.getMessage("filter-form.jspf.weeks"));
        }

        so.setLastCheckinString(buffer.toString());
      }
      request.setAttribute(INACTIVE_SYSTEM_LIST, isdr);
    } else {
      inactiveSystemCSSTable =
          RendererHelper.makeEmptyTable(
              true, "inactivelist.jsp.header", "yourrhn.jsp.noinactivesystems");
      request.setAttribute(INACTIVE_SYSTEMS_EMPTY, inactiveSystemCSSTable);
    }
    RendererHelper.setTableStyle(request, INACTIVE_SYSTEMS_CLASS);
  }
 /** @return returns the localized system count */
 public String getSystemCountString() {
   LocalizationService service = LocalizationService.getInstance();
   Integer count = getSystemCount();
   final Integer one = new Integer(1);
   if (one.equals(count)) {
     return service.getMessage("system.common.onesystem");
   }
   if (count == null) {
     count = new Integer(0);
   }
   return service.getMessage("system.common.numsystems", new Object[] {count});
 }
Esempio n. 3
0
 /**
  * Util method to return the page size in a accessible way.
  *
  * @param totalSize the total size of page
  * @param descriptionKey the message key for description
  * @return the appropriate pagination message.
  */
 protected String makePaginationMessage(int end, int totalSize, String descriptionKey) {
   LocalizationService ls = LocalizationService.getInstance();
   int start = 0;
   if (totalSize > 0) {
     start = 1;
   }
   if (StringUtils.isBlank(descriptionKey)) {
     return ls.getMessage("message.range", start, end, totalSize);
   }
   return ls.getMessage(
       "message.range.withtypedescription", start, end, totalSize, ls.getMessage(descriptionKey));
 }
Esempio n. 4
0
  /**
   * set the Locale for this thread
   *
   * @param localeIn Locale for this thread.
   */
  public void setLocale(Locale localeIn) {
    this.locale = localeIn;
    LocalizationService ls = LocalizationService.getInstance();

    if (ls.hasMessage("preferences.jsp.lang." + localeIn.toString())) {
      activeLocaleLabel = ls.getMessage("preferences.jsp.lang." + localeIn.toString(), localeIn);
    } else {
      // default to en_US
      // the localeIn will be default to en_US if the LS doesn't
      // find a supported bundle, so we're safe there.
      activeLocaleLabel = ls.getMessage("preferences.jsp.lang.en_US", localeIn);
    }
  }
Esempio n. 5
0
  private void setupManipulator() throws JspException {
    manip.setAlphaColumn(alphaBarColumn);
    manip.filter(filter, pageContext);
    if (!StringUtils.isBlank(ListTagHelper.getFilterValue(pageContext.getRequest(), uniqueName))) {
      LocalizationService ls = LocalizationService.getInstance();

      ListTagUtil.write(pageContext, "<div class=\"site-info\">");

      if (manip.getTotalDataSetSize() != manip.getUnfilteredDataSize()) {
        if (manip.getAllData().size() == 0) {
          ListTagUtil.write(
              pageContext,
              ls.getMessage(
                  "listtag.filteredmessageempty", new Integer(manip.getTotalDataSetSize())));
        } else {
          ListTagUtil.write(
              pageContext,
              ls.getMessage("listtag.filteredmessage", new Integer(manip.getTotalDataSetSize())));
        }

        ListTagUtil.write(pageContext, "<br /><a href=\"");
        List<String> excludeParams = new ArrayList<String>();
        excludeParams.add(ListTagUtil.makeSelectActionName(getUniqueName()));
        excludeParams.add(ListTagUtil.makeFilterByLabel(getUniqueName()));
        excludeParams.add(ListTagUtil.makeFilterValueByLabel(getUniqueName()));
        excludeParams.add(ListTagUtil.makeOldFilterValueByLabel(getUniqueName()));
        excludeParams.add(ListTagUtil.makeFilterSearchChildLabel(getUniqueName()));
        excludeParams.add(ListTagUtil.makeFilterSearchParentLabel(getUniqueName()));
        excludeParams.add(ListTagUtil.makeParentIsAnElementLabel(getUniqueName()));

        ListTagUtil.write(
            pageContext,
            ListTagUtil.makeParamsLink(
                pageContext.getRequest(), name, Collections.EMPTY_MAP, excludeParams));

        ListTagUtil.write(pageContext, "\">" + ls.getMessage("listtag.clearfilter"));
        ListTagUtil.write(
            pageContext,
            ls.getMessage("listtag.seeall", new Integer(manip.getUnfilteredDataSize())));
        ListTagUtil.write(pageContext, "</a>");
      } else {
        ListTagUtil.write(
            pageContext,
            ls.getMessage(
                "listtag.all_items_in_filter",
                ListTagHelper.getFilterValue(pageContext.getRequest(), uniqueName)));
      }

      ListTagUtil.write(pageContext, "</div>");
    }
  }
 /** {@inheritDoc} */
 @Override
 public void beforeList() throws JspException {
   // <script src="/javascript/tree.js" type="text/javascript"></script>
   ListTagUtil.write(pageContext, IMPORT_TREE_JS);
   ListTagUtil.write(pageContext, String.format(NEW_VAR_SCRIPT, listName));
   LocalizationService ls = LocalizationService.getInstance();
   ListTagUtil.write(
       pageContext,
       String.format(
           SHOW_ALL_SCRIPT,
           listName,
           ls.getMessage("show.all"),
           listName,
           ls.getMessage("hide.all")));
 }
Esempio n. 7
0
  /**
   * convert combo box types to ErrataFactory types
   *
   * @param type the type from the combo box
   * @return a list of types to get
   */
  protected List<String> getTypes(String type) {
    List<String> typeList = new ArrayList<String>();
    LocalizationService ls = LocalizationService.getInstance();

    if (ls.getMessage(BUGFIX).equals(type)) {
      typeList.add(ErrataFactory.ERRATA_TYPE_BUG);
    } else if (ls.getMessage(SECUR).equals(type)) {
      typeList.add(ErrataFactory.ERRATA_TYPE_SECURITY);
    } else if (ls.getMessage(ENHANCE).equals(type)) {
      typeList.add(ErrataFactory.ERRATA_TYPE_ENHANCEMENT);
    } else if (ls.getMessage(NON_CRITICAL).equals(type)) {
      typeList.add(ErrataFactory.ERRATA_TYPE_BUG);
      typeList.add(ErrataFactory.ERRATA_TYPE_ENHANCEMENT);
    } else { // ALL
      typeList.add(ErrataFactory.ERRATA_TYPE_BUG);
      typeList.add(ErrataFactory.ERRATA_TYPE_ENHANCEMENT);
      typeList.add(ErrataFactory.ERRATA_TYPE_SECURITY);
    }
    return typeList;
  }
Esempio n. 8
0
  /**
   * Set up the filter combo
   *
   * @param request the request
   * @return the map for the combo
   */
  protected List<Map<String, Object>> getComboList(HttpServletRequest request) {

    String selected = request.getParameter(SELECTOR);

    List<Map<String, Object>> combo = new ArrayList<Map<String, Object>>();

    LocalizationService ls = LocalizationService.getInstance();

    Map<String, Object> tmp = new HashMap<String, Object>();
    tmp.put("name", ALL);
    tmp.put("id", ALL);
    tmp.put("default", ls.getMessage(ALL).equals(selected));

    Map<String, Object> tmp1 = new HashMap<String, Object>();
    tmp1.put("name", NON_CRITICAL);
    tmp1.put("id", NON_CRITICAL);
    tmp1.put("default", ls.getMessage(NON_CRITICAL).equals(selected));

    Map<String, Object> tmp2 = new HashMap<String, Object>();
    tmp2.put("name", BUGFIX);
    tmp2.put("id", BUGFIX);
    tmp2.put("default", ls.getMessage(BUGFIX).equals(selected));

    Map<String, Object> tmp3 = new HashMap<String, Object>();
    tmp3.put("name", ENHANCE);
    tmp3.put("id", ENHANCE);
    tmp3.put("default", ls.getMessage(ENHANCE).equals(selected));

    Map<String, Object> tmp4 = new HashMap<String, Object>();
    tmp4.put("name", SECUR);
    tmp4.put("id", SECUR);
    tmp4.put("default", ls.getMessage(SECUR).equals(selected));

    combo.add(tmp);
    combo.add(tmp1);
    combo.add(tmp2);
    combo.add(tmp3);
    combo.add(tmp4);
    return combo;
  }
Esempio n. 9
0
  private void prepDropdowns(RequestContext ctx) {
    User loggedInUser = ctx.getCurrentUser();
    // populate parent base channels
    List<Map<String, String>> baseChannels = new ArrayList<Map<String, String>>();
    List<Channel> bases = ChannelManager.findAllBaseChannelsForOrg(loggedInUser);

    LocalizationService ls = LocalizationService.getInstance();
    addOption(baseChannels, ls.getMessage("generic.jsp.none"), "");
    for (Channel c : bases) {
      addOption(baseChannels, c.getName(), c.getId().toString());
    }
    ctx.getRequest().setAttribute("parentChannels", baseChannels);

    Map<Long, String> parentChannelArches = new HashMap<Long, String>();
    for (Channel c : bases) {
      parentChannelArches.put(c.getId(), c.getChannelArch().getLabel());
    }
    ctx.getRequest().setAttribute("parentChannelArches", parentChannelArches);

    Map<Long, String> parentChannelChecksums = new HashMap<Long, String>();
    for (Channel c : bases) {
      parentChannelChecksums.put(c.getId(), c.getChecksumTypeLabel());
    }
    ctx.getRequest().setAttribute("parentChannelChecksums", parentChannelChecksums);

    // base channel arches
    List<Map<String, String>> channelArches = new ArrayList<Map<String, String>>();
    List<ChannelArch> arches = ChannelManager.getChannelArchitectures();
    for (ChannelArch arch : arches) {
      addOption(channelArches, arch.getName(), arch.getLabel());
    }
    ctx.getRequest().setAttribute("channelArches", channelArches);
    // set the list of yum supported checksums
    List<Map<String, String>> checksums = new ArrayList<Map<String, String>>();
    addOption(checksums, ls.getMessage("generic.jsp.none"), "");
    for (ChecksumType chType : ChannelFactory.listYumSupportedChecksums()) {
      addOption(checksums, chType.getLabel(), chType.getLabel());
    }
    ctx.getRequest().setAttribute("checksums", checksums);
  }
Esempio n. 10
0
  /**
   * Creates a new user
   *
   * @param loggedInUser The current user
   * @param desiredLogin The login for the new user
   * @param desiredPassword The password for the new user
   * @param firstName The first name of the new user
   * @param lastName The last name of the new user
   * @param email The email address for the new user
   * @param usePamAuth Should this user authenticate via PAM?
   * @return Returns 1 if successful (exception otherwise)
   * @throws FaultException A FaultException is thrown if the loggedInUser doesn't have permissions
   *     to create new users in thier org.
   * @xmlrpc.doc Create a new user.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param_desc("string", "desiredLogin", "Desired login name, will fail if already
   *     in use.")
   * @xmlrpc.param #param("string", "desiredPassword")
   * @xmlrpc.param #param("string", "firstName")
   * @xmlrpc.param #param("string", "lastName")
   * @xmlrpc.param #param_desc("string", "email", "User's e-mail address.")
   * @xmlrpc.param #param_desc("int", "usePamAuth", "1 if you wish to use PAM authentication for
   *     this user, 0 otherwise.")
   * @xmlrpc.returntype #return_int_success()
   */
  public int create(
      User loggedInUser,
      String desiredLogin,
      String desiredPassword,
      String firstName,
      String lastName,
      String email,
      Integer usePamAuth)
      throws FaultException {
    // Logged in user must be an org admin and we must be on a sat to do this.
    ensureOrgAdmin(loggedInUser);
    ensurePasswordOrPamAuth(usePamAuth, desiredPassword);

    boolean pamAuth = BooleanUtils.toBoolean(usePamAuth, new Integer(1), new Integer(0));

    if (pamAuth) {
      desiredPassword = getDefaultPasswordForPamAuth();
    }

    CreateUserCommand command = new CreateUserCommand();
    command.setUsePamAuthentication(pamAuth);
    command.setLogin(desiredLogin);
    command.setPassword(desiredPassword);
    command.setFirstNames(firstName);
    command.setLastName(lastName);
    command.setEmail(email);
    command.setOrg(loggedInUser.getOrg());
    command.setCompany(loggedInUser.getCompany());

    // Validate the user to be
    ValidatorError[] errors = command.validate();
    if (errors.length > 0) {
      StringBuilder errorString = new StringBuilder();
      LocalizationService ls = LocalizationService.getInstance();
      // Build a sane error message here
      for (int i = 0; i < errors.length; i++) {
        ValidatorError err = errors[i];
        errorString.append(ls.getMessage(err.getKey(), err.getValues()));
        if (i != errors.length - 1) {
          errorString.append(" :: ");
        }
      }
      // Throw a BadParameterException with our message string
      throw new BadParameterException(errorString.toString());
    }

    command.storeNewUser();
    return 1;
  }
Esempio n. 11
0
  /** {@inheritDoc} */
  public List getResult(RequestContext context) {
    User user = context.getCurrentUser();
    Long sid = context.getRequiredParam("sid");
    String type = context.getParam(SELECTOR, false);
    String synopsis = "";
    Boolean currency = false;

    LocalizationService ls = LocalizationService.getInstance();

    String eType = new String();

    if (ls.getMessage(SECUR_CRIT).equals(type)) {
      eType = ErrataFactory.ERRATA_TYPE_SECURITY;
      synopsis = "C";
      currency = true;
    } else if (ls.getMessage(SECUR_IMP).equals(type)) {
      eType = ErrataFactory.ERRATA_TYPE_SECURITY;
      synopsis = "I";
      currency = true;
    } else if (ls.getMessage(SECUR_MOD).equals(type)) {
      eType = ErrataFactory.ERRATA_TYPE_SECURITY;
      synopsis = "M";
      currency = true;
    } else if (ls.getMessage(SECUR_LOW).equals(type)) {
      eType = ErrataFactory.ERRATA_TYPE_SECURITY;
      synopsis = "L";
      currency = true;
    }

    if (currency) {
      return SystemManager.relevantCurrencyErrata(user, sid, eType, synopsis);
    }

    List<String> typeList = getTypes(type);
    return SystemManager.relevantErrata(user, sid, typeList);
  }
Esempio n. 12
0
  private void renderEmptyList() throws JspException {
    ListTagUtil.write(pageContext, "<tr class=\"list-row-odd\"><td ");
    ListTagUtil.write(pageContext, "class=\"first-column last-column\" ");
    ListTagUtil.write(pageContext, "colspan=\"");
    ListTagUtil.write(pageContext, String.valueOf(columnCount));
    ListTagUtil.write(pageContext, "\">");

    if (emptyKey != null) {
      LocalizationService ls = LocalizationService.getInstance();
      String msg = ls.getMessage(emptyKey);
      ListTagUtil.write(pageContext, "<div class=\"list-empty-message\">");
      ListTagUtil.write(pageContext, msg);
      ListTagUtil.write(pageContext, "<br /></div>");
    }

    ListTagUtil.write(pageContext, "</td></tr>");
  }
  public void testRender() throws Exception {
    RequiredFieldTag tag = new RequiredFieldTag();
    RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
    TagTestHelper tth = TagTestUtils.setupTagTest(tag, new URL("http://localhost"), request);
    tag.setPageContext(tth.getPageContext());
    String key = "getMessage";
    tag.setKey(key);
    // ok let's test the tag
    tth.assertDoStartTag(Tag.EVAL_BODY_INCLUDE);
    tth.assertDoEndTag(Tag.SKIP_BODY);

    RhnMockJspWriter rout = (RhnMockJspWriter) tth.getPageContext().getOut();
    assertTrue(rout.toString().indexOf("<span class") > -1);
    assertTrue(rout.toString().indexOf("</span>") > -1);
    assertTrue(rout.toString().indexOf("*") > -1);
    assertTrue(rout.toString().indexOf("\"" + RequiredFieldTag.REQUIRED_FIELD_CSS + "\"") > -1);
    LocalizationService ls = LocalizationService.getInstance();
    assertTrue(rout.toString().startsWith(ls.getMessage(key)));
  }