Exemple #1
0
  public static Book getByFile(ZLFile bookFile) {
    if (bookFile == null) {
      return null;
    }

    final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile();
    if (physicalFile != null && !physicalFile.exists()) {
      return null;
    }

    final FileInfoSet fileInfos = new FileInfoSet(bookFile);

    Book book = BooksDatabase.Instance().loadBookByFile(fileInfos.getId(bookFile), bookFile);
    if (book != null) {
      book.loadLists();
    }

    if (book != null && fileInfos.check(physicalFile, physicalFile != bookFile)) {
      return book;
    }
    fileInfos.save();

    if (book == null) {
      book = new Book(bookFile);
    }
    if (book.readMetaInfo()) {
      book.save();
      return book;
    }
    return null;
  }
Exemple #2
0
 public void testInOperatorWithList() throws Exception {
   // Create test setup
   removeAll(Book.class);
   removeAll(Author.class);
   // Create
   Author author1 = new Author("Geordi", "LaForge");
   Author author2 = new Author("Data", "");
   Author author3 = new Author("Scott", "Montgomery");
   Book book = new Book("Starship internals", "1-3-5-7");
   book.setMainAuthor(author1);
   // Save
   getStore().save(book);
   getStore().save(author1);
   getStore().save(author2);
   getStore().save(author3);
   // Create list
   ArrayList authorList = new ArrayList();
   authorList.add(author1);
   authorList.add(author2);
   authorList.add(author3);
   // Select
   List result =
       getStore().find("find book where book.mainauthor in ?", new Object[] {authorList});
   logger.debug("result is: " + result);
   Assert.assertEquals(result.size(), 1);
 }
Exemple #3
0
 public List<CancelActionDescription> getCancelActionsList() {
   myCancelActionsList.clear();
   if (ShowLibraryInCancelMenuOption.getValue()) {
     myCancelActionsList.add(new CancelActionDescription(CancelActionType.library, null));
   }
   if (ShowNetworkLibraryInCancelMenuOption.getValue()) {
     myCancelActionsList.add(new CancelActionDescription(CancelActionType.networkLibrary, null));
   }
   if (ShowPreviousBookInCancelMenuOption.getValue()) {
     final Book previousBook = Library.Instance().getPreviousBook();
     if (previousBook != null) {
       myCancelActionsList.add(
           new CancelActionDescription(CancelActionType.previousBook, previousBook.getTitle()));
     }
   }
   if (ShowPositionsInCancelMenuOption.getValue()) {
     if (Model != null && Model.Book != null) {
       for (Bookmark bookmark : Library.Instance().invisibleBookmarks(Model.Book)) {
         myCancelActionsList.add(new BookmarkDescription(bookmark));
       }
     }
   }
   myCancelActionsList.add(new CancelActionDescription(CancelActionType.close, null));
   return myCancelActionsList;
 }
 public void setBookFavorite(Book book, boolean favorite) {
   if (favorite) {
     myDatabase.addToFavorites(book.getId());
   } else {
     myDatabase.removeFromFavorites(book.getId());
   }
   fireBookEvent(BookEvent.Updated, book);
 }
 private boolean isClubBook(Book book) {
   boolean isClubBook = false;
   if (getNumberOfBooks() > 0) {
     for (Book clubBook : clubBooks) {
       if (clubBook.getIsbnNumber().equals(book.getIsbnNumber())) isClubBook = true;
     }
   }
   return isClubBook;
 }
 public List<String> titles() {
   synchronized (myBooksByFile) {
     final List<String> titles = new ArrayList<String>(myBooksByFile.size());
     for (Book book : myBooksByFile.values()) {
       titles.add(book.getTitle());
     }
     return titles;
   }
 }
 public List<Book> booksForSeries(String series) {
   final LinkedList<Book> filtered = new LinkedList<Book>();
   for (Book b : books()) {
     final SeriesInfo info = b.getSeriesInfo();
     if (info != null && series.equals(info.Title)) {
       filtered.add(b);
     }
   }
   return filtered;
 }
 public boolean hasSeries() {
   synchronized (myBooksByFile) {
     for (Book book : myBooksByFile.values()) {
       if (book.getSeriesInfo() != null) {
         return true;
       }
     }
   }
   return false;
 }
