@RolesAllowed("user")
  @POST
  @Path("/create")
  @Consumes("application/json")
  @Produces("application/json")
  public Response createDebate(NewPolarizedRoom newDebate) {

    logger.info("Starting new room creating");

    OpiningError error = new PolarizedRoomValidation().validateInsertion(newDebate);
    ResponseBuilder builder;

    if (error == null) {

      UserDAO userDAO = new UserDAO();
      User user = userDAO.getByLogin(newDebate.getCreator().getLogin());
      newDebate.setCreator(user);

      PolarizedRoom polarizedRoom = newDebate.toPolarizedRoom();

      PolarizedRoomDAO polarizedRoomDAO = new PolarizedRoomDAO();
      polarizedRoomDAO.insert(polarizedRoom);

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

      logger.info("Room succefully created");

    } else {
      builder = Response.status(Response.Status.CONFLICT).entity(error);
      logger.warn("Room creation is failed with error code: " + error.getCode());
    }

    return builder.build();
  }
  @RolesAllowed("user")
  @POST
  @Path("/list/subject")
  @Produces("application/json")
  public Response listDebatesBySubject(@QueryParam("q") String subject) {

    PolarizedRoomDAO polarizedRoomDAO = new PolarizedRoomDAO();

    List<PolarizedRoom> polarizedRoom = polarizedRoomDAO.getBySubject(subject);

    ResponseBuilder builder;

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

    return builder.build();
  }
  @RolesAllowed("user")
  @GET
  @Path("/list")
  @Produces("application/json")
  public Response listDebates() {

    PolarizedRoomDAO polarizedRoomDAO = new PolarizedRoomDAO();

    List<PolarizedRoom> polarizedRoom = polarizedRoomDAO.getAll();

    ResponseBuilder builder;

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

    return builder.build();
  }
  @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();
  }