Beispiel #1
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();
  }
Beispiel #2
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;
   }
 }
Beispiel #3
0
  @PermitAll
  @GET
  @Path("/institutions")
  @Produces("application/json")
  public List<Institution> listInstitutions() {
    InstitutionDAO institutionDAO = new InstitutionDAO();
    try {
      List<Institution> list = institutionDAO.getAll();

      return list;
    } catch (ForCodeDataException fed) {
      logger.warn(fed);
      return null;
    }
  }