Beispiel #1
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();
  }
Beispiel #2
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();
 }
Beispiel #3
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();
 }
Beispiel #4
0
 private void updateUserGoodReadsSynchToInprogress(User user) {
   user.setGoodReadsSynchStatus(IN_PROGRESS_GREADS_STATUS);
   userDao.updateUser(user.getId(), user);
 }