Class ImportUsers

All Implemented Interfaces:
LogEnabled, Component, Serviceable

public class ImportUsers extends AbstractLogEnabled implements Component, Serviceable
Import users from a CSV or text file.
  • Field Details

  • Constructor Details

  • Method Details

    • service

      public void service(ServiceManager smanager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • importUsers

      public Map<String,Object> importUsers(Part filePart, String populationId, String userDirectoryId, boolean cleanDirectory, boolean hashedPasswords) throws FileNotFoundException, InvalidModificationException
      Read a file from disk and add users inside in the requested population/directory
      Parameters:
      filePart - file
      populationId - population Id
      userDirectoryId - user directory
      cleanDirectory - true to clear every user that was not in the import file
      hashedPasswords - true if the passwords are already hashed in the file (salt must be in the file too, and password hashed with "saltPassword" with nothing in-between)
      Returns:
      a map containing success, addedCount, existingCount, errorCount, deletedCount, message success : true if success addedCount, existingCount, errorCount : number of imported user added, modified, an error occured (see server log) message : error message if something wrong happened (usually malformed file)
      Throws:
      FileNotFoundException - error reading the file
      InvalidModificationException - error modifying the directory
    • clearUserDirectory

      protected List<Map<String,String>> clearUserDirectory(String populationId, String userDirectoryId, List<UserIdentity> usersToSave) throws InvalidModificationException
      Remove all users in a userDirectory, avoiding those in usersToSave list
      Parameters:
      populationId - population Id
      userDirectoryId - directory Id
      usersToSave - list of users that need to be saved
      Returns:
      list of deleted users (containing login and populationId)
      Throws:
      InvalidModificationException - If modification is not possible
    • parseFile

      protected Map<String,List<UserIdentity>> parseFile(BOMInputStream bomIS, String populationId, String userDirectoryId, boolean hashedPassword) throws IOException, org.ametys.plugins.core.user.ImportUsers.ImportUserActionException
      Parse the file to add new users in the directory
      Parameters:
      bomIS - input stream
      populationId - population Id
      userDirectoryId - directory Id
      hashedPassword - true if the password is hashed
      Returns:
      a map, containing added/edited/error, each containing the logins in each list
      Throws:
      IOException - if an error occurs
      org.ametys.plugins.core.user.ImportUsers.ImportUserActionException - file parsing failed