Example #1
0
  // remove photo api
  @Override
  @DELETE
  @Path("/remove")
  @Produces(MediaType.APPLICATION_XML)
  @Transactional(propagation = Propagation.NESTED)
  public Response removePhoto(Integer photoId, @Context HttpServletRequest request) {

    try {

      Photo photo = photoDao.load(photoId);
      Token tokenObj = (Token) request.getAttribute("token");
      User user = tokenObj.getUser();
      if (user.equals(photo.getUser())) {

        new File(photo.getPath()).delete(); // delete the file
        photoDao.delete(photo);
      }
      GetPhotoResponseDTO dto = buildDTO(200, null);
      dto.setImageId(photoId);
      return Response.status(200).entity(dto).build();
    } catch (HibernateException e) {

      e.printStackTrace();
      return Response.status(500).entity(buildDTO(500, null)).build();
    }
  }