@RolesAllowed(value = {"Admin"}) @POST @Path("/updateadmin") @Consumes("application/json") @Produces("application/json") public Response updateAdmin(Admin admin) { UserDAO userDAO = new UserDAO(); ResponseBuilder builder; ForCodeError error = ForCodeValidator.validateUpdate(admin); try { if (error == null) { userDAO.update(admin); builder = Response.status(Response.Status.OK).entity(admin); logger.info("Admin updated."); } else { System.out.println(error.getMessage()); builder = Response.status(Response.Status.CONFLICT).entity(error); logger.info("Conflict while trying to update Admin."); } } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); builder = Response.status(Response.Status.BAD_REQUEST).entity(fde); } return builder.build(); }
@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(); }
@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(); }
@PermitAll @POST @Path("/createcontestant") @Consumes("application/json") @Produces("application/json") public Response createContestant(Contestant contestant) { UserDAO userDAO = new UserDAO(); ResponseBuilder builder; ForCodeError error = ForCodeValidator.validateInsertion(contestant); try { if (error == null) { userDAO.insert(contestant); builder = Response.status(Response.Status.OK).entity(contestant); logger.info("New Contestant registered."); } else { System.out.println(error.getMessage()); builder = Response.status(Response.Status.CONFLICT).entity(error); logger.info("Conflict while trying to register new contestant."); } } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); builder = Response.status(Response.Status.BAD_REQUEST).entity(fde); } return builder.build(); }
@RolesAllowed(value = {"Admin"}) @POST @Path("/createinstitute") @Consumes("application/json") @Produces("application/json") public Response createInstitution(Institution institution) { InstitutionDAO userDAO = new InstitutionDAO(); ResponseBuilder builder; ForCodeError error = ForCodeValidator.validate(institution); try { if (error == null) { userDAO.insert(institution); builder = Response.status(Response.Status.OK).entity(institution); logger.info("New institution registered."); } else { System.out.println(error.getMessage()); builder = Response.status(Response.Status.CONFLICT).entity(error); logger.info("Conflict while trying to register new institute."); } } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); builder = Response.status(Response.Status.BAD_REQUEST).entity(fde); } return builder.build(); }
private User findUser(String username) { UserDAO userDao = new UserDAO(); try { User user = userDao.getByUsername(username); return user; } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); return null; } }
private Institution findInstitution(String institutionName) { InstitutionDAO institutionDAO = new InstitutionDAO(); try { Institution institution = institutionDAO.getByName(institutionName); return institution; } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); return null; } }
@PermitAll @GET @Path("/problems") @Produces("application/json") public List<Problem> listProblems() { ProblemDAO problemDao = new ProblemDAO(); try { return problemDao.getAll(); } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); return null; } }
@PermitAll @GET @Path("/users") @Produces("application/json") public List<User> listUsers() { UserDAO userDao = new UserDAO(); try { return userDao.getAll(); } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); return null; } }
@PermitAll @GET @Path("/submission") @Produces("application/json") public List<Submission> listSubmissions() { SubmissionDAO submissionDao = new SubmissionDAO(); try { return submissionDao.getAll(); } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); return null; } }
@PermitAll @POST @Path("/contestsbymanager") @Consumes("application/json") @Produces("application/json") public List<Contest> listContestsByProblemSetter(Manager manager) { ContestDAO contestDao = new ContestDAO(); try { return contestDao.getAllByProblemSetter(manager); } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); return null; } }
@PermitAll @GET @Path("/contests") @Consumes("application/json") @Produces("application/json") public List<Contest> listContests() { ContestDAO contestDao = new ContestDAO(); try { return contestDao.getAll(); } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); return null; } }
@PermitAll @POST @Path("/problemsbymanager") @Consumes("application/json") @Produces("application/json") public List<Problem> listProblemsByProblemSetter(Manager problemSetter) { ProblemDAO problemDao = new ProblemDAO(); try { return problemDao.getAllByProblemSetter(problemSetter); } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); return null; } }
@PermitAll @POST @Path("/usersbytype") @Consumes("application/json") @Produces("application/json") public List<User> listAllByType(String type) { UserDAO userDAO = new UserDAO(); try { return userDAO.getAllByTypeUser(type); } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); return null; } }
@PermitAll @POST @Path("/submissionsbycontest") @Consumes("application/json") @Produces("application/json") public List<Submission> listSubmissions(Contest contest) { SubmissionDAO submissionDao = new SubmissionDAO(); if (contest == null) return new ArrayList<Submission>(); try { return submissionDao.getSubmissionsByContest(contest); } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); return new ArrayList<Submission>(); } }
@PermitAll @GET @Path("/contestbyname") @Consumes("application/json") @Produces("application/json") public List<Contest> seachContestByName(@QueryParam("q") String name) { ContestDAO contestDao = new ContestDAO(); logger.info("Searching for contest " + name); try { List<Contest> contests = contestDao.getByName(name); return contests; } catch (ForCodeDataException fde) { logger.warn(fde.getMessage()); return null; } }