Exemple #9
0
 public void getData() {
   for (int i = model.getRowCount() - 1; i >= 0; i--) {
     model.removeRow(i);
   }
   ArrayList<Book> list = bm.bookAllData();
   for (Book book : list) {
     String[] data = {String.valueOf(book.getNo()), book.getTitle(), book.getAuthor()};
     model.addRow(data);
   }
 }
 public List<Book> booksForTag(Tag tag) {
   final boolean isNull = Tag.NULL.equals(tag);
   final LinkedList<Book> filtered = new LinkedList<Book>();
   for (Book b : books()) {
     final List<Tag> bookTags = b.tags();
     if (isNull && bookTags.isEmpty() || bookTags.contains(tag)) {
       filtered.add(b);
     }
   }
   return filtered;
 }
 public List<Book> booksForAuthor(Author author) {
   final boolean isNull = Author.NULL.equals(author);
   final LinkedList<Book> filtered = new LinkedList<Book>();
   for (Book b : books()) {
     final List<Author> bookAuthors = b.authors();
     if (isNull && bookAuthors.isEmpty() || bookAuthors.contains(author)) {
       filtered.add(b);
     }
   }
   return filtered;
 }
Exemple #12
0
 public void getFindData() {
   for (int i = model.getRowCount() - 1; i >= 0; i--) {
     model.removeRow(i);
   }
   String pub = box.getSelectedItem().toString();
   ArrayList<Book> list = bm.bookFindData(pub);
   tf.setText(pub);
   for (Book book : list) {
     String[] data = {String.valueOf(book.getNo()), book.getTitle(), book.getAuthor()};
     model.addRow(data);
   }
 }
Exemple #13
0
 public static void main(String[] args) {
   BookShelf bookShelf = new BookShelf(4);
   bookShelf.appendBook(new Book("Around the World in 80 Days"));
   bookShelf.appendBook(new Book("Bible"));
   bookShelf.appendBook(new Book("Cinderella"));
   bookShelf.appendBook(new Book("Daddy-Long-Legs"));
   Iterator it = bookShelf.iterator();
   while (it.hasNext()) {
     Book book = (Book) it.next();
     System.out.println(book.getName());
   }
 }
 public List<String> series() {
   final Set<String> series = new TreeSet<String>();
   synchronized (myBooksByFile) {
     for (Book book : myBooksByFile.values()) {
       final SeriesInfo info = book.getSeriesInfo();
       if (info != null) {
         series.add(info.Title);
       }
     }
   }
   return new ArrayList<String>(series);
 }
 @Override
 protected void reloadBook(Book book) {
   final Cursor cursor =
       myDatabase.rawQuery(
           "SELECT title,encoding,language FROM Books WHERE book_id = " + book.getId(), null);
   if (cursor.moveToNext()) {
     book.setTitle(cursor.getString(0));
     book.setEncoding(cursor.getString(1));
     book.setLanguage(cursor.getString(2));
   }
   cursor.close();
 }
  public Book getBookByFile(ZLFile bookFile) {
    if (bookFile == null) {
      return null;
    }
    final FormatPlugin plugin = PluginCollection.Instance().getPlugin(bookFile);
    if (plugin == null) {
      return null;
    }
    try {
      bookFile = plugin.realBookFile(bookFile);
    } catch (BookReadingException e) {
      return null;
    }

    Book book = myBooksByFile.get(bookFile);
    if (book != null) {
      return book;
    }

    final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile();
    if (physicalFile != null && !physicalFile.exists()) {
      return null;
    }

    final FileInfoSet fileInfos = new FileInfoSet(myDatabase, bookFile);

    book = myDatabase.loadBookByFile(fileInfos.getId(bookFile), bookFile);
    if (book != null) {
      book.loadLists(myDatabase);
    }

    if (book != null && fileInfos.check(physicalFile, physicalFile != bookFile)) {
      saveBook(book, false);
      // saved
      addBook(book, false);
      return book;
    }
    fileInfos.save();

    try {
      if (book == null) {
        book = new Book(bookFile);
      } else {
        book.readMetaInfo();
      }
    } catch (BookReadingException e) {
      return null;
    }

    saveBook(book, false);
    return book;
  }
  public boolean hasBooksForPattern(String pattern) {
    if (pattern == null || pattern.length() == 0) {
      return false;
    }
    pattern = pattern.toLowerCase();

    for (Book b : books()) {
      if (b.matches(pattern)) {
        return true;
      }
    }
    return false;
  }
