public int compare(UserAuthorityGroup ur0, UserAuthorityGroup ur1) {
    if (ur0 == null) {
      return 1;
    }

    if (ur1 == null) {
      return -1;
    }

    return ur0.getName().compareTo(ur1.getName());
  }
Exemple #2
0
  /**
   * Creates a table with the given validation rule
   *
   * @param user The User
   * @param i18n i18n object
   * @param format I18nFormat object
   * @param keepTogether Indicates whether the table could be broken across multiple pages or should
   *     be kept at one page.
   * @param columnWidths The column widths.
   */
  public static PdfPTable printUser(
      UserCredentials userCredentials,
      I18n i18n,
      I18nFormat format,
      boolean keepTogether,
      float... columnWidths) {
    User user = userCredentials.getUser();

    PdfPTable table = getPdfPTable(keepTogether, columnWidths);

    table.addCell(getHeaderCell(user.getFirstName() + ", " + user.getSurname(), 2));

    table.addCell(getEmptyCell(2, 15));

    table.addCell(getItalicCell(i18n.getString("username")));
    table.addCell(getTextCell(userCredentials.getUsername()));

    if (nullIfEmpty(user.getEmail()) != null) {
      table.addCell(getItalicCell(i18n.getString("email")));
      table.addCell(getTextCell(user.getEmail()));
    }

    if (nullIfEmpty(user.getPhoneNumber()) != null) {
      table.addCell(getItalicCell(i18n.getString("phone_number")));
      table.addCell(getTextCell(user.getPhoneNumber()));
    }

    table.addCell(getItalicCell(i18n.getString("last_login")));
    table.addCell(
        getTextCell(
            userCredentials.getLastLogin() != null
                ? format.formatDate(userCredentials.getLastLogin())
                : EMPTY));

    String temp = "";

    for (OrganisationUnit unit : user.getOrganisationUnits()) {
      temp += unit.getName().concat(", ");
    }

    temp = temp.trim();
    temp = temp.substring(0, temp.isEmpty() ? 0 : temp.length() - 1);

    table.addCell(getItalicCell(i18n.getString("organisation_units")));
    table.addCell(getTextCell(temp));

    temp = "";

    for (UserAuthorityGroup role : userCredentials.getUserAuthorityGroups()) {
      temp += role.getName().concat(", ");
    }

    temp = temp.trim();
    temp = temp.substring(0, temp.isEmpty() ? 0 : temp.length() - 1);

    table.addCell(getItalicCell(i18n.getString("roles")));
    table.addCell(getTextCell(temp));

    for (AttributeValue value : user.getAttributeValues()) {
      table.addCell(getItalicCell(value.getAttribute().getName()));
      table.addCell(getTextCell(value.getValue()));
    }

    table.addCell(getEmptyCell(2, 30));

    return table;
  }