@RequestMapping(method = RequestMethod.POST) public String update( @ModelAttribute Complaint complaint, final BindingResult errors, final RedirectAttributes redirectAttrs, final Model model, final HttpServletRequest request, @RequestParam("files") final MultipartFile[] files) { // this validation is common for citizen and official. Any more // specific // validation required for official then write different method validateUpdate(complaint, errors, request); Long approvalPosition = 0l; String approvalComent = ""; String result = ""; if (request.getParameter("approvalComent") != null && !request.getParameter("approvalComent").trim().isEmpty()) approvalComent = request.getParameter("approvalComent"); if (request.getParameter("approvalPosition") != null && !request.getParameter("approvalPosition").isEmpty()) approvalPosition = Long.valueOf(request.getParameter("approvalPosition")); if (!securityUtils.currentUserType().equals(UserType.CITIZEN)) if (files != null) complaint.getSupportDocs().addAll(addToFileStore(files)); if (!errors.hasErrors()) { complaint = complaintService.update(complaint, approvalPosition, approvalComent); redirectAttrs.addFlashAttribute("complaint", complaint); result = "redirect:" + complaint.getCrn() + COMPLAINT_UPDATE_SUCCESS; } else { final List<Hashtable<String, Object>> historyTable = complaintService.getHistory(complaint); model.addAttribute("complaintHistory", historyTable); model.addAttribute("complaintType", complaintTypeService.findAll()); model.addAttribute("approvalDepartmentList", departmentService.getAllDepartments()); model.addAttribute( "zone", boundaryService.getBoundariesByBndryTypeNameAndHierarchyTypeName( "ZONE", "ADMINISTRATION")); model.addAttribute("ward", Collections.EMPTY_LIST); if (complaint.getLocation() != null && complaint.getLocation().getParent() != null) model.addAttribute( "ward", boundaryService.getActiveChildBoundariesByBoundaryId( complaint.getLocation().getParent().getId())); if (securityUtils.currentUserType().equals(UserType.CITIZEN)) result = COMPLAINT_CITIZEN_EDIT; else result = COMPLAINT_EDIT; } return result; }
@RequestMapping(method = RequestMethod.GET) public String edit(final Model model, @PathVariable final String crnNo) { final Complaint complaint = complaintService.getComplaintByCRN(crnNo); model.addAttribute("complaintHistory", complaintService.getHistory(complaint)); model.addAttribute( "status", complaintStatusMappingService.getStatusByRoleAndCurrentStatus( securityUtils.getCurrentUser().getRoles(), complaint.getStatus())); model.addAttribute("complaint", complaint); if (securityUtils.currentUserType().equals(UserType.CITIZEN)) return COMPLAINT_CITIZEN_EDIT; else { model.addAttribute("approvalDepartmentList", departmentService.getAllDepartments()); model.addAttribute("complaintType", complaintTypeService.findAll()); model.addAttribute("ward", Collections.EMPTY_LIST); if (complaint.getLocation() != null && complaint.getLocation().getParent() != null) model.addAttribute( "ward", boundaryService.getBoundariesByBndryTypeNameAndHierarchyTypeName( "Ward", "Administration")); if (complaint.getLocation() != null && complaint.getLocation().getParent() != null) model.addAttribute( "location", crossHierarchyService.getChildBoundariesNameAndBndryTypeAndHierarchyType( "Locality", "Ward", "Location")); model.addAttribute( "mailSubject", "Grievance regarding " + complaint.getComplaintType().getName()); model.addAttribute("mailBody", complaintService.getEmailBody(complaint)); return COMPLAINT_EDIT; } }
private void validateUpdate( final Complaint complaint, final BindingResult errors, final HttpServletRequest request) { if (complaint.getStatus() == null) errors.rejectValue("status", "status.requried"); if (request.getParameter("approvalComent") == null || request.getParameter("approvalComent").trim().isEmpty()) errors.addError( new ObjectError( "approvalComent", messageSource.getMessage("comment.not.null", null, null))); }