@Override
  protected Navigation run() throws Exception {
    // TODO Auto-generated method stub
    /*UserService service = new UserService();
    service.removeUserModel(um.getKey());
    return redirect("/");*/
    UserService service = new UserService();
    JSONObject json = new JSONObject();
    UserDto user = new UserDto();

    try {
      json = new JSONObject((String) this.requestScope("data"));
      user.setAddress(json.getString("address"));
      user.setAge(json.getInt("age"));
      // user.setBirthday(Date.parse(json.getString("date"));
      user.setEmail(json.getString("email"));
      // user.setKey(null);
      // user.setImgSrc(json.getString("imgSrc"));
      user.setName(json.getString("name"));
      service.removeUserModel(user);

    } catch (Exception e) {
      e.printStackTrace();
      user.getErrorList().add("Server controller error: " + e.getMessage());
    }
    json.put("user", user.toJSON());
    json.put("errorList", user.getErrorList());
    response.setContentType("application/json");
    response.getWriter().write(json.toString());

    return null;
  }
Ejemplo n.º 2
0
  @RequestMapping(value = "/message", method = RequestMethod.GET)
  public String messageViewGet(HttpServletRequest request, Model model) {

    User receiver = userService.findOne(Long.parseLong(request.getParameter("user_id")));
    Ad relevantAd = new Ad();

    try {
      relevantAd = adService.findOne(Long.parseLong(request.getParameter("ad_id")));
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

    if (relevantAd.getId() != null) {
      model.addAttribute("ad", relevantAd);
    }

    model.addAttribute("receiver", receiver);
    model.addAttribute("message", new Message());

    return "messages/new_message";
  }
Ejemplo n.º 3
0
  @RequestMapping(value = "/message", method = RequestMethod.POST)
  public String messageViewPost(
      HttpServletRequest request, @ModelAttribute("message") Message message, Model model) {

    User sender = (User) request.getSession().getAttribute("user");
    User receiver = userService.findOne(Long.parseLong(request.getParameter("receiver_id")));

    message.setSender(sender);
    message.setReceiver(receiver);
    message.setSendTime((new Date()).getTime());

    try {
      Ad relevantAd = adService.findOne(Long.parseLong(request.getParameter("ad_id")));
      message.setRelevantAd(relevantAd);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

    messageService.save(message);

    model.addAttribute("receiver", receiver);

    return "messages/success";
  }