method.invoke(csvUser, arguments);
i++;
}
User userToImport = csvUser.getUser(errorMessages);
if(userToImport == null){
// error during parsing the user
importResult.incUsersIgnored();
continue;
}
// users with too less data will be ignored
if((userToImport.getUsername() == null || userToImport.getUsername().trim().equals("")) &&
(userToImport.getFirstName() == null || userToImport.getFirstName().trim().equals("")) &&
(userToImport.getLastName() == null || userToImport.getLastName().trim().equals("")) &&
(userToImport.getMsisdn() == null) &&
(userToImport.getEmail() == null || userToImport.getEmail().trim().equals("")) &&
(userToImport.getPersonalNumber() == null || userToImport.getPersonalNumber().equals(""))){
importResult.incUsersIgnored();
continue;
}
User alreadyExistingUser = null;
if(mergeAccordingToUsername){
if(userToImport.getUsername() != null && userToImport.getUsername().length() > 0){
alreadyExistingUser = getUserDetails(userToImport.getUsername(),userSet.getGroup());
}
} else if(mergeAccordingToMsisdn){
if(userToImport.getMsisdn() != null){
alreadyExistingUser = getUserDetails(userToImport.getMsisdn(),userSet.getGroup());
}
} else if(mergeAccordingToPersonelNumber){
if(userToImport.getPersonalNumber() != null && userToImport.getPersonalNumber().length() > 0){
alreadyExistingUser = getUserDetailsByPersonalNumber(userToImport.getPersonalNumber(),userSet.getGroup());
}
}
User userInDb = null;
if(alreadyExistingUser == null){
LOGGER.debug("create new User data objet");
if(userToImport.getUsername() != null && !userToImport.getUsername().equals("")){ // a default role will be assigned
Role role = getRole(USER);
Set<Role> roles = new HashSet<Role>(1);
roles.add(role);
userToImport.setRoles(roles);
}
userToImport.setGroup(userSet.getGroup());
userInDb = createUser(userToImport, userToImport.getPassword());
importResult.incUsersCreated();
} else{
LOGGER.debug("merge existing user data object");
User user = mergeUser(userToImport,alreadyExistingUser);
modifyUser(user);
importResult.incUsersUpdated();
userInDb = user;
}