コード例 #1
0
  @RolesAllowed("user")
  @POST
  @Path("/enter")
  @Consumes("application/x-www-form-urlencoded")
  @Produces("application/json")
  public Response enterDebate(
      @FormParam("password") String password,
      @FormParam("idRoom") Integer idRoom,
      @FormParam("login") String login) {

    logger.info("Starting new user entrance");

    OpiningError error = new PolarizedRoomValidation().validateEntrance(password, idRoom, login);
    ResponseBuilder builder;

    if (error == null) {

      PolarizedDebater debater = new PolarizedDebater();
      PolarizedRoom room = new PolarizedRoom();
      User user = new User();

      PolarizedDebaterDAO debaterDAO = new PolarizedDebaterDAO();
      PolarizedRoomDAO polarizedRoomDAO = new PolarizedRoomDAO();
      UserDAO userDAO = new UserDAO();

      user = userDAO.getByLogin(login);
      room = polarizedRoomDAO.getById(idRoom);

      debater.setRoom(room);
      debater.setUser(user);

      debaterDAO.insert(debater);
      debater.setSide(null);

      builder = Response.status(Response.Status.OK).entity(debater);

    } else {

      builder = Response.status(Response.Status.CONFLICT).entity(error);
      logger.warn("User entrance is failed with error code: " + error.getCode());
    }

    return builder.build();
  }
コード例 #2
0
  @POST
  @Path("/leave")
  @Consumes("application/json")
  @Produces("application/json")
  public Response leaveDebate(PolarizedDebater debater) {

    PolarizedDebaterDAO debaterDAO = new PolarizedDebaterDAO();
    ResponseBuilder builder;

    debater.setIsValid(false);
    debaterDAO.update(debater);

    builder = Response.status(Response.Status.OK);

    return builder.build();
  }