@RequestMapping(value = "editadviseraction", method = RequestMethod.GET) public ModelAndView edit(Integer id, Integer projectId) throws Exception { ProjectWrapper pw = this.tempProjectManager.get(projectId); ModelAndView mav = new ModelAndView(); AdviserAction aa = new AdviserAction(); Adviser a = this.projectDao.getAdviserByTuakiriUniqueId(getTuakiriUniqueIdFromRequest()); aa.setAdviserId(a.getId()); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); aa.setDate(df.format(new Date())); for (AdviserAction aac : pw.getAdviserActions()) { if (aac.getId().equals(id)) aa = aac; } mav.addObject("adviserAction", aa); mav.addObject("adviserId", aa.getAdviserId()); return mav; }
@RequestMapping(value = "editadviseraction", method = RequestMethod.POST) public RedirectView editPost(AdviserAction aa) throws Exception { Integer projectId = aa.getProjectId(); ProjectWrapper pw = this.tempProjectManager.get(projectId); aa.setAdviserName(this.projectDao.getAdviserById(aa.getAdviserId()).getFullName()); if (aa.getId() == null) { aa.setId(random.nextInt()); pw.getAdviserActions().add(aa); } else { for (int i = 0; i < pw.getAdviserActions().size(); i++) { if (pw.getAdviserActions().get(i).getId().equals(aa.getId())) { aa.setAttachments(pw.getAdviserActions().get(i).getAttachments()); pw.getAdviserActions().set(i, aa); } } } this.tempProjectManager.update(projectId, pw); return new RedirectView("editproject?id=" + projectId + "#adviseractions"); }