* <code>false</code> if all's well.
*/
private boolean handleCollectionUpdateRequest(HttpServletRequest request,
Command command, ArrayList<String> errors, User user,
ArrayList<Integer> openNodes, HashMap<String, String> fieldMessages) {
CollectionManager collectionManager = new CollectionManager();
WorkflowManager workflowManager = new WorkflowManager();
Collection collection = null;
int parentId = -1;
boolean goToList = false;
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 "
+ "collection to the requested object.");
goToList = true;
} else {
request.setAttribute("parentId", request
.getParameter("parentId"));
}
}
if (!goToList) {
try {
int collectionId;
boolean isFormSubmission = false;
if (request.getParameter("collectionId") != null) {
// the id comes from the request if it's a form
// submission
collectionId = Integer.parseInt(request
.getParameter("collectionId"));
isFormSubmission = true;
} else {
// the id comes from the "other" portion of the command
// if the user's clicked the collection for editing
collectionId = Integer.parseInt(command.getOther().get(0));
}
if (collectionId == -1) {
// this is a new collection
try {
collection = collectionManager.getCollection(command,
-1, false);
} catch (NoSuchCollectionException e) {
Logger.error(
"An empty collection couldn't be created.", e);
errors.add("Empty collection couldn't be constructed.");
goToList = true;
}
} else {
// this is an existing collection
// first make sure that the user can edit it
if (!workflowManager.canEdit(user, command.getProject(),
command.getCommand(), collectionId)) {
errors.add("You don't have permission to edit "
+ "the requested collection.");
goToList = true;
} else {
try {
collection = collectionManager
.getCollectionForUpdate(command,
collectionId, false, request
.getSession());
} catch (NoSuchCollectionException e) {
Logger.warn("Requested collection (" + collectionId
+ ") couldn't be retrieved", e);
errors.add("Requested collection (" + collectionId
+ ") couldn't be retrieved");
goToList = true;
} catch (ContentLockedException e) {
errors.add(e.getMessage());
goToList = true;
}
}
}
if ((isFormSubmission) && (collection != null)) {
String oldData = collection.toString();
populateVBOFromRequest(collection, request, fieldMessages,
true);
String addToRepeatables = request
.getParameter("addToRepeatables");
if ((addToRepeatables == null)
|| (addToRepeatables.trim().length() == 0)) {
if (oldData.equals(collection.toString())) {
errors.add("No changes detected.");
}
if ((errors.size() == 0) && (fieldMessages.size() == 0)) {
try {
if (collection.getId() == -1) {
collectionManager.addCollection(user,
collection, parentId);
request.setAttribute("successMessage",
"Collection successfully added.");
} else {
collectionManager.updateCollection(
collection, ((User) request
.getSession().getAttribute(
"user")), oldData);
request
.setAttribute(