protected void handleRequest(HttpServletRequest request,
HttpServletResponse response) {
Command command = (Command) request.getAttribute("command");
ProjectManager manager = new ProjectManager();
Project project = null;
ArrayList<String> errors = new ArrayList<String>();
HashMap<String, String> fieldMessages = new HashMap<String, String>();
// first check to see if we're just pulling a record from the history
try {
if ((command.getModifier() != null)
&& (command.getModifier().equals("history"))) {
String[] vals = command.getOther().get(0).split("\\|");
AuditLogManager alm = new AuditLogManager();
try {
AuditLog record = alm.getRecord(Integer.parseInt(vals[0]),
ContentType.valueOf(Integer.parseInt(vals[1])),
Integer.parseInt(vals[2]), Timestamp
.valueOf(vals[3]));
String data = record.getDataExport();
project = new Project();
project.fromString(data);
request.setAttribute("isDirty", "t");
} catch (NullPointerException e) {
errors.add("Invalid history request format.");
} catch (NumberFormatException e) {
errors.add("Invalid history request format.");
} catch (NoSuchAuditLogRecordException e) {
errors
.add("The history record requested couldn't be located.");
} catch (DataTypeMismatchException e) {
Logger.error(
"Data type mismatch occurred pulling "
+ command.getOther().get(0)
+ " from the audit log", e);
errors
.add("A system error was encountered (DataTypeMismatch). "
+ "Please contact a system administrator.");
}
if (project == null) {
project = manager.getProject(command.getProject());
}
} else {
// if it's not from history, then...
project = manager.getProject(command.getProject());
String cancel;
if (((cancel = request.getParameter("cancelChanges")) != null)
&& (cancel.equals("yes"))) {
request.setAttribute("successMessage",
"Your changes have been cancelled.");
} else {
if (request.getParameter("projectId") != null) {
// this is an update from the project form if the
// projectId param is set
String oldVersion = project.toString();
if ((project.getProjectId() != Integer.parseInt(request
.getParameter("projectId")))
|| (!project.getHandle().equals(
request.getParameter("handle")))
|| (!project.getHandle().equals(
command.getProject()))) {
errors
.add("Form corruption occurred ... please try again.");
} else {
// go ahead and populate the data from the request
populateVBOFromRequest(project, request,
fieldMessages, true);
}
if (project.toString().equals(oldVersion)) {
errors.add("No changes detected.");
}
if ((errors.size() == 0) && (fieldMessages.size() == 0)) {
User user = (User) request.getSession()
.getAttribute("user");
manager.updateProject(project, user, oldVersion);
request.setAttribute("successMessage",
"Project successfully updated <span class=\"tinyformtext\">("
+ Calendar.getInstance().getTime()
.toString() + ")</span>");
}
}
}
}
} catch (NoSuchProjectException e) {
Logger.fatal("Project handle '" + command.getProject()
+ "' doesn't exist!", e);
request
.setAttribute(
"errorMessage",
"The requested project couldn't be located. "
+ "This is a FATAL error, so please stop working in this area, "
+ "and contact the system administrator.");
}
request.setAttribute("project", project);
// put the project's history in the request scope (the project itself
// is in the application scope)
ArrayList<AuditLog> historyRecords = (new AuditLogManager())
.getUpdateRecords(project.getProjectId(), ContentType.PROJECT,
project.getProjectId());
if ((historyRecords != null) && (historyRecords.size() > 0)) {
request.setAttribute("history", historyRecords);
}
// set up error and field messages, as appropriate