* <code>false</code> if all's well.
*/
private boolean handleCommunityUpdateRequest(HttpServletRequest request,
Command command, ArrayList<String> errors, User user,
ArrayList<Integer> openNodes, HashMap<String, String> fieldMessages) {
CommunityManager communityManager = new CommunityManager();
WorkflowManager workflowManager = new WorkflowManager();
Community community = null;
// user is updating an existing community
boolean goToList = false;
int parentId = -1;
if (request.getParameter("parentId") != null) {
parentId = Integer.parseInt(request.getParameter("parentId"));
// verify that the user can edit the requested parent
if (!workflowManager.canEdit(user, command.getProject(), command
.getCommand(), parentId)) {
errors.add("You don't have permission to add a "
+ "subcommunity to the requested community.");
goToList = true;
} else {
request.setAttribute("parentId", request
.getParameter("parentId"));
}
}
// continue processing the update request if no errors have been
// encountered so far
if (!goToList) {
try {
int communityId;
boolean isFormSubmission = false;
if (request.getParameter("communityId") != null) {
// the id comes from the request if it's a form
// submission
communityId = Integer.parseInt(request
.getParameter("communityId"));
isFormSubmission = true;
} else {
// the id comes from the "other" portion of the command
// if the user's clicked the community for editing
communityId = Integer.parseInt(command.getOther().get(0));
}
if (communityId == -1) {
// this is a new community
try {
community = communityManager.getCommunity(command, -1,
false);
} catch (NoSuchCommunityException e) {
Logger.error("An empty community couldn't be created.",
e);
errors.add("Empty community couldn't be constructed.");
goToList = true;
}
} else {
// this is an existing community
if (!workflowManager.canEdit(user, command.getProject(),
command.getCommand(), communityId)) {
errors.add("You don't have permission to edit "
+ "the requested community.");
goToList = true;
} else {
// user has permission, so get the existing
// community
try {
community = communityManager.getCommunityForUpdate(
command, communityId, false, request
.getSession());
} catch (NoSuchCommunityException e) {
Logger.warn("Requested community (" + communityId
+ ") couldn't be retrieved", e);
errors.add("Requested community (" + communityId
+ ") couldn't be retrieved");
goToList = true;
} catch (ContentLockedException e) {
errors.add(e.getMessage());
goToList = true;
}
}
}
// if all's well so far....
if ((isFormSubmission) && (community != null)) {
String oldData = community.toString();
populateVBOFromRequest(community, request, fieldMessages,
true);
if (oldData.equals(community.toString())) {
errors.add("No changes detected.");
}
if ((errors.size() == 0) && (fieldMessages.size() == 0)) {
// perform the add or update with the community
// manager
try {
if (community.getId() == -1) {
communityManager.addCommunity(user, community,
parentId);
request.setAttribute("successMessage",
"Community successfully added.");
} else {
communityManager
.updateCommunity(community,
((User) request.getSession()
.getAttribute("user")),
oldData);
request