@RequestMapping(value = "/viewrecord.html", method = RequestMethod.GET) public String viewRecord(@RequestParam Map<String, Object> map, Map<String, Object> mapresp) { User currentUser = getCurrentUser(); String paramId = (String) map.get("id"); Integer id; try { id = Integer.parseInt(paramId); } catch (NumberFormatException e) { mapresp.put("errMesg", "Incorect record id"); return "redirect:/records.html"; } Record record = recordService.getRecord(id); if (record != null) { if (!record.getUser().equals(currentUser) && record.getAccess().getId() != 2) { record = null; } } else { mapresp.put("errMesg", "Incorect record id"); return "redirect:/records.html"; } List<FileView> fileDescription = fileDescriptionService.getFilesDescription(record); mapresp.put("filelist", fileDescription); mapresp.put("currentuser", getCurrentUser()); mapresp.put("record", record); return "viewrecord"; }
/** A-Team Deleting Group of note marked by checkboxes */ @RequestMapping(value = "/deleterecordgroup.html", method = RequestMethod.POST) public String deleteRecordGroup( @RequestParam Map<String, Object> map, Map<String, Object> mapresp, HttpServletRequest request) { String button1 = request.getParameter("deletegroup"); if (button1 != null) { User currentUser = getCurrentUser(); String[] checkedNotesId = request.getParameterValues("markednotes"); Integer id = null; if (checkedNotesId != null) { for (String itemID : checkedNotesId) { try { id = Integer.parseInt(itemID); } catch (NumberFormatException e) { id = 0; } Record record = recordService.getRecord(id); if (record != null && record.getUser().equals(currentUser)) { recordService.deleteRecord(id); } } } } return "redirect:/records.html"; }
@RequestMapping(value = "/deleterecord.html", method = RequestMethod.GET) public String deleteRecord(@RequestParam Map<String, Object> map, Map<String, Object> mapresp) { User currentUser = getCurrentUser(); String paramId = (String) map.get("id"); Integer id = null; try { id = Integer.parseInt(paramId); } catch (NumberFormatException e) { id = 0; } Record record = recordService.getRecord(id); if (record != null && record.getUser().equals(currentUser)) { recordService.deleteRecord(id); } return "redirect:/records.html"; }
@RequestMapping(value = "/editrecord.html", method = RequestMethod.GET) public String editRecord(@RequestParam Map<String, Object> map, Map<String, Object> respMap) { String id = (String) map.get("id"); respMap.put("errMesg", map.get("errMesg")); Integer recId = Integer.parseInt(id); Record record = recordService.getRecord(recId); if (record == null || !record.getUser().equals(getCurrentUser())) { return "redirect:/records.html"; } List<FileView> fileDescription = fileDescriptionService.getFilesDescription(record); respMap.put("fileDescription", fileDescription); respMap.put("respMap", respMap); respMap.put("currentuser", getCurrentUser()); respMap.put("accesses", accessService.getAccesses()); respMap.put("record", record); return "addrecord"; }
/** * @param record * @param result * @return */ @RequestMapping(value = "/addrecord.html", method = RequestMethod.POST) public String addRecord( @ModelAttribute("record") Record record, BindingResult result, Map<String, Object> map) { System.out.println("print id " + record.getId()); try { record.setDate(new Date()); record.setUser(getCurrentUser()); record.setRecType(recordTypeService.getRecordType(1)); recordService.saveOrUpdateRecord(record); } catch (Exception e) { e.printStackTrace(); map.put("currentuser", getCurrentUser()); map.put("accesses", accessService.getAccesses()); map.put("record", new Record()); return "addrecord"; } return "redirect:/records.html"; }