示例#1
0
  @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();
  }
示例#2
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();
  }
示例#3
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();
  }
示例#4
0
  @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();
  }
示例#5
0
  @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();
  }
示例#6
0
 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;
   }
 }
示例#7
0
 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;
   }
 }
示例#8
0
 @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;
   }
 }
示例#9
0
 @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;
   }
 }
示例#10
0
 @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;
   }
 }
示例#11
0
 @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;
   }
 }
示例#12
0
 @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;
   }
 }
示例#13
0
 @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;
   }
 }
示例#14
0
 @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;
   }
 }
示例#15
0
  @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>();
    }
  }
示例#16
0
  @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;
    }
  }