private void enforceBusinessRules(Role role, String userName, String userPassword, String firstName, String middleName, String lastName, String gender){
if(role == null)
throw new BusinessRuleException("The role to be associated with an user cannot be null");
if(role.getRoleId()==null)
throw new BusinessRuleException("The role to be associated with an user was not initialized properly ");
if(StringUtils.isEmpty(firstName))
throw new BusinessRuleException("User's first name cannot be blank");
if(firstName.length()>32)
throw new BusinessRuleException("User's first name can be only 32 characters in length");
if(! firstName.matches("[a-zA-Z]*"))
throw new BusinessRuleException("User's first name can consist of only A-Z or a-z");
if(! StringUtils.isEmpty(middleName)){
if(middleName.length()>32)
throw new BusinessRuleException("User's middle name can be only 32 characters in length");
if(! middleName.matches("[a-zA-Z]*"))
throw new BusinessRuleException("User's middle name can consist of only A-Z or a-z");
}
if(StringUtils.isEmpty(lastName))
throw new BusinessRuleException("User's last name cannot be blank");
if(lastName.length()>32)
throw new BusinessRuleException("User's last name can be only 32 characters in length");
if(! lastName.matches("[a-zA-Z]*"))
throw new BusinessRuleException("User's last name can consist of only A-Z or a-z");
if(StringUtils.isEmpty(userName))
throw new BusinessRuleException("User-name cannot be blank");
if(userName.length()>32)
throw new BusinessRuleException("User-name cannot be more than 32 characters");
if(! userName.matches("[a-zA-Z0-9.]*"))
throw new BusinessRuleException("User-name cannot contain other characters than a-z A-Z 0-9.");
if(StringUtils.isEmpty(userPassword))
throw new BusinessRuleException("Password cannot be blank");
if(userPassword.length()>64)
throw new BusinessRuleException("Password cannot be more than 64 chars");
if(StringUtils.isEmpty(gender))
throw new BusinessRuleException("User's gender cannot be blank");
if(gender.length()>1)
throw new BusinessRuleException("User's gender can be only M/F");
if(isActive == null)
throw new BusinessRuleException("The User has to be either active/inactive");
}