コード例 #1
0
  @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";
  }
コード例 #2
0
  @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;
  }
コード例 #3
0
  @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();
  }
コード例 #4
0
 @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()));
 }
コード例 #5
0
 @RequestMapping(value = "/sendPublicMessage", method = RequestMethod.POST)
 public @ResponseBody void sendPublicMessage(
     @RequestParam("pubmessage") String message,
     @ModelAttribute("currentUser") CurrentUser currentUser) {
   messageService.sendPublicMessage(currentUser, message);
 }
コード例 #6
0
 @RequestMapping(value = "/getMessages", method = RequestMethod.GET)
 @ResponseBody
 public List<PublicMessage> getPublicMessages() {
   return messageService.getAllPublicMessages();
 }