示例#1
0
  public String execute() throws Exception {
    UserCredentials currentUserCredentials =
        currentUserService.getCurrentUser() != null
            ? currentUserService.getCurrentUser().getUserCredentials()
            : null;

    // ---------------------------------------------------------------------
    // Prepare values
    // ---------------------------------------------------------------------

    if (email != null && email.trim().length() == 0) {
      email = null;
    }

    if (rawPassword != null && rawPassword.trim().length() == 0) {
      rawPassword = null;
    }

    // ---------------------------------------------------------------------
    // Update userCredentials and user
    // ---------------------------------------------------------------------

    Collection<OrganisationUnit> units =
        selectionTreeManager.getReloadedSelectedOrganisationUnits();

    User user = userService.getUser(id);
    user.setSurname(surname);
    user.setFirstName(firstName);
    user.setEmail(email);
    user.setPhoneNumber(phoneNumber);
    user.updateOrganisationUnits(new HashSet<OrganisationUnit>(units));

    UserCredentials userCredentials = userService.getUserCredentials(user);

    Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<UserAuthorityGroup>();

    for (String id : selectedList) {
      UserAuthorityGroup group = userService.getUserAuthorityGroup(Integer.parseInt(id));

      if (currentUserCredentials != null && currentUserCredentials.canIssue(group)) {
        userAuthorityGroups.add(group);
      }
    }

    userCredentials.setUserAuthorityGroups(userAuthorityGroups);

    if (rawPassword != null) {
      userCredentials.setPassword(
          passwordManager.encodePassword(userCredentials.getUsername(), rawPassword));
    }

    if (jsonAttributeValues != null) {
      AttributeUtils.updateAttributeValuesFromJson(
          user.getAttributeValues(), jsonAttributeValues, attributeService);
    }

    userService.updateUserCredentials(userCredentials);
    userService.updateUser(user);

    if (currentUserService.getCurrentUser() == user) {
      selectionManager.setRootOrganisationUnits(units);
      selectionManager.setSelectedOrganisationUnits(units);

      selectionTreeManager.setRootOrganisationUnits(units);
      selectionTreeManager.setSelectedOrganisationUnits(units);
    }

    if (units.size() > 0) {
      selectionManager.setSelectedOrganisationUnits(units);
    }

    return SUCCESS;
  }
示例#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;
  }