コード例 #1
0
ファイル: UserResource.java プロジェクト: sudhavn/neo4j-akka
 @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();
 }
コード例 #2
0
ファイル: UserResource.java プロジェクト: sudhavn/neo4j-akka
  @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();
  }