@@ -0,0 +1,1967 @@
+package com.google.sps.servlets;%0A%0Aimport com.google.common.collect.ImmutableMap;%0Aimport com.google.sps.data.Book;%0Aimport com.google.sps.data.BookReader;%0Aimport com.google.sps.data.BookUploadUtility;%0Aimport java.io.IOException;%0Aimport java.util.Map;%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.annotation.WebServlet;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0A// Initiate upload books into the books datastore%0A@WebServlet(%22/admin-book-upload%22)%0Apublic class BookUploadServlet extends HttpServlet %7B%0A  private final BookUploadUtility bookUploadUtility = new BookUploadUtility();%0A  private Map%3CInteger, Book%3E bookList;%0A%0A  @Override%0A  public void init() throws ServletException %7B%0A    try %7B%0A      BookReader reader = new BookReader(getServletContext().getRealPath(%22/WEB-INF/20_books.csv%22));%0A      bookList = reader.makeBookList();%0A    %7D catch (Exception ex) %7B%0A      throw new ServletException(%22Error reading CSV file%22, ex);%0A    %7D%0A  %7D%0A%0A  @Override%0A  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException %7B%0A    String failedBooks = %22%5Cn Could not upload: %22;%0A    int successes = 0;%0A    for (Book book : bookList.values()) %7B%0A      try %7B%0A        System.out.println(book.title());%0A        bookUploadUtility.mergeUploadBook(book.title(), book);%0A        System.out.println(%22 -- success!%22);%0A        successes++;%0A      %7D catch (Exception e) %7B%0A        failedBooks += %22%5Cn%5Ct%22 + book.title() + %22 because of %22 + e + %22.%22;%0A        System.out.println(%22 -- failed because of %22 + e + %22.%22);%0A      %7D%0A    %7D%0A    String proportion = %22Uploaded %22 + successes + %22 out of %22 + bookList.values().size() + %22 books.%22;%0A    response.setContentType(%22application/json%22);%0A    if (failedBooks.equals(%22Could not upload: %22)) %7B%0A      response.getWriter().println(%22Data Uploaded!%22);%0A    %7D else %7B%0A      response.getWriter().println(proportion + failedBooks);%0A    %7D%0A  %7D%0A%7D%0A%0A

Create book upload servlet