Esempio n. 1
0
  /** Selects the home page and populates the model with a message */
  @RequestMapping(value = "/addfriend", method = RequestMethod.GET)
  @Transactional
  public String home(Model model, @RequestParam(required = false, value = "id") String id) {
    logger.info("Welcome home!");
    User user = service.getCurrentUser();
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -7);
    if (StringUtils.isEmpty(id)) {
      SocialUserImpl userImpl = socailUserRepo.findOne(user.getId());
      AddFriendLinkImpl link =
          linkRepo.findByUser_IdAndCreateDateGreaterThan(user.getId(), calendar.getTime());
      if (link == null) {
        link = new AddFriendLinkImpl();
        link.setUser(userImpl);
        link.setCreateDate(new Date());
        link = linkRepo.save(link);
      }
      return "redirect:/social/addfriend.do?id=" + link.getId();
    } else {
      AddFriendLinkImpl link = linkRepo.findOne(id);

      boolean expired = calendar.getTime().compareTo(link.getCreateDate()) >= 0;
      model.addAttribute("link", link);
      model.addAttribute("expired", expired);
      boolean self = link.getUser().getId().equals(user.getId());
      model.addAttribute("self", self);
      AddFriendForm form = new AddFriendForm();
      if (!self) {
        SocialRelationshipImpl relation =
            socialRelationRepo.findByFrom_IdAndTo_Id(user.getId(), link.getUser().getId());
        if (relation != null) {
          form.setRating(relation.getRating());
          form.setFriendshipType(ArrayUtil.toLongArray(relation.getRelationType()));
        } else {
          form.setRating(3F);
        }
      } else {
        form.setRating(3f);
      }
      model.addAttribute("addFriendForm", form);
      SocialUserImpl userImpl = socailUserRepo.findOne(user.getId());
      model.addAttribute("hasProfile", user != null);
      model.addAttribute("friendshipTypes", categoryService.findByParent("friendship.type", null));
    }

    return "social.addfriend";
  }
Esempio n. 2
0
  @RequestMapping(value = "/addfriend", method = RequestMethod.POST)
  @Transactional
  public String postAddFriend(
      Model model, final AddFriendForm addFriendForm, BindingResult result) {
    final User user = service.getCurrentUser();
    // from
    SocialUserImpl userImpl = socailUserRepo.findOne(user.getId());
    final AddFriendLinkImpl link = linkRepo.findOne(addFriendForm.getId());
    SocialRelationshipImpl relation =
        socialRelationRepo.findByFrom_IdAndTo_Id(user.getId(), link.getUser().getId());
    if (relation == null) {
      relation = new SocialRelationshipImpl();
      relation.setId(userImpl.getId() + "_" + link.getUser().getId());
      relation.setFrom(userImpl);
      relation.setTo(link.getUser());

      // check whether reverse relation exists
      SocialRelationshipImpl reverse =
          socialRelationRepo.findByFrom_IdAndTo_Id(link.getUser().getId(), userImpl.getId());
      if (reverse == null) {
        // TODO something here
        AddFriendRequestImpl request = new AddFriendRequestImpl();
        request.setFrom(userImpl);
        request.setTo(link.getUser());
        request.setMessage(
            userImpl.getNickname()
                + " accept your add friend link, he also want to add you as friend!");
        request.setType(AddFriendRequestType.CONFIRM);
        request.setCreateDate(new Date());
        addFriendRequestRepo.save(request);
      }
    }
    relation.setLastUpdate(new Date());
    relation.setRating(addFriendForm.getRating());
    relation.setRelationType(Arrays.toString(addFriendForm.getFriendshipType()));
    socialRelationRepo.save(relation);

    // dfggffg
    /**
     * jmsTemplate.send(new MessageCreator() { public Message createMessage(Session session) throws
     * JMSException { // return session.createTextMessage("hello queue world"); AddRelationCommand
     * command = new AddRelationCommand(); command.setFromUser(user.getId());
     * command.setToUser(link.getUser().getId());
     * command.setTypes(addFriendForm.getFriendshipType());
     * command.setRating(addFriendForm.getRating()); return session.createObjectMessage(command); }
     * });
     */
    return "redirect:/user/index.do";
  }