@SuppressWarnings("unchecked")
 @ProcessAction(name = "addBookAction")
 public void addBook(ActionRequest request, ActionResponse response)
     throws PortletException, IOException {
   logger.info("addBook action invoked");
   if (!request.isUserInRole("administrator")) {
     response.setRenderParameter("myaction", "error");
     response.setRenderParameter(
         "exceptionMsg",
         "You are not authorized for this action. You must have Administrator role.");
     return;
   }
   request.setAttribute("myaction", "addBookAction");
   PortletRequestDispatcher dispatcher =
       request
           .getPortletSession()
           .getPortletContext()
           .getRequestDispatcher(response.encodeURL("/myservlet/bookServlet"));
   dispatcher.include(request, response);
   Map<String, String> map = (Map<String, String>) request.getAttribute("errors");
   if (map != null && !map.isEmpty()) {
     response.setRenderParameter("myaction", "addBookAction");
   } else {
     response.setRenderParameter("myaction", "showCatalog");
   }
 }
 @ProcessAction(name = "removeBookAction")
 public void removeBook(ActionRequest request, ActionResponse response)
     throws PortletException, IOException {
   logger.info("Inside removeBook action method");
   if (!request.isUserInRole("administrator")) {
     response.setRenderParameter("myaction", "error");
     response.setRenderParameter(
         "exceptionMsg",
         "You are not authorized for this action. You must have Administrator role.");
     return;
   }
   request.setAttribute("myaction", "removeBookAction");
   PortletRequestDispatcher dispatcher =
       request
           .getPortletSession()
           .getPortletContext()
           .getRequestDispatcher(response.encodeURL("/myservlet/bookServlet"));
   dispatcher.include(request, response);
   response.setRenderParameter("myaction", "showCatalog");
 }
  @ProcessAction(name = "uploadTocAction")
  public void uploadToc(ActionRequest request, ActionResponse response)
      throws PortletException, IOException {
    logger.info("Inside uploadToc action method");
    if (!request.isUserInRole("administrator")) {
      response.setRenderParameter("myaction", "error");
      response.setRenderParameter(
          "exceptionMsg",
          "You are not authorized for this action. You must have Administrator role.");
      return;
    }

    String isbnNumber = (String) request.getPortletSession().getAttribute("isbnNumber");
    logger.info("ISBN Number of selected book : " + isbnNumber);

    // --obtain the Book catalog from PortletContext
    BookDataObject catalog = (BookDataObject) getPortletContext().getAttribute("bookCatalog");
    // --get the Book with the same ISBN number
    Book matchingBook = null;
    List<Book> books = catalog.getBooks();
    for (Book book : books) {
      if (book.getIsbnNumber().longValue() == Long.valueOf(isbnNumber)) {
        matchingBook = book;
        break;
      }
    }
    if (matchingBook != null) {
      logger.info(
          "Setting download URL for book with ISBN "
              + matchingBook.getIsbnNumber()
              + " to "
              + request.getParameter("tocDownloadUrl"));
      matchingBook.setDownloadUrl(request.getParameter("tocDownloadUrl"));
    } else {
      response.setRenderParameter("myaction", "error");
      response.setRenderParameter(
          "exceptionMsg",
          "No matching book with ISBN number " + isbnNumber + " found in the catalog");
    }
  }