Package org.ametys.plugins.core.user
Class ImportUsers
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.core.user.ImportUsers
- All Implemented Interfaces:
LogEnabled
,Component
,Serviceable
Import users from a CSV or text file.
-
Field Summary
Modifier and TypeFieldDescriptionprotected CurrentUserProvider
Current User Providerprotected I18nUtils
I18n utilsprotected ObservationManager
Observation Managerprotected UserManager
User Manager.protected UserDAO
The subscribers DAO.static final String
Avalon Role -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclearUserDirectory
(String populationId, String userDirectoryId, List<UserIdentity> usersToSave) Remove all users in a userDirectory, avoiding those in usersToSave listimportUsers
(Part filePart, String populationId, String userDirectoryId, boolean cleanDirectory, boolean hashedPasswords) Read a file from disk and add users inside in the requested population/directoryprotected Map<String,
List<UserIdentity>> parseFile
(BOMInputStream bomIS, String populationId, String userDirectoryId, boolean hashedPassword) Parse the file to add new users in the directoryvoid
service
(ServiceManager smanager) Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
Avalon Role -
_usersDao
The subscribers DAO. -
_userManager
User Manager. -
_i18nUtils
I18n utils -
_observationManager
Observation Manager -
_currentUserProvider
Current User Provider
-
-
Constructor Details
-
ImportUsers
public ImportUsers()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- 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
- filepopulationId
- population IduserDirectoryId
- user directorycleanDirectory
- true to clear every user that was not in the import filehashedPasswords
- 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 fileInvalidModificationException
- 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 IduserDirectoryId
- directory IdusersToSave
- 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 streampopulationId
- population IduserDirectoryId
- directory IdhashedPassword
- 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 occursorg.ametys.plugins.core.user.ImportUsers.ImportUserActionException
- file parsing failed
-