コード例 #1
0
  @POST()
  @Path("New")
  public Response New(
      String siteInfo,
      @Context HttpServletResponse servletResponse,
      @Context SecurityContext context) {
    if (!context.isUserInRole(Roles.REG_USER)) {
      return Response.status(500).entity(GeoRedConstants.ACCESS_DENIED).build();
    }

    Response response;

    try {
      Gson gson = new Gson();
      String json = siteInfo.split("=")[1];
      Site site = gson.fromJson(json, Site.class);
      SitesController.getInstance().NewSite(site);

      response = Response.status(200).entity(GeoRedConstants.SITE_SUCCESSFULY_ADDED).build();
    } catch (Exception e) {
      response = Response.status(500).entity(e.getMessage()).build();
    }

    return response;
  }
コード例 #2
0
  // crear comentario. recibe un Comment.
  @POST()
  @Path("Comments/New")
  public Response CommentsNew(
      String commentInfo,
      @Context HttpServletResponse servletResponse,
      @Context SecurityContext context) {
    // si no es un usuario registrado, devolver error 500 de acceso denegado
    if (!context.isUserInRole(Roles.REG_USER)) {
      return Response.status(500).entity(GeoRedConstants.ACCESS_DENIED).build();
    }

    // crear comentario
    try {
      Gson gson = new Gson();
      commentInfo = commentInfo.split("=")[1];
      Comment comment = gson.fromJson(commentInfo, Comment.class);
      SitesController.getInstance().newComment(comment);

      return Response.status(200).entity(GeoRedConstants.COMMENT_SUCCESSFULY_ADDED).build();
    }

    // si salta una excepción, devolver error
    catch (Exception ex) {
      return Response.status(500).entity(ex.getMessage()).build();
    }
  }
コード例 #3
0
  @POST
  @Path("/add")
  @Consumes("multipart/form-data")
  public Response addSite(@MultipartForm AddSiteForm form) {
    Response ret;
    try {
      Site site = new Site();
      site.setName(form.getName());
      site.setAddress(form.getAddress());
      Double[] coordinates = new Double[2];
      coordinates[1] = Double.valueOf(form.getLatitude());
      coordinates[0] = Double.valueOf(form.getLongitude());
      site.setCoordinates(coordinates);
      site.setDescription(form.getDescription());
      site.setImage(form.getImageData());
      site.setRadius(Integer.valueOf(form.getRadius()));
      if (form.getTags() != null && !form.getTags().isEmpty()) {
        site.setName(form.getName());
        String[] tagsStr = form.getTags().trim().split(",");
        for (String tagStr : tagsStr) {
          Tag tag = new Tag();
          tag.setName(tagStr.trim());
          site.addTag(tag);
        }
      }
      SitesController.getInstance().NewSite(site);
      ret = Response.seeOther(new URI("../GeoRedUy.BackEnd/site?ListSites")).build();
    } catch (Exception e) {
      e.printStackTrace();
      ret = Response.serverError().entity(e.getMessage()).build();
    }

    return ret;
  }
コード例 #4
0
  // obtener datos de una visita.
  // recibe un String con el id, y devuelve un Site.
  @GET()
  @Produces("text/plain")
  @Path("GetById")
  public Response GetById(
      @QueryParam("siteId") String siteId,
      @Context HttpServletResponse servletResponse,
      @Context SecurityContext context) {
    if (!context.isUserInRole(Roles.REG_USER)) {
      return Response.status(500).entity(GeoRedConstants.ACCESS_DENIED).build();
    }

    // obtener visita
    try {
      Gson gson = new Gson();

      Site site = SitesController.getInstance().getById(siteId);

      return Response.status(200).entity(gson.toJson(site)).build();
    }

    // si salta una excepción, devolver error
    catch (Exception ex) {
      return Response.status(500).entity(ex.getMessage()).build();
    }
  }
コード例 #5
0
  // obtener sitios, por pagina
  @GET()
  @Produces("text/plain")
  @Path("GetPage")
  public Response GetPaged(
      @QueryParam("from") Integer from,
      @QueryParam("count") Integer count,
      @Context HttpServletResponse servletResponse,
      @Context SecurityContext context) {
    if (!context.isUserInRole(Roles.REG_USER)) {
      return Response.status(500).entity(GeoRedConstants.ACCESS_DENIED).build();
    }

    if (count == null) count = 15;
    if (from == null) from = 0;

    Gson gson = new Gson();
    List<Site> sites = SitesController.getInstance().getSites(from, count);
    return Response.status(200).entity(gson.toJson(sites)).build();
  }
