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 checkAllBooksInstalled() {
    BookInstaller bookInstaller = new BookInstaller();
    List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER);

    for (Book book : books) {
      try {
        Book installedBook = bookInstaller.getInstalledBook(book.getInitials());
        if (installedBook == null) {
          System.out.println("Not installed:" + book.getInitials() + " Name:" + book.getName());
        } else {
          Version versionObj = (Version) book.getProperty("Version");
          String version = versionObj == null ? "No version" : versionObj.toString();

          Version installedVersionObj =
              (Version) installedBook.getBookMetaData().getProperty("Version");
          String installedVersion =
              installedVersionObj == null ? "No version" : installedVersionObj.toString();
          if (!version.equals(installedVersion)) {
            System.out.println(
                "Incorrect version of "
                    + book.getInitials()
                    + " installed:"
                    + installedVersion
                    + " Repo:"
                    + version);
          } else {
            System.out.println("Okay:" + book.getInitials() + " " + version);
          }
        }
      } catch (Exception e) {
        System.out.println("Error installing:" + book.getInitials());
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 3
0
 private void updateCachedRepoBookList() {
   try {
     BookInstaller bookInstaller = new BookInstaller();
     bookInstaller.reloadBookList(REPOSITORY);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 4
0
  private void showRepoBooks() {
    BookInstaller bookInstaller = new BookInstaller();
    List<Book> books = (List<Book>) bookInstaller.getRepositoryBooks(REPOSITORY, BOOK_FILTER);

    for (Book book : books) {
      String lang = book.getLanguage() == null ? " " : book.getLanguage().getCode();
      System.out.println(lang + " " + book.getName());
    }
  }
Exemplo n.º 5
0
  private void createZipFiles() {

    List<Book> books = (List<Book>) BookInstaller.getInstalledBooks();
    for (Book book : books) {
      createZipFile(book);
    }
  }
Exemplo n.º 6
0
  private void addPropertiesFile() {
    Properties indexProperties = new Properties();
    indexProperties.put("version", "1");
    indexProperties.put(
        "java.specification.version", System.getProperty("java.specification.version"));
    indexProperties.put("java.vendor", System.getProperty("java.vendor"));
    indexProperties.put(
        "lucene.specification.version", LucenePackage.get().getSpecificationVersion());

    List<Book> books = (List<Book>) BookInstaller.getInstalledBooks();
    for (Book book : books) {
      System.out.println(
          "Adding properties file:" + book.getInitials() + " name:" + book.getName());
      String initials = book.getInitials();
      File indexPropertiesFile = new File(LUCENE_INDEX_DIR_FILE, initials + "/index.properties");

      FileOutputStream fos = null;
      try {
        fos = new FileOutputStream(indexPropertiesFile);
        indexProperties.store(fos, null);
      } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
        ioe.printStackTrace();
      } finally {
        if (fos != null) {
          try {
            fos.close();
          } catch (IOException e2) {
            e2.printStackTrace();
          }
        }
      }
    }
  }
Exemplo n.º 7
0
  private void indexAllBooks() {
    List<Book> books = (List<Book>) BookInstaller.getInstalledBooks();

    for (Book book : books) {
      indexBook(book);
    }
  }
Exemplo n.º 8
0
  private void showInstalledBooks() {
    List<Book> books = (List<Book>) BookInstaller.getInstalledBooks();

    for (Book book : books) {
      System.out.println(book.getName());
    }
  }
Exemplo n.º 9
0
  private void deleteAllBooks() {
    List<Book> books = (List<Book>) BookInstaller.getInstalledBooks();

    BookInstaller bookInstaller = new BookInstaller();
    for (Book book : books) {
      deleteBook(book);
    }
  }
Exemplo n.º 10
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();
      }
    }
  }
Exemplo n.º 11
0
  private void indexSingleBook(String initials) {
    try {
      Book book = BookInstaller.getInstalledBook(initials);

      IndexManager imanager = IndexManagerFactory.getIndexManager();
      if (imanager.isIndexed(book)) {
        imanager.deleteIndex(book);
      }

      indexBook(book);
      createZipFile(book);
    } catch (Exception e) {
      System.out.println("Error indexing:" + initials);
      e.printStackTrace();
    }
  }
Exemplo n.º 12
0
 private void deleteBook(String initials) {
   Book book = BookInstaller.getInstalledBook(initials);
   if (book != null) {
     deleteBook(book);
   }
 }