@SuppressWarnings("unchecked") @GET @Produces(MediaType.APPLICATION_JSON) public Response volumes( @QueryParam("categoryId") Long categoryId, @QueryParam("page") Integer page, @QueryParam("q") String q) { Volumes volumes = new Volumes(); VolumeDAO volumeDAO = DAOFactory.getInstance().getVolumeDAO(); FullTextSession fts = org.hibernate.search.Search.getFullTextSession(volumeDAO.getSession()); try { Query query = buildLuceneQuery(categoryId, page, q); FullTextQuery createFullTextQuery = fts.createFullTextQuery(query, com.book.identification.model.Volume.class); addPaginationToQuery(createFullTextQuery, page); List<Volume> list = createFullTextQuery.list(); for (Volume volume : list) { volume.setPage(page); volume.setQ(q); } volumes.setVolumes(createFullTextQuery.list()); } catch (ParseException e1) { e1.printStackTrace(); } if (volumes.getVolumes().isEmpty()) { return Response.ok("volumes : {}").build(); } return Response.ok(volumes).build(); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("hash/") public Response hashing() throws IOException { VolumeDAO volumeDAO = DAOFactory.getInstance().getVolumeDAO(); List<Volume> findAll = volumeDAO.findAll(); Transaction beginTransaction = volumeDAO.getSession().beginTransaction(); for (Volume volume : findAll) { String fileSHA1 = DigestUtils.shaHex(FileUtils.openInputStream(new File(volume.getPath()))); volume.setHashSH1(fileSHA1); } beginTransaction.commit(); return Response.ok("hashed").build(); }