Пример #1
0
  @GET
  @Path("{userId}/friends")
  public Response getFriends(
      @PathParam("userId") String userId, @QueryParam(LOGGED_IN_USER_QPARAM) String currentUser) {
    List<User> friends = userDao.getFriends(userId, currentUser);
    List<com.campusconnect.neo4j.types.web.User> returnFriends = new ArrayList<>();
    for (User friend : friends) {
      returnFriends.add(Neo4jToWebMapper.mapUserNeo4jToWeb(friend));
    }
    FriendsPage friendsPage = new FriendsPage(0, returnFriends.size(), returnFriends);

    Friends allFriends = new Friends();
    allFriends.setFriends(friendsPage);

    if (currentUser != null && !currentUser.equals(userId)) {
      List<User> mutualFriends = userDao.getMutualFriends(currentUser, userId);
      List<com.campusconnect.neo4j.types.web.User> returnMutualFriends = new ArrayList<>();
      for (User friend : mutualFriends) {
        returnMutualFriends.add(Neo4jToWebMapper.mapUserNeo4jToWeb(friend));
      }
      FriendsPage mutualFriendsPage =
          new FriendsPage(0, returnMutualFriends.size(), returnMutualFriends);
      allFriends.setMutualFriends(mutualFriendsPage);
    }
    return Response.ok().entity(allFriends).build();
  }
Пример #2
0
 @POST
 @Path("{userId}/follow/{followUserId}")
 public Response follow(
     @PathParam("userId") final String userId,
     @PathParam("followUserId") final String followUserId) {
   userDao.createFollowingRelation(userDao.getUser(userId), userDao.getUser(followUserId));
   return Response.ok().build();
 }
Пример #3
0
 @POST
 @Path("{userId}/friend/{friendUserId}")
 public Response addFriend(
     @PathParam("userId") final String userId,
     @PathParam("friendUserId") final String friendUserId) {
   userDao.createFriendRelationWithPending(userDao.getUser(userId), userDao.getUser(friendUserId));
   return Response.ok().build();
   //  return null;
 }
Пример #4
0
 @PUT
 @Path("{userId}/fields")
 public Response updateUserFields(@PathParam("userId") final String userId, Fields fields)
     throws Exception {
   // todo: validate passed fields are valid or not
   User user = userDao.getUser(userId);
   setUpdatedFields(user, fields);
   user.setLastModifiedDate(System.currentTimeMillis());
   User updatedUser = userDao.updateUser(userId, user);
   checkWhetherSynchIsNeeded(updatedUser, fields);
   com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(updatedUser);
   return Response.ok().entity(returnUser).build();
 }
Пример #5
0
  @PUT
  @Path("{userId}/friend/{friendUserId}")
  public Response confirmFriend(
      @PathParam("userId") final String userId,
      @PathParam("friendUserId") final String friendUserId,
      @QueryParam(STATUS_QPARAM) final String status) {
    if (status.toLowerCase().equals("agreed")) {
      userDao.confirmFriendRelation(userDao.getUser(userId), userDao.getUser(friendUserId));
      // TODO:notification to user about acceptance

    } else if (status.toLowerCase().equals("cancel")) {
      userDao.deleteFriendRequest(userId, friendUserId, Constants.FRIEND_REQUEST_CANCEL_DELETE);
    }
    return Response.ok().build();
  }
Пример #6
0
  @POST
  @Path("{userId}/addresses")
  public Response addAddress(
      @PathParam("userId") String userId,
      com.campusconnect.neo4j.types.web.Address addressPayload) {
    Address address = mapAddressWebToNeo4j(addressPayload);
    User user = userDao.getUser(userId);
    // create new address
    Address createdAddress = addressDao.createAddress(address, userId);
    // Link to user
    userDao.addAddressToUser(createdAddress, user);

    com.campusconnect.neo4j.types.web.Address returnAddress = mapAddressNeo4jToWeb(createdAddress);
    return Response.ok().entity(returnAddress).build();
  }
Пример #7
0
 @GET
 @Path("{userId}")
 public Response getUser(@PathParam("userId") final String userId) {
   User user = userDao.getUser(userId);
   com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(user);
   return Response.ok().entity(returnUser).build();
 }
