}
public void addUser(User newUser) throws WebloggerException {
if(newUser == null)
throw new WebloggerException("cannot add null user");
// TODO BACKEND: we must do this in a better fashion, like getUserCnt()?
boolean adminUser = false;
List existingUsers = this.getUsers(null, Boolean.TRUE, null, null, 0, 1);
if(existingUsers.size() == 0) {
// Make first user an admin
adminUser = true;
//if user was disabled (because of activation user
// account with e-mail property), enable it for admin user
newUser.setEnabled(Boolean.TRUE);
newUser.setActivationCode(null);
}
if(getUserByUserName(newUser.getUserName()) != null ||
getUserByUserName(newUser.getUserName().toLowerCase()) != null) {
throw new WebloggerException("error.add.user.userNameInUse");
}
newUser.grantRole("editor");
if(adminUser) {
newUser.grantRole("admin");