Exemplo n.º 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();
  }
Exemplo n.º 2
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();
  }
Exemplo n.º 3
0
  @RolesAllowed(value = {"Admin"})
  @POST
  @Path("/createmanager")
  @Consumes("application/json")
  @Produces("application/json")
  public Response createManager(Manager manager) {
    UserDAO userDAO = new UserDAO();
    ResponseBuilder builder;

    ForCodeError error = ForCodeValidator.validateInsertion(manager);
    try {
      if (error == null) {
        userDAO.insert(manager);
        builder = Response.status(Response.Status.OK).entity(manager);
        logger.info("New Manager registered.");
      } else {
        logger.info(error.getMessage());
        builder = Response.status(Response.Status.CONFLICT).entity(error);
        logger.info("Conflict while trying to register new Manager.");
      }
    } catch (ForCodeDataException fde) {
      logger.warn(fde.getMessage());
      builder = Response.status(Response.Status.BAD_REQUEST).entity(fde);
    }

    return builder.build();
  }
Exemplo n.º 4
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;
   }
 }
Exemplo n.º 5
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;
   }
 }
Exemplo n.º 6
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;
   }
 }