Пример #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;
 }
Пример #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;
  }
Пример #3
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;
  }