예제 #1
0
  @RolesAllowed(value = {"Manager"})
  @POST
  @Path("/invalidatecontestant")
  @Consumes("application/json")
  @Produces("application/json")
  public Response invalidateContestant(UserContest contestant) {
    UserContestDAO userContestDao = new UserContestDAO();
    ResponseBuilder builder;

    try {
      contestant = userContestDao.getById(contestant.getIdUserContest());
      logger.info("Invalidating contestant");

      if (contestant == null) {
        logger.info("Contestant not found");
        ForCodeError error = ErrorFactory.getErrorFromIndex(ErrorFactory.USER_CONTEST_NOT_FOUND);
        builder = Response.status(Response.Status.NOT_FOUND).entity(error);

      } else {
        contestant.setValid(false);
        userContestDao.update(contestant);

        logger.info("Contestant invalidated " + contestant.getUser().getUsername());
        builder = Response.status(Response.Status.ACCEPTED).entity(contestant);
      }
    } catch (ForCodeDataException fde) {
      logger.warn(fde.getMessage());
      builder = Response.status(Response.Status.BAD_REQUEST).entity(fde);
    }
    return builder.build();
  }
예제 #2
0
  @PermitAll
  @GET
  @Path("/searchuser")
  @Consumes("application/json")
  @Produces("application/json")
  public Response searchUser(@QueryParam("q") String username) {

    logger.info("Searching for user " + username);

    User user = this.findUser(username);

    ResponseBuilder builder;

    if (user == null) {
      ForCodeError error = ErrorFactory.getErrorFromIndex(ErrorFactory.USER_NOT_FOUND);
      builder = Response.status(Response.Status.NOT_FOUND).entity(error);

      logger.info("Unsuccessful attempt to find user.");
    } else {

      user.setPassword(null);
      user.setUserKey(null);

      builder = Response.status(Response.Status.FOUND).entity(user);

      logger.info("Successful attempt to find user.");
    }

    return builder.build();
  }
예제 #3
0
  @PermitAll
  @POST
  @Path("/searchinstitution")
  @Consumes("application/json")
  @Produces("application/json")
  public Response searchInstitution(String institutionName) {

    logger.info("Searching for institution " + institutionName);

    Institution institution = this.findInstitution(institutionName);

    ResponseBuilder builder;

    if (institution == null) {
      ForCodeError error = ErrorFactory.getErrorFromIndex(ErrorFactory.INSTITUTION_NOT_FOUND);
      builder = Response.status(Response.Status.NOT_FOUND).entity(error);

      logger.info("Unsuccessful attempt to find institution.");
    } else {
      builder = Response.status(Response.Status.FOUND).entity(institution);

      logger.info("Successful attempt to find institution.");
    }

    return builder.build();
  }
예제 #4
0
  @PermitAll
  @GET
  @Path("/contestbyid")
  @Consumes("application/json")
  @Produces("application/json")
  public Response seachContestById(@QueryParam("q") Integer idContest) {
    ContestDAO contestDao = new ContestDAO();
    ResponseBuilder builder;

    logger.info("Searching for contest " + idContest);
    try {
      Contest contest = contestDao.getById(idContest);

      if (contest == null) {
        ForCodeError error = ErrorFactory.getErrorFromIndex(ErrorFactory.CONTEST_NOT_EXISTENT);
        builder = Response.status(Response.Status.NOT_FOUND).entity(error);
      } else {
        builder = Response.status(Response.Status.OK).entity(contest);
      }
    } catch (ForCodeDataException fde) {
      logger.warn(fde.getMessage());
      builder = Response.status(Response.Status.BAD_REQUEST).entity(fde);
    }

    return builder.build();
  }
예제 #5
0
  @PermitAll
  @POST
  @Path("/login")
  @Consumes("application/json")
  @Produces("application/json")
  public Response login(@QueryParam("user") String username, String password) {

    username = EncodingUtil.decode(username);

    logger.info(username + " is signing in");

    User user = this.findUser(username);
    ResponseBuilder builder;

    if (user == null) {
      logger.info("Incorrect username: "******"Incorrect password for this username: "******" is logged");

        builder = Response.status(Response.Status.OK).entity(user);
        return builder.build();
      }
    }

    return builder.build();
  }