Example #1
0
  @GET
  @Path("profile")
  @Consumes(MediaType.TEXT_PLAIN)
  @Produces(MediaType.APPLICATION_JSON)
  @Override
  public UserProfileResponse profile(
      @QueryParam("serviceKey") String serviceKey,
      @QueryParam("email") String email,
      @QueryParam("sessionKey") String sessionKey) {
    UserProfileResponse response = new UserProfileResponse();

    AuthenticatedUserRequest request = new AuthenticatedUserRequest() {};
    request.setServiceKey(serviceKey);
    request.setEmail(email);
    request.setSessionKey(sessionKey);

    try {
      securityChecker.checkUserLoggedIn(request);
    } catch (ServiceNotAllowedException e) {
      ServiceNotAllowedJSONException exception =
          new ServiceNotAllowedJSONException("user/profile", request.getServiceKey());
      response.setServiceNotAllowedException(exception);
      return response;
    } catch (UserNotLoggedInException e) {
      UserNotLoggedInJSONException exception = new UserNotLoggedInJSONException("user/profile");
      response.setUserNotLoggedInException(exception);
      return response;
    }

    User user = userService.findUser(email);

    response.setFirstName(user.getFirstName());
    response.setLastName(user.getLastName());
    response.setEmail(user.getEmail());
    response.setRegisteredSince(user.getRegistrationDate());
    response.setRole(user.getRole());
    response.setLoggedInSince(userService.getLogInTime(user, sessionKey));

    return response;
  }