@RequestMapping(value = "/message", method = RequestMethod.POST) public String handleMessageSendForm( @ModelAttribute("currentUser") CurrentUser currentUser, @Valid @ModelAttribute("form") MessageForm form, BindingResult bindingResult) { LOGGER.debug("Processing message send form={}, bindingResult={}", form, bindingResult); if (bindingResult.hasErrors()) { // failed validation return "message"; } try { if (currentUserDetailsService.checkUserRole(form.getRecipient()) == Role.ADMIN) { messageService.sendMessageM(form, currentUser); } else { messageService.sendMessage(form, currentUser); } } catch (DataIntegrityViolationException e) { // probably email already exists - very rare case when multiple admins are adding same user // at the same time and form validation has passed for more than one of them. // LOGGER.warn("Exception occurred when trying to save the user, assuming duplicate // email", e); return "message"; } // ok, redirect return "redirect:/message"; }
@RequestMapping(value = "/hasnewmessage", method = RequestMethod.GET) @ResponseBody public Boolean hasNewMessage(@ModelAttribute("currentUser") CurrentUser currentUser) { LOGGER.debug("Checking if there is a any new message"); messagesCounter = messageService.getMessagesQuantity(currentUser); Collection<Message> messages = messageService.getAllMessages(currentUser.getUser()); if (messages.size() > messagesCounter) { messageService.saveMessageQuantity(messages.size(), currentUser); messagesCounter = messages.size(); return true; } return false; }
@RequestMapping(value = "/howmanymessages", method = RequestMethod.GET) @ResponseBody public Integer howManyMessages(@ModelAttribute("currentUser") CurrentUser currentUser) { LOGGER.debug("Checking how many messages user have"); Collection<Message> messages = messageService.getAllMessages(currentUser.getUser()); return messages.size(); }
@RequestMapping(value = "/messages", method = RequestMethod.GET) public ModelAndView getMessagesPage(@ModelAttribute("currentUser") CurrentUser currentUser) { LOGGER.debug("Getting messages page"); return new ModelAndView( "messages", "messages", messageService.getAllMessages(currentUser.getUser())); }
@RequestMapping(value = "/sendPublicMessage", method = RequestMethod.POST) public @ResponseBody void sendPublicMessage( @RequestParam("pubmessage") String message, @ModelAttribute("currentUser") CurrentUser currentUser) { messageService.sendPublicMessage(currentUser, message); }
@RequestMapping(value = "/getMessages", method = RequestMethod.GET) @ResponseBody public List<PublicMessage> getPublicMessages() { return messageService.getAllPublicMessages(); }