コード例 #6
0
  // obtener sitios
  @GET()
  @Produces("text/plain")
  @Path("Get")
  public Response Get(@Context SecurityContext context) {
    if (!context.isUserInRole(Roles.REG_USER)) {
      return Response.status(500).entity(GeoRedConstants.ACCESS_DENIED).build();
    }

    // obtener sitios
    try {
      Gson gson = new Gson();
      List<Site> sites = SitesController.getInstance().getSites();
      return Response.status(200).entity(gson.toJson(sites)).build();
    }

    // si salta una excepción, devolver error
    catch (Exception ex) {
      return Response.status(500).entity(ex.getMessage()).build();
    }
  }
コード例 #7
0
  // obtener comentarios del usuario
  @GET()
  @Produces("text/plain")
  @Path("Comments/GetByUser")
  public Response CommentsGetByUser(@Context SecurityContext context) {
    if (!context.isUserInRole(Roles.REG_USER)) {
      return Response.status(500).entity(GeoRedConstants.ACCESS_DENIED).build();
    }

    // obtener comentarios del usuario
    try {
      Gson gson = new Gson();
      List<Comment> comments = SitesController.getInstance().getCommentsByUser();
      return Response.status(200).entity(gson.toJson(comments)).build();
    }

    // si salta una excepción, devolver error
    catch (Exception ex) {
      return Response.status(500).entity(ex.getMessage()).build();
    }
  }
コード例 #8
0
  // obtener visitas del usuario, sistema paginado
  @GET()
  @Produces("text/plain")
  @Path("Visits/GetByUserPage")
  public Response VisitsGetByUserPage(
      @QueryParam("pageNumber") Integer pageNumber, @Context SecurityContext context) {
    if (!context.isUserInRole(Roles.REG_USER)) {
      return Response.status(500).entity(GeoRedConstants.ACCESS_DENIED).build();
    }

    // obtener visitas del usuario
    try {
      Gson gson = new Gson();
      List<Visit> visits = SitesController.getInstance().getVisitsByUser(pageNumber);
      return Response.status(200).entity(gson.toJson(visits)).build();
    }

    // si salta una excepción, devolver error
    catch (Exception ex) {
      return Response.status(500).entity(ex.getMessage()).build();
    }
  }
コード例 #9
0
  @GET()
  @Produces("text/plain")
  @Path("GetByLocation")
  public Response GetByLocation(
      @QueryParam("bottomLeftLatitude") Integer bottomLeftLatitude,
      @QueryParam("bottomLeftLongitude") Integer bottomLeftLongitud,
      @QueryParam("topRightLatitude") Integer topRightLatitude,
      @QueryParam("topRightLongitude") Integer topRightLongitude,
      @Context SecurityContext context) {
    if (!context.isUserInRole(Roles.REG_USER)) {
      return Response.status(500).entity(GeoRedConstants.ACCESS_DENIED).build();
    }

    Gson gson = new Gson();
    List<Site> sites =
        SitesController.getInstance()
            .getSitesByPosition(
                bottomLeftLatitude, bottomLeftLongitud, topRightLatitude, topRightLongitude);

    return Response.status(200).entity(gson.toJson(sites)).build();
  }
コード例 #10
0
  @GET()
  @Produces("image/jpg")
  @Path("GetImageById")
  public Response GetImageById(
      @QueryParam("siteId") String siteId,
      @Context HttpServletResponse servletResponse,
      @Context SecurityContext context) {
    /*if (!context.isUserInRole(Roles.REG_USER)) {
    	return Response.status(500).entity(GeoRedConstants.ACCESS_DENIED)
    			.build();
    }*/

    try {
      byte[] image = SitesController.getInstance().getSiteImage(siteId);
      return Response.status(200).entity(image).build();
    }

    // si salta una excepción, devolver error
    catch (Exception ex) {
      return Response.status(500).entity(ex.getMessage()).build();
    }
  }