public class ImportUsers extends AbstractLogEnabled implements Component, Serviceable
Modifier and Type | Class and Description |
---|---|
private static class |
ImportUsers.ImportUserActionException
Internal exception to throw with a i18n message
|
Modifier and Type | Field and Description |
---|---|
private static String[] |
_ALLOWED_EXTENSIONS |
private static String |
_COLUMN_EMAIL |
private static String |
_COLUMN_FIRSTNAME |
private static String |
_COLUMN_LASTNAME |
private static String |
_COLUMN_LOGIN |
private static String |
_COLUMN_PASSWORD |
private static String |
_COLUMN_SALT |
private static String[] |
_COLUMNS |
protected I18nUtils |
_i18nUtils
I18n utils
|
protected UserManager |
_userManager
User Manager.
|
protected UserDAO |
_usersDao
The subscribers DAO.
|
static String |
ROLE
Avalon Role
|
Constructor and Description |
---|
ImportUsers() |
Modifier and Type | Method and Description |
---|---|
private void |
_checkCsvHeader(String[] columns,
boolean hashedPassword)
Check a line (the header) and throw an exception if not correct
|
private String |
_parseErrors(Map<String,Errors> errors) |
protected List<Map<String,String>> |
clearUserDirectory(String populationId,
String userDirectoryId,
List<UserIdentity> usersToSave)
Remove all users in a userDirectory, avoiding those in usersToSave list
|
Map<String,Object> |
importUsers(Part filePart,
String populationId,
String userDirectoryId,
boolean cleanDirectory,
boolean hashedPasswords)
Read a file from disk and add users inside in the requested population/directory
|
protected Map<String,List<UserIdentity>> |
parseFile(org.apache.commons.io.input.BOMInputStream bomIS,
String populationId,
String userDirectoryId,
boolean hashedPassword)
Parse the file to add new users in the directory
|
void |
service(ServiceManager smanager) |
getLogger, setLogger
private static final String[] _ALLOWED_EXTENSIONS
private static final String _COLUMN_LOGIN
private static final String _COLUMN_PASSWORD
private static final String _COLUMN_FIRSTNAME
private static final String _COLUMN_LASTNAME
private static final String _COLUMN_EMAIL
private static final String _COLUMN_SALT
protected UserManager _userManager
protected I18nUtils _i18nUtils
public ImportUsers()
public void service(ServiceManager smanager) throws ServiceException
service
in interface Serviceable
ServiceException
public Map<String,Object> importUsers(Part filePart, String populationId, String userDirectoryId, boolean cleanDirectory, boolean hashedPasswords) throws FileNotFoundException, InvalidModificationException
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)FileNotFoundException
- error reading the fileInvalidModificationException
- error modifying the directoryprotected List<Map<String,String>> clearUserDirectory(String populationId, String userDirectoryId, List<UserIdentity> usersToSave) throws InvalidModificationException
populationId
- population IduserDirectoryId
- directory IdusersToSave
- list of users that need to be savedInvalidModificationException
- If modification is not possibleprotected Map<String,List<UserIdentity>> parseFile(org.apache.commons.io.input.BOMInputStream bomIS, String populationId, String userDirectoryId, boolean hashedPassword) throws IOException, ImportUsers.ImportUserActionException
bomIS
- input streampopulationId
- population IduserDirectoryId
- directory IdhashedPassword
- true if the password is hashedIOException
- if an error occursImportUsers.ImportUserActionException
- file parsing failedprivate String _parseErrors(Map<String,Errors> errors)
private void _checkCsvHeader(String[] columns, boolean hashedPassword) throws ImportUsers.ImportUserActionException
columns
- list of fieldshashedPassword
- is the password in clear text ? (special case for 'salt' column)ImportUsers.ImportUserActionException
- thrown if error