Exemple #18
0
  public static void main(String[] args) {
    System.setProperty("fr.umlv.jbucks.factory", BuckFactoryImpl.class.getName());

    BuckFactory factory = BuckFactory.getFactory();
    Book book = factory.createBook("test");
    System.out.println(book.getName());

    book.setUserData("hello-UID", "12345");
    System.out.println("hello-UID " + book.getUserDataValue("hello-UID"));

    EventManager manager = factory.getEventManager();

    manager.addListener(
        Book.class,
        "accounts",
        PropertyEvent.TYPE_PROPERTY_ADDED | PropertyEvent.TYPE_PROPERTY_REMOVED,
        new PropertyListener() {
          public void propertyChanged(PropertyEvent event) {
            System.out.println(event);
          }
        });

    Account account = factory.createAccount(book, "remi");
    factory.createAccount(book, "gilles");

    List list = book.getAccounts();

    System.out.println(list);

    SortedSet transactions = account.getTransactions();

    manager.addListener(
        Account.class,
        "transactions",
        PropertyEvent.TYPE_PROPERTY_ADDED | PropertyEvent.TYPE_PROPERTY_REMOVED,
        new PropertyListener() {
          public void propertyChanged(PropertyEvent event) {
            System.out.println("transaction " + event);
          }
        });

    Transaction transaction =
        factory.createTransaction(new Date().getTime(), Collections.EMPTY_LIST);
    transactions.add(transaction);

    SortedSet tailSet = transactions.tailSet(transaction);

    System.out.println(tailSet);

    tailSet.add(factory.createTransaction(transaction.getDate() + 1, Collections.EMPTY_LIST));
  }
 public List<Author> authors() {
   final Set<Author> authors = new TreeSet<Author>();
   synchronized (myBooksByFile) {
     for (Book book : myBooksByFile.values()) {
       final List<Author> bookAuthors = book.authors();
       if (bookAuthors.isEmpty()) {
         authors.add(Author.NULL);
       } else {
         authors.addAll(bookAuthors);
       }
     }
   }
   return new ArrayList<Author>(authors);
 }
  public List<Book> booksForPattern(String pattern) {
    if (pattern == null || pattern.length() == 0) {
      return Collections.emptyList();
    }
    pattern = pattern.toLowerCase();

    final LinkedList<Book> filtered = new LinkedList<Book>();
    for (Book b : books()) {
      if (b.matches(pattern)) {
        filtered.add(b);
      }
    }
    return filtered;
  }
 public List<Book> booksForSeriesAndAuthor(String series, Author author) {
   final boolean isNull = Author.NULL.equals(author);
   final LinkedList<Book> filtered = new LinkedList<Book>();
   for (Book b : books()) {
     final List<Author> bookAuthors = b.authors();
     final SeriesInfo info = b.getSeriesInfo();
     if (info != null
         && series.equals(info.Title)
         && (isNull && bookAuthors.isEmpty() || bookAuthors.contains(author))) {
       filtered.add(b);
     }
   }
   return filtered;
 }
 public int updateBook(Book bo) {
   int x = 0;
   try {
     con = JdbcUtil.getMysqlConnection();
     System.out.println("update 2");
     ps =
         con.prepareStatement(
             "update jlcbooks set bname=?,author=?,pub=?,cost=?,edition=?,isbn=? where bid=?");
     System.out.println("update 3");
     System.out.println(bo.getBid());
     ps.setString(7, bo.getBid());
     ps.setString(1, bo.getBname());
     ps.setString(2, bo.getAuthor());
     ps.setString(3, bo.getPub());
     ps.setString(4, bo.getCost());
     ps.setString(5, bo.getEdi());
     ps.setString(6, bo.getIsbn());
     x = ps.executeUpdate();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     JdbcUtil.cleanup(ps, con);
   }
   return x;
 }
 public List getBooksByCost(String cost) {
   List al = new ArrayList();
   try {
     con = JdbcUtil.getMysqlConnection();
     ps = con.prepareStatement("select *from jlcbooks where cost=?");
     ps.setString(1, cost);
     rs = ps.executeQuery();
     while (rs.next()) {
       Book bo = new Book();
       bo.setBid(rs.getString(1));
       bo.setBname(rs.getString(2));
       bo.setAuthor(rs.getString(3));
       bo.setPub(rs.getString(4));
       bo.setCost(rs.getString(5));
       bo.setEdi(rs.getString(6));
       bo.setIsbn(rs.getString(7));
       al.add(bo);
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     JdbcUtil.cleanup(ps, con);
   }
   return al;
 }
  public void removeBook(Book book, boolean deleteFromDisk) {
    synchronized (myBooksByFile) {
      myBooksByFile.remove(book.File);
      myBooksById.remove(book.getId());

      final List<Long> ids = myDatabase.loadRecentBookIds();
      if (ids.remove(book.getId())) {
        myDatabase.saveRecentBookIds(ids);
      }
      if (deleteFromDisk) {
        book.File.getPhysicalFile().delete();
      }
    }
    fireBookEvent(BookEvent.Removed, book);
  }
Exemple #25
0
 public void testMixedSelectWithAlias() throws Exception {
   // Create test setup
   removeAll(Book.class);
   // Create
   Book book = new Book("Starship internals", "1-3-5-7");
   book.setMainAuthor(new Author("Geordi", "LaForge"));
   // Save
   getStore().save(book);
   // Select
   List result = getStore().find("find book,book.mainauthor.firstName authorname");
   logger.debug("result is: " + result);
   Assert.assertEquals(result.size(), 1);
   Assert.assertEquals(((Map) result.get(0)).get("object"), book);
   Assert.assertEquals(((Map) result.get(0)).get("authorname"), "Geordi");
 }
Exemple #26
0
 public void testRemovedAttributeSelect() throws Exception {
   // Drop
   removeAll(Book.class);
   removeAll(Author.class);
   // Create book with mainauthor
   Author author = new Author("Short", "Live");
   Book book = new Book("The Death of Null", "0");
   book.setMainAuthor(author);
   getStore().save(book);
   // Now remove mainauthor
   getStore().remove(author);
   // Run the select
   Assert.assertEquals(getStore().find("find book where book.mainauthor is null").size(), 1);
   Assert.assertEquals(getStore().find("find book where book.mainauthor is not null").size(), 0);
 }
Exemple #27
0
  public static boolean searchBook(ArrayList<Book> o, Book target, int lo, int hi) {
    boolean found = false;
    // int m = (lo + hi) / 2;

    while (lo <= hi) {
      int m = (lo + hi) / 2;
      if (o.get(m).compareTo(target) == 0) {
        // System.out.println("Book has been found");
        found = true;
        if (o.get(m).getStatus() == true) {
          o.get(m).setStatus(false);
          System.out.print(
              "Thank you for checking out " + target.getTitle() + ". We hope you enjoy it!");
          return found;
        } else {
          System.out.println(
              "We are sorry to inform you that the book that you requested has already been checked out. Would you like to be added to the waiList for the book?");
          return found;
        }
      } else if (o.get(m).compareTo(target) > 0) {
        // System.out.println("searching in the lower range");
        hi = m - 1;
      } else if (o.get(m).compareTo(target) < 0) {
        // System.out.println("searching in the upper range");
        lo = m + 1;
      } else {
      }
    }

    return found;
  }
Exemple #28
0
 public void testRemovedObjectIdSelect() throws Exception {
   // Drop
   removeAll(Book.class);
   // Create book
   Author author = new Author("Joe", "Author");
   Book book = new Book("Book", "X");
   book.setMainAuthor(author);
   getStore().save(book);
   // Remove author
   getStore().remove(author);
   // Run the select
   Assert.assertEquals(
       getStore().find("find book where book.mainauthor=?", new Object[] {author}).size(), 0);
   Assert.assertEquals(
       getStore().find("find book where book.mainauthor=?", new Object[] {null}).size(), 1);
 }
  public void recordExchange(String initiatorEmail, ExchangeOrder exchangeOrder)
      throws BookExchangeInternalException {
    Book bookUnderOffer =
        bookDao
            .getBookPostedByUser(
                exchangeOrder.getBookUnderOffer(), exchangeOrder.getBookUnderOfferOwner())
            .orElseThrow(() -> new BookExchangeInternalException("Book under offer not found"));
    User exchangeInitiator =
        userDao
            .findUserByEmail(initiatorEmail)
            .orElseThrow(() -> new BookExchangeInternalException("No user found for email"));
    DirectBookExchange exchangeToRecord = buildBookExchange(bookUnderOffer, exchangeInitiator);

    bookExchangeDao.saveBookExchange(exchangeToRecord);
    addNewExchangeRequestNotification(
        bookUnderOffer.getPostedBy(), exchangeInitiator.getFullName(), exchangeToRecord);
  }
Exemple #30
0
  public void testSelectSymbolTable() throws Exception {
    // Drop books
    removeAll(Book.class);
    removeAll(Author.class);

    // Create
    Book book = new Book("Title", "Isbn");
    book.setMainAuthor(new Author("Peter", "Jackson"));
    getStore().save(book);

    // Select
    List result =
        getStore()
            .find(
                "find book where book.mainauthor.firstname='Peter' or book.mainauthor.firstname='Peter'");
    Assert.assertEquals(result.size(), 1);
  }