Exemplo n.º 1
0
  private void installSingleBook(String initials) {
    BookInstaller bookInstaller = new BookInstaller();
    List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER);

    for (Book book : books) {
      if (initials.equalsIgnoreCase(book.getInitials())) {
        String lang = book.getLanguage() == null ? " " : book.getLanguage().getCode();
        System.out.println("Found in repo:" + lang + " " + book.getName());

        try {
          if (Books.installed().getBook(book.getInitials()) != null) {
            System.out.println("Already installed:" + book.getInitials() + ":" + book.getName());
          } else {
            System.out.println(
                "Downloading and installing:" + book.getInitials() + ":" + book.getName());
            bookInstaller.installBook(REPOSITORY, book);
            waitToFinish();
          }

          Book installedBook = bookInstaller.getInstalledBook(book.getInitials());
          if (installedBook == null) {
            System.out.println("Not installed:" + book.getInitials() + " Name:" + book.getName());
          }

        } catch (Exception e) {
          System.out.println("Error installing:" + book.getInitials());
          e.printStackTrace();
        }
      }
    }
  }
Exemplo n.º 2
0
  private void installRepoBooks() {
    BookInstaller bookInstaller = new BookInstaller();
    List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER);

    for (Book book : books) {
      try {
        if (Books.installed().getBook(book.getInitials()) != null) {
          System.out.println("Already installed:" + book.getInitials() + ":" + book.getName());
        } else {
          System.out.println(
              "Downloading and installing:" + book.getInitials() + ":" + book.getName());
          bookInstaller.installBook(REPOSITORY, book);
          waitToFinish();
        }
      } catch (Exception e) {
        System.out.println("Error installing:" + book.getInitials());
        e.printStackTrace();
      }
    }
  }