Пример #8
0
 @POST
 @Path("{userId}/reminders")
 public Response createReminder(
     Reminder reminder,
     @PathParam("userId") final String userId,
     @QueryParam(REMINDER_ABOUT_QPARM) final String reminderAbout,
     @QueryParam(CREATED_BY_QPARAM) final String createdBy) {
   setReminderCreateProperties(reminder);
   Reminder createdReminder = reminderDao.createReminder(reminder);
   User reminderForUser = userDao.getUser(userId);
   Long currentTime = System.currentTimeMillis();
   ReminderRelationShip reminderRelationShip =
       new ReminderRelationShip(
           createdBy, currentTime, reminderForUser, currentTime, reminderAbout, reminder);
   userDao.setReminder(reminderRelationShip);
   return Response.created(null).entity(createdReminder).build();
 }
Пример #9
0
 @DELETE
 @Path("{userId}/friend/{friendUserId}")
 public Response unFriend(
     @PathParam("userId") final String userId,
     @PathParam("friendUserId") final String friendUserId) {
   userDao.deleteFriendRequest(userId, friendUserId, Constants.FRIEND_UNFRIEND_DELETE);
   return Response.ok().build();
 }
Пример #10
0
 @PUT
 @Path("{userId}")
 public Response updateUser(
     @PathParam("userId") final String userId,
     com.campusconnect.neo4j.types.web.User userPayload) {
   User user = mapUserWebToNeo4j(userPayload);
   user.setLastModifiedDate(System.currentTimeMillis());
   User updatedUser = userDao.updateUser(userId, user);
   com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(updatedUser);
   return Response.ok().entity(returnUser).build();
 }
Пример #11
0
 @GET
 @Path("{userId}/following")
 public Response getFollowing(@PathParam("userId") final String userId) {
   final List<User> following = userDao.getFollowing(userId);
   List<com.campusconnect.neo4j.types.web.User> returnUsers = new ArrayList<>(following.size());
   for (User user : following) {
     returnUsers.add(Neo4jToWebMapper.mapUserNeo4jToWeb(user));
   }
   UsersPage usersPage = new UsersPage(0, returnUsers.size(), returnUsers);
   return Response.ok().entity(usersPage).build();
 }
Пример #12
0
 @GET
 @Path("{userId}/friends/rec")
 public Response getFriendsRec(
     @PathParam("userId") String userId,
     @QueryParam(SIZE_QPARAM) @DefaultValue("10") final String size,
     @QueryParam(INCLUDE_FRIENDS_QPARAM) @DefaultValue("false") final String includeFriends) {
   // validations
   boolean isIncludeFriends = StringUtils.getBoolean(includeFriends);
   Integer sizeValue = StringUtils.getIntegerValue(size, 10);
   List<FriendRecommendation> friendRecommendations;
   if (isIncludeFriends) {
     friendRecommendations = userDao.getFriendsRecWithFriends(userId, size);
   } else {
     friendRecommendations = userDao.getFriendsRecWithCount(userId, size);
   }
   return Response.ok()
       .entity(
           new FriendRecommendationsPage(friendRecommendations, friendRecommendations.size(), 0))
       .build();
 }
Пример #13
0
 @GET
 @Path("{userId}/search/friends")
 public Response searchFriends(
     @PathParam("userId") String userId, @QueryParam(SEARCH_QPARAM) String searchString) {
   List<User> users = userDao.searchFriends(userId, searchString);
   List<com.campusconnect.neo4j.types.web.User> returnUsers = new ArrayList<>(users.size());
   for (User user : users) {
     returnUsers.add(Neo4jToWebMapper.mapUserNeo4jToWeb(user));
   }
   return Response.ok().entity(new UsersPage(0, returnUsers.size(), returnUsers)).build();
 }
