Esempio n. 1
0
 /**
  * @param params
  * @param request
  * @param response
  * @return
  * @throws RepositoryException
  * @throws JCRNodeFactoryServiceException
  * @throws IOException
  */
 private Map<String, Object> doRequestConnect(
     FriendsParams params, HttpServletRequest request, HttpServletResponse response)
     throws JCRNodeFactoryServiceException, RepositoryException, IOException {
   FriendsBean myFriends = friendsResolverService.resolve(params.uuid);
   FriendsBean friendFriends = friendsResolverService.resolve(params.friendUuid);
   if (myFriends.hasFriend(params.friendUuid) || friendFriends.hasFriend(params.uuid)) {
     throw new RestServiceFaultException(
         HttpServletResponse.SC_CONFLICT,
         "There is already a connection invited, pending or accepted ");
   }
   FriendBean friend = new FriendBean(params.uuid, params.friendUuid, FriendStatus.PENDING);
   FriendBean me = new FriendBean(params.friendUuid, params.uuid, FriendStatus.INVITED);
   if (!StringUtils.isEmpty(params.type)) {
     me.setProperties(ImmutableMap.of("type", params.type, "message", params.message));
     friend.setProperties(ImmutableMap.of("type", params.type, "message", params.message));
   }
   myFriends.addFriend(friend);
   friendFriends.addFriend(me);
   authzResolverService.setRequestGrant("Saving Request Connect");
   try {
     myFriends.save();
     friendFriends.save();
     jcrService.getSession().save();
   } finally {
     authzResolverService.clearRequestGrant();
   }
   return OK;
 }
Esempio n. 2
0
  /**
   * @param params
   * @param request
   * @param response
   * @return
   * @throws RepositoryException
   * @throws JCRNodeFactoryServiceException
   * @throws IOException
   */
  private Map<String, Object> doIgnoreConnect(
      FriendsParams params, HttpServletRequest request, HttpServletResponse response)
      throws JCRNodeFactoryServiceException, RepositoryException, IOException {
    FriendsBean myFriends = friendsResolverService.resolve(params.uuid);
    FriendsBean friendFriends = friendsResolverService.resolve(params.friendUuid);
    if (!myFriends.hasFriend(params.friendUuid) || !friendFriends.hasFriend(params.uuid)) {
      throw new RestServiceFaultException(
          HttpServletResponse.SC_NOT_FOUND, " The friend connection is missing ");
    }
    FriendBean myFriendBean = myFriends.getFriend(params.friendUuid);
    FriendBean friendFriendBean = friendFriends.getFriend(params.uuid);
    if (!myFriendBean.isInState(FriendStatus.INVITED)
        || !friendFriendBean.isInState(FriendStatus.PENDING)) {
      throw new RestServiceFaultException(
          HttpServletResponse.SC_CONFLICT, "The invitation to connect is not current");
    }

    myFriends.removeFriend(params.friendUuid);
    friendFriends.removeFriend(params.uuid);
    authzResolverService.setRequestGrant("Saving Ignore Connect");
    try {
      myFriends.save();
      friendFriends.save();
      jcrService.getSession().save();
    } finally {
      authzResolverService.clearRequestGrant();
    }
    return OK;
  }
Esempio n. 3
0
  /**
   * @param params
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @throws RepositoryException
   * @throws UnsupportedEncodingException
   */
  private Map<String, Object> doStatus(
      FriendsParams params, HttpServletRequest request, HttpServletResponse response)
      throws UnsupportedEncodingException, RepositoryException, IOException {
    FriendsBean myFriends = friendsResolverService.resolve(params.uuid);

    Query query = null;
    StringBuilder sb = new StringBuilder();
    sb.append(FriendsIndexBean.FINDBY_UUID_WITH_SORT);
    if (params.filterStatus != null) {
      sb.append(" and ")
          .append(FriendsIndexBean.FRIENDS_STATUS_FIELD)
          .append(" = :")
          .append(FriendsIndexBean.PARAM_FRIENDSTATUS);
    }
    if (params.sort != null && params.sort.length > 0) {
      sb.append(" order by ");
      for (int i = 0; i < params.sort.length; i++) {
        if (i != 0) {
          sb.append(",");
        }
        sb.append(" s.").append(params.sort[i]);
        if (params.sortOrder != null && params.sortOrder.length == params.sort.length) {
          sb.append(" ").append(params.sortOrder[i]);
        }
      }
    }
    query = entityManager.createQuery(sb.toString());

    query.setFirstResult(params.start);
    query.setMaxResults(params.end);
    query.setParameter(FriendsIndexBean.PARAM_UUID, params.uuid);
    if (params.filterStatus != null) {
      query.setParameter(FriendsIndexBean.PARAM_FRIENDSTATUS, params.filterStatus.toString());
    }

    List<?> results = query.getResultList();
    System.err.println(" Results: " + results.size());

    Map<String, FriendBean> myFriendMap = myFriends.friendsMap();
    Map<String, FriendBean> sortedFriendMap = Maps.newLinkedHashMap();
    for (Object fio : results) {
      FriendsIndexBean fi = (FriendsIndexBean) fio;
      FriendBean fb = myFriendMap.get(fi.getFriendUuid());
      if (fb != null) {
        sortedFriendMap.put(fb.getFriendUuid(), fb);
        UserProfile profile = profileResolverService.resolve(fb.getFriendUuid());
        fb.setProfile(profile.getProperties());
        Map<String, String> properties = fb.getProperties();
        properties.put(
            "userStoragePrefix", userFactoryService.getUserPathPrefix(fb.getFriendUuid()));
        fb.setProperties(properties);
      }
    }
    myFriends.setFriends(Lists.newArrayList(sortedFriendMap.values()));

    return ImmutableMap.of("response", "OK", "status", myFriends);
  }
Esempio n. 4
0
  /**
   * @param params
   * @param request
   * @param response
   * @return
   * @throws RepositoryException
   * @throws JCRNodeFactoryServiceException
   * @throws IOException
   */
  private Map<String, Object> doRemoveConnect(
      FriendsParams params, HttpServletRequest request, HttpServletResponse response)
      throws JCRNodeFactoryServiceException, RepositoryException, IOException {
    FriendsBean myFriends = friendsResolverService.resolve(params.uuid);
    FriendsBean friendFriends = friendsResolverService.resolve(params.friendUuid);
    if (!myFriends.hasFriend(params.friendUuid) || !friendFriends.hasFriend(params.uuid)) {
      throw new RestServiceFaultException(
          HttpServletResponse.SC_NOT_FOUND, " The friend connection is missing ");
    }
    myFriends.removeFriend(params.friendUuid);
    friendFriends.removeFriend(params.uuid);

    authzResolverService.setRequestGrant("Saving Remove Connect");
    try {
      myFriends.save();
      friendFriends.save();
      jcrService.getSession().save();
    } finally {
      authzResolverService.clearRequestGrant();
    }
    return OK;
  }