public void postObject(
      HttpServletResponse response, HttpServletRequest request, Message message) {
    List<User> users = new ArrayList<User>(message.getUsers());
    message.getUsers().clear();

    for (OrganisationUnit ou : message.getOrganisationUnits()) {
      OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou.getUid());

      if (organisationUnit == null) {
        ContextUtils.conflictResponse(response, "Organisation Unit does not exist: " + ou.getUid());
        return;
      }

      message.getUsers().addAll(organisationUnit.getUsers());
    }

    for (User u : users) {
      User user = userService.getUser(u.getUid());

      if (user == null) {
        ContextUtils.conflictResponse(response, "User does not exist: " + u.getUid());
        return;
      }

      message.getUsers().add(user);
    }

    for (UserGroup ug : message.getUserGroups()) {
      UserGroup userGroup = userGroupService.getUserGroup(ug.getUid());

      if (userGroup == null) {
        ContextUtils.conflictResponse(response, "User Group does not exist: " + ug.getUid());
        return;
      }

      message.getUsers().addAll(userGroup.getMembers());
    }

    if (message.getUsers().isEmpty()) {
      ContextUtils.conflictResponse(response, "No recipients selected.");
      return;
    }

    String metaData =
        MessageService.META_USER_AGENT + request.getHeader(ContextUtils.HEADER_USER_AGENT);

    int id =
        messageService.sendMessage(
            message.getSubject(), message.getText(), metaData, message.getUsers());

    MessageConversation conversation = messageService.getMessageConversation(id);

    ContextUtils.createdResponse(
        response,
        "Message conversation created",
        MessageConversationController.RESOURCE_PATH + "/" + conversation.getUid());
  }
Пример #2
0
  @RequestMapping(value = "signup", method = RequestMethod.POST)
  public String signup(
      @Valid @ModelAttribute SignupForm signupForm, Errors errors, RedirectAttributes ra) {
    if (errors.hasErrors()) {
      return null;
    }

    Account account = accountRepository.save(signupForm.createAccount());
    userService.signin(account);

    MessageHelper.addSuccessAttribute(ra, "Congratulations! You have successfully signed up.");

    return "redirect:/";
  }
 @RequestMapping(value = "/create", method = RequestMethod.POST)
 public String create(
     @Valid @ModelAttribute AccountForm accountForm,
     Errors errors,
     RedirectAttributes ra,
     Model model) {
   if (errors.hasErrors()) {
     MessageHelper.addErrorAttribute(model, "account.create.failed");
     return "account/create";
   }
   Account employeeAccount = accountForm.createEmployeeAccount();
   userService.createAccount(employeeAccount);
   LOG.info("Created new employee account with id={}", employeeAccount.getId());
   MessageHelper.addSuccessAttribute(ra, "account.create.success");
   return "redirect:/account/list";
 }
Пример #4
0
 private Topic createCodeReviewWithLockHandling(Topic topic, TopicDto topicDto)
     throws NotFoundException {
   for (int i = 0; i < UserController.LOGIN_TRIES_AFTER_LOCK; i++) {
     try {
       return topicModificationService.createTopic(topic, topicDto.getBodyText());
     } catch (HibernateOptimisticLockingFailureException e) {
     }
   }
   try {
     return topicModificationService.createTopic(topic, topicDto.getBodyText());
   } catch (HibernateOptimisticLockingFailureException e) {
     LOGGER.error(
         "User has been optimistically locked and can't be reread {} times. Username: {}",
         UserController.LOGIN_TRIES_AFTER_LOCK,
         userService.getCurrentUser().getUsername());
     throw e;
   }
 }