@GET
 @Path("/{isbn}/authors/{id}")
 @Produces(MediaType.APPLICATION_JSON)
 @Consumes(MediaType.APPLICATION_JSON)
 @Timed(name = "view-book-author")
 public Response getAuthorByBook(
     @PathParam("isbn") LongParam isbn, @PathParam("id") LongParam authorId) {
   Author bookAuthor;
   bookAuthor = AuthorHashMap.get(isbn.get()).get(authorId.get());
   AuthorDto authorResponse = new AuthorDto(bookAuthor);
   authorResponse.addLink(
       new LinkDto("view-author", "/books/" + isbn + "/authors/" + authorId, "GET"));
   return Response.ok(authorResponse).build();
 }
  @GET
  @Path("/{isbn}/reviews/{id}")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  @Timed(name = "view-book-review")
  public Response getReview(
      @PathParam("isbn") LongParam isbn, @PathParam("id") LongParam reviewId) {

    Reviews bookReview = BookReviewMap.get(isbn.get()).get(reviewId.get());
    ReviewDto reviewResponse = new ReviewDto(bookReview);
    reviewResponse.addLink(
        new LinkDto("view-review", "/books/" + isbn + "/reviews/" + reviewId, "GET"));
    return Response.ok(reviewResponse).build();
  }
  @GET
  @Path("/{reviewId}")
  @Timed(name = "view-book-by-reviewId")
  public Response viewBookReview(
      @PathParam("isbn") LongParam isbn, @PathParam("reviewId") IntParam reviewId) {

    Book book = bookRepository.getBookByISBN(isbn.get());

    ReviewDto reviewResponse = null;
    List<Review> reviewList = book.getReview();

    List<Review> tempList = new ArrayList<Review>();
    for (Review reviewObj : reviewList) {

      if (reviewObj.getId() == reviewId.get()) tempList.add(reviewObj);
    }
    reviewResponse = new ReviewDto(tempList);
    String location = "/books/" + book.getIsbn() + "/reviews/";

    HashMap<String, Object> map = new HashMap<String, Object>();

    Review review = reviewResponse.getReviewList().get(0);
    map.put("review", review);
    reviewResponse.addLink(new LinkDto("view-review", location + reviewId.get(), "GET"));
    map.put("links", reviewResponse.getLinks());
    return Response.status(200).entity(map).build();
  }
 // ****VIEWING A BOOK****
 @GET
 @Path("/{isbn}")
 @Timed(name = "view-book")
 public BookDto getBookByIsbn(@PathParam("isbn") LongParam isbn) {
   Book book = bookRepository.getBookByISBN(isbn.get());
   BookDto bookResponse = new BookDto(book);
   bookResponse.addLink(new LinkDto("view-book", "/books/" + book.getIsbn(), "GET"));
   bookResponse.addLink(new LinkDto("update-book", "/books/" + book.getIsbn(), "POST"));
   return bookResponse;
 }
  @DELETE
  @Path("/{isbn}")
  @Timed(name = "delete-book")
  public Response deleteBook(@PathParam("isbn") LongParam isbn) {

    book_map.remove(isbn.get());
    LinksDto linkResponse = new LinksDto();
    linkResponse.addLink(new LinkDto("create-book", "/books/", "POST"));
    return Response.ok(linkResponse).build();
  }
  @GET
  @Path("/{isbn}/authors")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  @Timed(name = "view-authors-all-isbn")
  public Response getAllAuthors(@PathParam("isbn") LongParam bookId) {

    Map<Long, Author> authorsMap;
    authorsMap = AuthorHashMap.get(bookId.get());
    AuthorsDto bookResponse = new AuthorsDto(authorsMap.values());
    return Response.ok(bookResponse).build();
  }
  @GET
  @Path("/{isbn}/reviews")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  @Timed(name = "view-all-reviews")
  public Response getAllBookReviews(@PathParam("isbn") LongParam isbn) {

    ArrayList allReviews;
    allReviews = BookReviewMapOne.get(isbn.get());
    ReviewsDto bookResponse = new ReviewsDto(allReviews);
    return Response.ok(bookResponse).build();
  }
  @GET
  @Timed(name = "view-book-review")
  public Response viewAllBookReview(@PathParam("isbn") LongParam isbn, Review request) {

    Book book = bookRepository.getBookByISBN(isbn.get());

    ReviewDto reviewResponse = new ReviewDto(book.getReview());

    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("reviews", reviewResponse.getReviewList());
    map.put("links", new ArrayList<String>());
    return Response.status(200).entity(map).build();
  }
  @POST
  @Timed(name = "create-review")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public Response createReview(@PathParam("isbn") LongParam isbn, Review request) {

    // int rating = request.getRating();

    if (request.getComment() == null) {
      return Response.status(400).type("text/plain").entity(" Comment is a required field").build();
    }

    if (request.getRating() == 0) {
      return Response.status(400)
          .type("text/plain")
          .entity(" Rating is a required field !!!!")
          .build();
    }
    final List<Integer> ratingList = Arrays.asList(1, 2, 3, 4, 5);

    if (!(ratingList.contains(request.getRating()))) {
      return Response.status(400)
          .type("text/plain")
          .entity("Invalid value for Rating. Ratings can be between 1 - 5 stars")
          .build();
    }

    Review reviewObject = bookRepository.createReview(isbn.get(), request);

    Book book = bookRepository.getBookByISBN(isbn.get());

    String location = "/books/" + book.getIsbn() + "/reviews/" + reviewObject.getId();
    BookDto bookResponse = new BookDto(book);
    bookResponse.addLink(new LinkDto("view-review", location, "GET"));

    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("links", bookResponse.getLinks());
    return Response.status(201).entity(map).build();
  }
  /**
   * Generate data for a user
   *
   * @param user the user id
   * @return OK status code
   */
  @GET
  @Path("generate/")
  public Response generateData(@PathParam("user") LongParam user) {
    ArrayList<DeviceUsage> usage;
    ArrayList<Device> devices = this.generateDevices(user.get());
    db.createDevices(devices.iterator());

    for (Device d : devices) {
      usage = generateUsage(d);

      db.addUsageForDevices(usage.iterator());
    }

    return Response.status(Response.Status.OK).build();
  }
 @GET
 @Path("/{isbn}")
 @Timed(name = "view-book")
 public Response getBookByIsbn(@PathParam("isbn") LongParam isbn) {
   {
     Book book = (Book) book_map.get(isbn.get());
     checkNotNull(book, "newBook instance must not be null");
     BookDto bookResponse = new BookDto(book);
     bookResponse.addLink(new LinkDto("view-book", "/books/" + isbn, "GET"));
     bookResponse.addLink(new LinkDto("update-book", "/books/" + isbn, "PUT"));
     bookResponse.addLink(new LinkDto("delete-book", "/books/" + isbn, "DELETE"));
     bookResponse.addLink(new LinkDto("create-review", "/books/" + isbn + "/reviews", "POST"));
     if (reviewsArray.size() > 0)
       bookResponse.addLink(new LinkDto("view-all-reviews", "/books/" + isbn + "/reviews", "GET"));
     return Response.ok(bookResponse).build();
   }
 }
  @PUT
  @Path("/{isbn}")
  @Timed(name = "update-book")
  public Response updateBookStatus(
      @PathParam("isbn") LongParam isbn, @QueryParam("status") String status) {

    Book book = (Book) book_map.get(isbn.get());
    book.setNewStatus(status);
    LinksDto response = new LinksDto();
    response.addLink(new LinkDto("view-book", "/books/" + isbn, "GET"));
    response.addLink(new LinkDto("update-book", "/books/" + isbn, "PUT"));
    response.addLink(new LinkDto("delete-book", "/books/" + isbn, "DELETE"));
    response.addLink(new LinkDto("create-review", "/books/" + isbn + "/reviews", "POST"));
    if (reviewsArray.size() > 0)
      response.addLink(new LinkDto("view-all-reviews", "/books/" + isbn + "/reviews", "GET"));
    return Response.ok(response).build();
  }
  @POST
  @Path("/{isbn}/reviews")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  @Timed(name = "create-book-review")
  public Response createReview(@PathParam("isbn") LongParam isbn, Reviews newReview) {

    Reviews newBookReview = new Reviews();
    Long reviewId = newBookReview.createRevID();
    newReview.setID(reviewId);
    newBookReviewMap.put(reviewId, newReview);
    reviewsArray.add(newReview);
    BookReviewMapOne.put(isbn.get(), reviewsArray);
    LinksDto reviewResponse = new LinksDto();
    reviewResponse.addLink(
        new LinkDto("view-review", "/books/" + isbn + "/reviews/" + reviewId, "GET"));
    return Response.created(null).entity(reviewResponse).build();
  }