{
logger.info("Changing user name for user: '" + userName + "' to '" + newUserName + "'");
SystemUserVO newSystemUserVO = user.getValueObject();
newSystemUserVO.setUserName(newUserName);
SystemUser newSystemUser = new SystemUserImpl();
newSystemUser.setValueObject(newSystemUserVO);
newSystemUser = (SystemUser) createEntity(newSystemUser, db);
// Add roles
List<RoleVO> roleVOs = RoleController.getController().getRoleVOList(userName, db);
logger.info("Adding roles in user name change. Number of roles: " + roleVOs.size());
for (RoleVO roleVO : roleVOs)
{
if (logger.isDebugEnabled())
{
logger.debug("Handling role (" + roleVO.getRoleName() + ") in user name change. User name, from: '" + userName + "', to '" + newUserName + "'");
}
RoleController.getController().addUser(roleVO.getRoleName(), newSystemUser.getUserName(), db);
RoleController.getController().removeUser(roleVO.getRoleName(), userName, db);
}
// Add groups
List<GroupVO> groupVOs = GroupController.getController().getGroupVOList(userName, db);
logger.info("Adding groups in user name change. Number of groups: " + groupVOs.size());
for (GroupVO groupVO : groupVOs)
{
if (logger.isDebugEnabled())
{
logger.debug("Handling group (" + groupVO.getGroupName() + ") in user name change. User name, from: '" + userName + "', to '" + newUserName + "'");
}
GroupController.getController().addUser(groupVO.getGroupName(), newSystemUser.getUserName(), db);
GroupController.getController().removeUser(groupVO.getGroupName(), userName, db);
}
// Add access rights
@SuppressWarnings("unchecked")
List<AccessRightUser> accessRightUserList = AccessRightController.getController().getAccessRightUserList(userName, db);
logger.debug("Updating access rights for user name change. Number of access rights: " + accessRightUserList.size());
Iterator<AccessRightUser> i = accessRightUserList.iterator();
while(i.hasNext())
{
AccessRightUser accessRightUser = i.next();
//accessRightUser.setUserName(newUserName);
AccessRight accessRight = accessRightUser.getAccessRight();
AccessRightUserVO accessRightUserVO = new AccessRightUserVO();
accessRightUserVO.setUserName(newSystemUser.getUserName());
AccessRightUser newAccessRightUser = AccessRightController.getController().createAccessRightUser(db, accessRightUserVO, accessRight);
accessRight.getUsers().add(newAccessRightUser);
deleteEntity(AccessRightUserImpl.class, accessRightUser.getAccessRightUserId(), db);
}