/** 提交并保存支路信息 */ @ResourceMapping(value = "submitCircuitinfoForm") public Resultmsg onSubmitCircuitinfoForm( @ModelAttribute("circuitinfo") Circuitinfo circuitinfo, BindingResult result, SessionStatus status, ResourceRequest request, ResourceResponse response) { Resultmsg msg = new Resultmsg(); boolean isnew = true; if (request.getParameter("isnew") == null) { msg.setMsg("页面缺少新增或编辑标记 isnew"); } else { isnew = Boolean.valueOf(request.getParameter("isnew")); } new CircuitinfoValidator().validate(circuitinfo, result); if (result.hasErrors()) { logger.error(result); msg.setMsg(result.toString()); } else { try { if (isnew) { circuitinfoService.addCircuitinfo(circuitinfo); } else { circuitinfoService.updateCircuitinfo(circuitinfo); } status.setComplete(); msg.setMsg(circuitinfo.getCircuitId()); msg.setSuccess("true"); } catch (Exception e) { logger.error(e); msg.setMsg(e.getMessage()); } } return msg; }
/** * Validates all changes and tries to save them to the database. * * @param principal the user that edited his profile. * @param signupForm the form which contains all information about the principal. * @param result contains error messages. * @param redirectAttributes used to add some attributes to the model. * @param session the current session especially containing the username. * @return the profile page if validations succeeded else returns the editProfile page with * attached errors. */ @RequestMapping(value = "/editProfile", method = RequestMethod.POST) public ModelAndView postProfile( Principal principal, @Validated(SignupForm.SignupValidatorGroup.class) SignupForm signupForm, BindingResult result, RedirectAttributes redirectAttributes, HttpSession session) { User user = userService.getPrincipalUser(); signupForm.setEmail(user.getEmail()); ModelAndView model; try { if (!signupForm.getPassword().equals(signupForm.getPasswordVerify())) { redirectAttributes.addFlashAttribute("passwordVerifyError", "Your passwords do not match!"); redirectAttributes.addFlashAttribute("infoMessage", "Your passwords do not match!"); return new ModelAndView("redirect:/editProfile"); } } catch (Exception d) { } if (!result.hasErrors()) { try { User updatedUser = userService.saveFrom(signupForm, user); userService.createAndSaveUserCoursesFromForm(signupForm, user); redirectAttributes.addFlashAttribute( "infoMessage", "You successfully edited your profile!"); session.setAttribute("username", updatedUser.getWholeName()); model = new ModelAndView("redirect:/profile"); } catch (InvalidUserException e) { model = new ModelAndView("editProfile"); model.addObject("page_error", e.getMessage()); } } else { model = new ModelAndView("editProfile"); model.addObject("infoMessage", result.toString()); System.out.println("Form has errors:\n" + result.toString()); } return model; }
@RequestMapping(value = "/add", method = RequestMethod.POST) @PreAuthorize("hasRole('CTRL_PERM_ADD_POST')") public String addPermission( @Valid @ModelAttribute PermissionDTO permissionDTO, BindingResult result, RedirectAttributes redirectAttrs) { logger.debug("IN: Permission/add-POST"); logger.debug(" DTO: " + permissionDTO.toString()); if (result.hasErrors()) { logger.debug("PermissionDTO add error: " + result.toString()); redirectAttrs.addFlashAttribute( "org.springframework.validation.BindingResult.permissionDTO", result); redirectAttrs.addFlashAttribute("permissionDTO", permissionDTO); return "redirect:/permission/list"; } else { Permission perm = new Permission(); try { perm = getPermission(permissionDTO); permissionService.addPermission(perm); String message = messageSource.getMessage( "ctrl.message.success.add", new Object[] {businessObject, perm.getPermissionname()}, Locale.US); redirectAttrs.addFlashAttribute("message", message); return "redirect:/permission/list"; } catch (DuplicatePermissionException e) { String message = messageSource.getMessage( "ctrl.message.error.duplicate", new Object[] {businessObject, permissionDTO.getPermissionname()}, Locale.US); redirectAttrs.addFlashAttribute("error", message); return "redirect:/permission/list"; } catch (RoleNotFoundException e) { String message = messageSource.getMessage( "ctrl.message.error.notfound", new Object[] {"role ids", permissionDTO.getPermRoles().toString()}, Locale.US); redirectAttrs.addFlashAttribute("error", message); return "redirect:/permission/list"; } } }
// Bestelbon toevoegen @RequestMapping(value = "overzicht", method = RequestMethod.POST) ModelAndView toevoegen( @Valid @ModelAttribute("bestelbon") Bestelbon bestelbon, BindingResult bindingResult) { if (!bindingResult.hasErrors()) { logger.info("Bestelbon word aangemaakt"); bestelbon.setBesteld(new Date()); bestelbon.setBestelbonlijnen(opvragenWijnDetails()); long bestelbonID = bestelbonService.verwerkenBestelbon(bestelbon); mandje.setMandje(new TreeMap<Long, Integer>()); return bevestigd(bestelbonID); } else { logger.info("Bestelbon niet aangemaakt"); logger.info(bindingResult.toString()); return new ModelAndView(VIEW, "mandje", mandje.getMandje()) .addObject("totaalPrijsTeBetalen", totaalPrijsTeBetalen(opvragenWijnDetails())); } }
@Transactional(readOnly = false) @RequestMapping( value = "/edit", method = {RequestMethod.POST, RequestMethod.GET}) public void editor( @RequestParam String oper, @RequestParam(required = false) Long id, Contact contacts, BindingResult result, HttpServletResponse response) throws IOException { if (result.hasErrors()) { response.sendError(400, result.toString()); return; } switch (oper) { case "add": contactRepository.save(contacts); response.setStatus(200); break; case "edit": Contact fromDB = contactRepository.getOne(contacts.getContactId()); if (fromDB != null) { if (contacts.getVersion() >= fromDB.getVersion()) { contactRepository.save(contacts); response.setStatus(200); } else { response.sendError(406, "ANOTHER TRANSACTION MODIFICATION"); } } else { response.sendError(406, "NO CONTACT TYPE FOUND"); } break; case "del": if (id != null) { contactRepository.delete(id); response.setStatus(200); } break; default: response.sendError(406, "UNKNOWN OPERATION"); } }
@Transactional(readOnly = false) @RequestMapping( value = "/edit", method = {RequestMethod.POST, RequestMethod.GET}) public void editor( @RequestParam String oper, Counterparty counterparty, BindingResult result, HttpServletResponse response) throws IOException { if (result.hasErrors()) { response.sendError(400, result.toString()); return; } switch (oper) { case "add": counterpartyRepository.save(counterparty); response.setStatus(200); break; case "edit": Counterparty cpt = counterpartyRepository.findOne(counterparty.getId()); if (counterparty != null) { if (cpt.getVersion() <= counterparty.getVersion()) { cpt.setFullName(counterparty.getFullName()); cpt.setShortName(counterparty.getShortName()); counterpartyRepository.save(cpt); response.setStatus(200); } else { response.sendError(400, "ANOTHER TRANSACTION MODIFICATION!"); } } else { response.sendError(404, "NO Counterpart WITH ID " + counterparty.getId() + " FOUND"); } break; case "del": counterpartyRepository.delete(counterparty.getId()); response.setStatus(200); break; default: response.sendError(406, "UNKNOWN OPERATION"); } }
@Transactional(readOnly = false) @RequestMapping( value = "/editperson", method = {RequestMethod.POST, RequestMethod.GET}) public void personsEditor( @RequestParam String oper, @RequestParam long ID, Person person, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws IOException { if (result.hasErrors()) { response.sendError(400, result.toString()); return; } switch (oper) { case "add": { Counterparty counterparty = counterpartyRepository.findOne(ID); if (counterparty != null) { counterparty.addPerson(person); String headIDS = request.getParameter("headID_primary_key"); if (headIDS != null && !headIDS.isEmpty()) { try { Long headid = Long.getLong(headIDS); Person headPerson = personRepository.findOne(headid); person.setHead(headPerson); } catch (NumberFormatException e) { // do nothing } } personRepository.save(person); counterpartyRepository.save(counterparty); response.setStatus(200); } else { response.sendError(404, "NO COUNTERPART WITH ID " + ID + " FOUND"); } } break; case "edit": { Person prsn = personRepository.findOne(person.getId()); if (prsn != null && prsn.getVersion() <= person.getVersion()) { prsn.setSurname(person.getSurname()); prsn.setFirstName(person.getFirstName()); prsn.setMiddleName(person.getMiddleName()); prsn.setComments(person.getComments()); prsn.setDate_of_birth(person.getDate_of_birth()); String headIDS = request.getParameter("headID_primary_key"); if (headIDS != null && !headIDS.isEmpty()) { try { Long headid = Long.getLong(headIDS); Person headPerson = personRepository.findOne(headid); person.setHead(headPerson); } catch (NumberFormatException e) { // do nothing } } personRepository.save(prsn); response.setStatus(200); } else { response.sendError(404, "NO Agreement WITH ID " + person.getId() + " FOUND"); } } break; case "del": { Counterparty counterparty = counterpartyRepository.findOne(ID); if (counterparty != null) { Person prsn = personRepository.findOne(person.getId()); if (prsn != null) { counterparty.removePerson(prsn); personRepository.delete(prsn); counterpartyRepository.save(counterparty); response.setStatus(200); } else { response.sendError(404, "NO Agreement WITH ID " + person.getId() + " FOUND"); } } else { response.sendError(404, "NO COUNTERPART WITH ID " + ID + " FOUND"); } } break; default: response.sendError(406, "UNKNOWN OPERATION"); } }
@Transactional(readOnly = false) @RequestMapping( value = "/editagreements", method = {RequestMethod.POST, RequestMethod.GET}) public void agrimentsEditor( @RequestParam String oper, @RequestParam long ID, Agreement agreement, BindingResult result, HttpServletResponse response) throws IOException { if (result.hasErrors()) { response.sendError(400, result.toString()); return; } switch (oper) { case "add": { Counterparty counterparty = counterpartyRepository.findOne(ID); if (counterparty != null) { counterparty.addAgreement(agreement); agreementRepository.save(agreement); counterpartyRepository.save(counterparty); response.setStatus(200); } else { response.sendError(404, "NO COUNTERPART WITH ID " + ID + " FOUND"); } } break; case "edit": { Agreement agr = agreementRepository.findOne(agreement.getId()); if (agr != null && agr.getVersion() <= agreement.getVersion()) { agr.setNumber(agreement.getNumber()); agr.setName(agreement.getName()); agr.setStartDate(agreement.getStartDate()); agr.setEndDate(agreement.getEndDate()); agr.setPlanEndDate(agreement.getPlanEndDate()); agreementRepository.save(agr); response.setStatus(200); } else { response.sendError(404, "NO Agreement WITH ID " + agreement.getId() + " FOUND"); } } break; case "del": { Counterparty counterparty = counterpartyRepository.findOne(ID); if (counterparty != null) { Agreement agr = agreementRepository.findOne(agreement.getId()); if (agr != null) { counterparty.removeAgreement(agr); agreementRepository.delete(agr); counterpartyRepository.save(counterparty); response.setStatus(200); } else { response.sendError(404, "NO Agreement WITH ID " + agreement.getId() + " FOUND"); } } else { response.sendError(404, "NO COUNTERPART WITH ID " + ID + " FOUND"); } } break; default: response.sendError(406, "UNKNOWN OPERATION"); } }
@RequestMapping(value = "/edit", method = RequestMethod.POST) @PreAuthorize("hasRole('CTRL_PERM_EDIT_POST')") public String editPermission( @Valid @ModelAttribute PermissionDTO permissionDTO, BindingResult result, RedirectAttributes redirectAttrs, @RequestParam(value = "action", required = true) String action) { logger.debug("IN: Permission/edit-POST: " + action); if (action.equals(messageSource.getMessage("button.action.cancel", null, Locale.US))) { String message = messageSource.getMessage( "ctrl.message.success.cancel", new Object[] {"Edit", businessObject, permissionDTO.getPermissionname()}, Locale.US); redirectAttrs.addFlashAttribute("message", message); } else if (result.hasErrors()) { logger.debug("Permission-edit error: " + result.toString()); redirectAttrs.addFlashAttribute( "org.springframework.validation.BindingResult.permissionDTO", result); redirectAttrs.addFlashAttribute("permissionDTO", permissionDTO); return "redirect:/permission/edit?id=" + permissionDTO.getId(); } else if (action.equals(messageSource.getMessage("button.action.save", null, Locale.US))) { logger.debug("Permission/edit-POST: " + permissionDTO.toString()); try { Permission permission = getPermission(permissionDTO); permissionService.updatePermission(permission); String message = messageSource.getMessage( "ctrl.message.success.update", new Object[] {businessObject, permissionDTO.getPermissionname()}, Locale.US); redirectAttrs.addFlashAttribute("message", message); } catch (DuplicatePermissionException unf) { String message = messageSource.getMessage( "ctrl.message.error.duplicate", new Object[] {businessObject, permissionDTO.getPermissionname()}, Locale.US); redirectAttrs.addFlashAttribute("error", message); return "redirect:/permission/list"; } catch (PermissionNotFoundException unf) { String message = messageSource.getMessage( "ctrl.message.error.notfound", new Object[] {businessObject, permissionDTO.getPermissionname()}, Locale.US); redirectAttrs.addFlashAttribute("error", message); return "redirect:/permission/list"; } catch (RoleNotFoundException unf) { String message = messageSource.getMessage( "ctrl.message.error.notfound", new Object[] {"role ids", permissionDTO.getPermRoles().toString()}, Locale.US); redirectAttrs.addFlashAttribute("error", message); return "redirect:/permission/list"; } } return "redirect:/permission/list"; }