* @return the user object
*/
public User getUser(List<String> errorMessages){
ResourceBundle messages = ResourceBundle.getBundle("UserManagement", currentLocale);
User user = new User();
user.setAddress(address);
user.setCity(city);
user.setCreationdate(new Date(System.currentTimeMillis()));
if(email!= null && !email.equals("") && !email.matches(".*@[a-zA-Z0-9-]*.[a-zA-Z0-9.]*$")){
errorMessages.add(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("InvalidEmailAddress"));
LOGGER.info(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("InvalidEmailAddress"));
return null;
}
user.setEmail(email);
user.setFirstName(firstName);
user.setLastName(lastName);
if(mobilePhoneProducer != null && !mobilePhoneProducer.equals("Nokia") && !mobilePhoneProducer.equals("Not Nokia")){
errorMessages.add(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("InvalidMobilePhoneProducer"));
LOGGER.info(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("InvalidMobilePhoneProducer"));
return null;
}
user.setMobilePhoneProducer(mobilePhoneProducer);
if(msisdn != null && msisdn.length() > 0){
Long parsedMsisdn = parseMsisdn(msisdn, errorMessages);
if(parsedMsisdn == null){
return null;
}
user.setMsisdn(parsedMsisdn);
}
user.setPersonalNumber(personalNumber);
user.setPostalCode(postalCode);
user.setTitle(title);
if(username != null && username.length() > 0){
if(username.length() < 3 || username.length() > 20 || !username.matches("^[0-9a-z._]*$")){
errorMessages.add(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("InvalidUserName"));
LOGGER.info(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("InvalidUserName"));
return null;
}
user.setUsername(username);
}
if(password != null && password.length() > 0){
if(password.length() < 3 || password.length() > 15){
errorMessages.add(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("InvalidPassword"));
LOGGER.info(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("InvalidPassword"));
return null;
}
user.setPassword(password);
}
if((username != null && password == null) || (username == null && password != null)){
errorMessages.add(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("EitherUsernameAndPasswordMustBeProvidedOrNothing"));
LOGGER.info(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("EitherUsernameAndPasswordMustBeProvidedOrNothing"));
return null;
}
if((username == null || username.equals(""))
&& (msisdn == null || msisdn.equals(""))
&& (firstName == null || firstName.equals(""))
&& (lastName == null || lastName.equals(""))
&& (email == null || email.equals("")) ){
errorMessages.add(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("EitherUsernameOrMsisdnOrFirstnameOrLastnameOrEmailMustBeProvided"));
LOGGER.info(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("EitherUsernameOrMsisdnOrFirstnameOrLastnameOrEmailMustBeProvided"));
return null;
}
if(gender != null){
try {
int genderValue = Integer.parseInt(gender);
if (genderValue < 1 || genderValue > 2 ){
errorMessages.add(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("GenderMustBe1ForMaleOr2ForFemale"));
LOGGER.info(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("GenderMustBe1ForMaleOr2ForFemale"));
return null;
} else {
user.setGender(genderValue);
}
} catch(NumberFormatException e){
errorMessages.add(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("GenderMustBe1ForMaleOr2ForFemale"));
LOGGER.info(messages.getString("ErrorInLine") +" " + lineNumber + ": " + messages.getString("GenderMustBe1ForMaleOr2ForFemale"));
}
}
user.setCustomerNumber(customerNumber);
user.setSalutation(salutation);
user.setConsultantName(consultantName);
user.setConsultantOrganization(consultantOrganization);
return user;
}