*/
private void updateRole(HttpServletRequest request,
HttpServletResponse response, Command command) {
ArrayList<String> errors = new ArrayList<String>();
HashMap<String, String> fieldMessages = new HashMap<String, String>();
RoleManager roleManager = new RoleManager();
Role role = new Role();
populateVBOFromRequest(role, request, fieldMessages, true);
int roleId = role.getRoleId();
boolean isErrors = false;
Role oldRole = null;
Project project = null;
// get original role record from database
try {
oldRole = new RoleManager().getRoleByRoleId(roleId);
if (oldRole == null) {
isErrors = true;
errors.add("Role ID was not found");
}
} catch (NoSuchRoleException nsue) {
isErrors = true;
Logger.error(
"\n Attempting to update Role but could not retrieve role by role_id "
+ roleId + "\n", nsue);
errors.add("Role ID was not found");
}
String oldContent = oldRole.toString();
// set parentId of new Info if its > 0
role.setParentRoleId(oldRole.getParentRoleId());
// detect whether role data changed
if (oldContent.equals(role.toString())) {
errors.add("No changes detected.");
isErrors = true;
}
// if user is attempting to change role name,
// the system must validate role name/manager pair doesn't already exist
if ((!oldRole.getName().equalsIgnoreCase(role.getName()))
&& (!oldRole.isManager() == role.isManager())) {
// if role exist add to errors messaging
if (roleManager.isRoleExist(role.getName().toLowerCase(), role
.isManager(), role.getParentRoleId())) {
errors.add("Role Name: " + role.getName()
+ " already exist. Please enter another role name.");
isErrors = true;
}
}
// if no errors occurred update role record
if ((!isErrors) && (fieldMessages.size() == 0)) {
try {
User sessionUser = (User) request.getSession().getAttribute(
"user");
roleManager.updateRole(new ProjectManager().getProject(command
.getProject()), sessionUser, role, oldContent);
// if update was successful send messages....
request.setAttribute("successMessage",
"Role successfully updated <span class=\"tinyformtext\">("
+ Calendar.getInstance().getTime().toString()