Exemplo n.º 1
0
  @GET
  @RolesAllowed({"ADMINISTRATOR"})
  public Response findByFilter() {
    final UserFilter userFilter = new UserUrlFilterExtractor(uriInfo).getFilter();
    logger.debug("Finding users using filter: {}", userFilter);

    final PaginatedData<User> users = userService.find(userFilter);

    logger.debug("Found {} users", users.getNumberOfRows());

    final JsonElement jsonWithPagingAndEntries =
        JsonUtils.getJsonElementWithPagingAndEntries(users, userJsonConverter);
    return Response.status(HttpCode.OK.getCode())
        .entity(JsonWriter.writeToString(jsonWithPagingAndEntries))
        .build();
  }
Exemplo n.º 2
0
  @GET
  @Path("/{id}")
  @RolesAllowed({"ADMINISTRATOR"})
  public Response find(@PathParam("id") final Long id) {
    logger.debug("Find user by id: {}", id);
    Response.ResponseBuilder responseBuilder;
    try {
      User user = userService.find(id);
      OperationResult result =
          OperationResult.success(userJsonConverter.convertToJsonElement(user));
      responseBuilder =
          Response.status(HttpCode.OK.getCode()).entity(OperationResultJsonWriter.toJson(result));
      logger.debug("User found by id: {}", user);
    } catch (UserNotFoundException e) {
      logger.error("No user found for id", id);
      responseBuilder = Response.status(HttpCode.NOT_FOUND.getCode());
    }

    return responseBuilder.build();
  }
Exemplo n.º 3
0
  @POST
  @Path("/authenticate")
  @PermitAll
  public Response findByEmailAndPassword(final String body) {
    logger.debug("Find user by email and password");
    Response.ResponseBuilder responseBuilder;
    try {
      User userWithEmailAndPassword = getUserWithEmailAndPasswordFromJson(body);
      User user =
          userService.find(
              userWithEmailAndPassword.getEmail(), userWithEmailAndPassword.getPassword());
      OperationResult result =
          OperationResult.success(userJsonConverter.convertToJsonElement(user));
      responseBuilder =
          Response.status(HttpCode.OK.getCode()).entity(OperationResultJsonWriter.toJson(result));
      logger.debug("User found by email/password: {}", user);
    } catch (UserNotFoundException e) {
      logger.error("No user found for email/password");
      responseBuilder = Response.status(HttpCode.NOT_FOUND.getCode());
    }

    return responseBuilder.build();
  }