Пример #14
0
 @GET
 @Path("random")
 public Response getRandomUsers(
     @QueryParam("size") @DefaultValue("10") final String size,
     @QueryParam("currentUserId") String currentUser) {
   List<User> userList = userDao.getRandomUsers(Integer.parseInt(size), currentUser);
   List<com.campusconnect.neo4j.types.web.User> returnUsers = new ArrayList<>(userList.size());
   for (User user : userList) {
     returnUsers.add(Neo4jToWebMapper.mapUserNeo4jToWeb(user));
   }
   return Response.ok().entity(new UsersPage(0, returnUsers.size(), returnUsers)).build();
 }
Пример #15
0
 @GET
 @Path("{googleId}/googleId")
 public Response getUserByGoogleId(@PathParam("googleId") final String googleId) {
   User user = userDao.getUserByGoogleId(googleId);
   if (user == null) {
     return Response.status(Response.Status.NOT_FOUND)
         .entity(
             new Neo4jErrorResponse(
                 "NOT_FOUND", "client", "User is nto found with googleId : " + googleId))
         .build();
   }
   return Response.ok().entity(user).build();
 }
Пример #16
0
 @GET
 @Path("fbId/{fbId}")
 public Response getUserByFbId(@PathParam("fbId") final String fbId) {
   User user = userDao.getUserByFbId(fbId);
   if (user == null) {
     return Response.status(Response.Status.NOT_FOUND)
         .entity(
             new Neo4jErrorResponse(
                 "NOT_FOUND", "client", "User is nto found with fbId : " + fbId))
         .build();
   }
   com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(user);
   return Response.ok().entity(returnUser).build();
 }
Пример #17
0
  @POST
  public Response createUser(
      @QueryParam(ACCESS_TOKEN_QPARAM) final String accessToken,
      final com.campusconnect.neo4j.types.web.User userPayload)
      throws URISyntaxException {

    StringBuffer validateUserDataMessage = Validator.validateUserObject(userPayload);
    if (null != validateUserDataMessage) {
      throw new InvalidInputDataException(INVALId_ARGMENTS, validateUserDataMessage.toString());
    }

    User user = mapUserWebToNeo4j(userPayload);

    if (user.getEmail() != null) {
      User existingUser = userDao.getUserByEmail(user.getEmail());
      if (null != existingUser) {
        if (existingUser.getFbId() == null && user.getFbId() != null) {
          existingUser.setFbId(user.getFbId());
          existingUser = userDao.updateUser(existingUser.getId(), existingUser);
        }
        if (existingUser.getGoogleId() == null && user.getGoogleId() != null) {
          existingUser.setGoogleId(user.getGoogleId());
          existingUser = userDao.updateUser(existingUser.getId(), existingUser);
        }
        com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(existingUser);
        return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build();
      }
    }
    if (user.getFbId() != null) {
      User existingUser = userDao.getUserByFbId(user.getFbId());
      if (null != existingUser) {
        com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(existingUser);
        return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build();
      }
    }

    if (user.getGoogleId() != null) {
      User existingUser = userDao.getUserByGoogleId(user.getGoogleId());
      if (null != existingUser) {
        com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(existingUser);
        return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build();
      }
    }
    addPropertiesForCreate(user);
    User createdUser = userDao.createUser(user, accessToken);
    com.campusconnect.neo4j.types.web.User returnUser = mapUserNeo4jToWeb(createdUser);
    return Response.created(new URI("/users/" + returnUser.getId())).entity(returnUser).build();
  }
Пример #18
0
 @DELETE
 @Path("{userId}")
 public Response deleteUser(@PathParam("userId") String userId) {
   userDao.deleteUser(userId);
   return Response.ok().build();
 }
Пример #19
0
 @PUT
 @Path("{userId}/books/wishlist/rec")
 public Response synchWishListRec(@PathParam("userId") final String userId) {
   userDao.synchWishListRec(userId);
   return Response.ok().build();
 }
Пример #20
0
 private void updateUserGoodReadsSynchToInprogress(User user) {
   user.setGoodReadsSynchStatus(IN_PROGRESS_GREADS_STATUS);
   userDao.updateUser(user.getId(), user);
 }
Пример #21
0
 @POST
 @Path("{userId}/goodreads/synch")
 public Response synchGoodreads(@PathParam("userId") final String userId) throws Exception {
   initiateGoodreadsSynch(userDao.getUser(userId));
   return Response.ok().build();
 }