return "console/directory/deptEdit";
}
@RequestMapping(value = "/console/directory/dept/submit/(*:action)", method = RequestMethod.POST)
public String consoleDeptSubmit(ModelMap model, @RequestParam("action") String action, @RequestParam("orgId") String orgId, @RequestParam(value = "parentId", required = false) String parentId, @ModelAttribute("department") Department department, BindingResult result) {
Organization organization = organizationDao.getOrganization(orgId);
Department parent = null;
if (parentId != null && parentId.trim().length() > 0) {
parent = departmentDao.getDepartment(parentId);
}
// validate ID
validator.validate(department, result);
boolean invalid = result.hasErrors();
if (!invalid) {
// check error
Collection<String> errors = new ArrayList<String>();
if ("create".equals(action)) {
// check id exist
if (departmentDao.getDepartment(department.getId()) != null) {
errors.add("console.directory.department.error.label.idExists");
} else {
department.setOrganization(organization);
if (parent != null) {
department.setParent(parent);
}
invalid = !departmentDao.addDepartment(department);
}
} else {
Department d = departmentDao.getDepartment(department.getId());
d.setName(department.getName());
d.setDescription(department.getDescription());
invalid = !departmentDao.updateDepartment(d);
}
if (!errors.isEmpty()) {
model.addAttribute("errors", errors);
invalid = true;
}
}
if (invalid) {
model.addAttribute("organization", organization);
model.addAttribute("department", department);
if (parent != null) {
model.addAttribute("parent", parent);
}
if ("create".equals(action)) {
return "console/directory/deptCreate";
} else {
return "console/directory/deptEdit";
}
} else {
String id = organization.getId();
String contextPath = WorkflowUtil.getHttpServletRequest().getContextPath();
String url = contextPath;
if ("create".equals(action)) {
if (parent != null) {
url += "/web/console/directory/dept/view/" + parent.getId();