private boolean handleBundleUpdateRequest(HttpServletRequest request,
Command command, ArrayList<String> errors, User user,
ArrayList<Integer> openNodes, HashMap<String, String> fieldMessages) {
BundleManager bundleManager = new BundleManager();
WorkflowManager workflowManager = new WorkflowManager();
Bundle bundle = 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 "
+ "bundle to the requested object.");
goToList = true;
} else {
request.setAttribute("parentId", request
.getParameter("parentId"));
}
}
if (!goToList) {
try {
int bundleId;
boolean isFormSubmission = false;
if (request.getParameter("bundleId") != null) {
// the id comes from the request if it's a form
// submission
bundleId = Integer.parseInt(request
.getParameter("bundleId"));
isFormSubmission = true;
} else {
// the id comes from the "other" portion of the command
// if the user's clicked the bundle for editing
bundleId = Integer.parseInt(command.getOther().get(0));
}
if (bundleId == -1) {
// this is a new bundle
try {
bundle = bundleManager.getBundle(command, -1, false);
} catch (NoSuchBundleException e) {
Logger.error("An empty bundle couldn't be created.", e);
errors.add("Empty bundle couldn't be constructed.");
goToList = true;
}
} else {
// this is an existing bundle
// first make sure that the user can edit it
if (!workflowManager.canEdit(user, command.getProject(),
command.getCommand(), bundleId)) {
errors.add("You don't have permission to edit "
+ "the requested bundle.");
goToList = true;
} else {
try {
bundle = bundleManager.getBundleForUpdate(command,
bundleId, false, request.getSession());
} catch (NoSuchBundleException e) {
Logger.warn("Requested bundle (" + bundleId
+ ") couldn't be retrieved", e);
errors.add("Requested bundle (" + bundleId
+ ") couldn't be retrieved");
goToList = true;
} catch (ContentLockedException e) {
errors.add(e.getMessage());
goToList = true;
}
}
}
if ((isFormSubmission) && (bundle != null)) {
String oldData = bundle.toString();
populateVBOFromRequest(bundle, request, fieldMessages, true);
String addToRepeatables = request
.getParameter("addToRepeatables");
if ((addToRepeatables == null)
|| (addToRepeatables.trim().length() == 0)) {
if (oldData.equals(bundle.toString())) {
errors.add("No changes detected.");
}
if ((errors.size() == 0) && (fieldMessages.size() == 0)) {
try {
if (bundle.getId() == -1) {
bundleManager.addBundle(user, bundle,
parentId);
request.setAttribute("successMessage",
"Bundle successfully added.");
} else {
bundleManager.updateBundle(bundle,
((User) request.getSession()
.getAttribute("user")),
oldData);
request
.setAttribute(
"successMessage",
"Bundle '"
+ bundle
.getMetadataBasedTitle()
+ "' successfully updated.");
if ((request.getParameter("fs") != null)
&& (request.getSession()
.getAttribute(
"searchResults") != null)) {
SearchManager
.updateSessionSearchResults(
request, bundle);
}
}
goToList = true;
} catch (NoSuchBundleException e) {
Logger.warn("Bundle " + bundle.getBundleId()
+ " couldn't be found for update", e);
errors.add(e.getMessage());
} catch (SQLException e) {
Logger
.error(