SHARE
TWEET

Untitled

a guest Jun 19th, 2017 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.List;
  2.  
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5.  
  6. import com.marcestarlet.booksearcher.rest.model.dao.BookDAO;
  7. import com.marcestarlet.booksearcher.rest.model.dao.MongoDAOFactory;
  8. import com.marcestarlet.booksearcher.rest.model.entity.Book;
  9.  
  10. /**
  11.  * BookServiceImp implements the operations exposed as
  12.  * services.
  13.  * @author MarceStarlet
  14.  *
  15.  * mongodb-basics
  16.  */
  17. public class BookServiceImp implements BookService {
  18.    
  19.     private Logger log = LoggerFactory.getLogger( BookServiceImp.class );
  20.    
  21.     private static final String BOOK_DAO = "book";
  22.     private BookDAO bookDAO = null;
  23.    
  24.     public BookServiceImp() {
  25.         bookDAO = (BookDAO) MongoDAOFactory.getInstance().getDAO( BOOK_DAO );
  26.     }
  27.  
  28.     /* (non-Javadoc)
  29.      * @see com.marcestarlet.booksearcher.rest.service.BookService#createBook(com.marcestarlet.booksearcher.rest.model.entity.Book)
  30.      */
  31.     @Override
  32.     public void createBook(Book book) {    
  33.         log.info("Creating a new Book...");
  34.        
  35.         bookDAO.create( book );
  36.        
  37.     }
  38.  
  39.     /* (non-Javadoc)
  40.      * @see com.marcestarlet.booksearcher.rest.service.BookService#updateBook(com.marcestarlet.booksearcher.rest.model.entity.Book)
  41.      */
  42.     @Override
  43.     public void updateBook(Book book) {
  44.         log.info( "Updating book {} ...", book.getIsbn() );
  45.        
  46.         bookDAO.update( book );
  47.  
  48.     }
  49.  
  50.     /* (non-Javadoc)
  51.      * @see com.marcestarlet.booksearcher.rest.service.BookService#deleteBook(java.lang.String)
  52.      */
  53.     @Override
  54.     public void deleteBook(String isbn) {
  55.         log.info( "Deleting book {} ...", isbn );
  56.        
  57.         bookDAO.delete( isbn );
  58.  
  59.     }
  60.  
  61.     /* (non-Javadoc)
  62.      * @see com.marcestarlet.booksearcher.rest.service.BookService#findAllBooks()
  63.      */
  64.     @Override
  65.     public List<Book> findAllBooks() {
  66.         log.info( "Finding all books ..." );
  67.        
  68.         List<Book> books = bookDAO.findAll();
  69.  
  70.         return books;
  71.     }
  72.  
  73.     /* (non-Javadoc)
  74.      * @see com.marcestarlet.booksearcher.rest.service.BookService#findBookByISBN(java.lang.String)
  75.      */
  76.     @Override
  77.     public Book findBookByISBN(String isbn) {
  78.         log.info( "Finding book {} ...", isbn );
  79.        
  80.         Book book = bookDAO.findById( isbn );
  81.        
  82.         return book;
  83.  
  84.     }
  85.  
  86.     /* (non-Javadoc)
  87.      * @see com.marcestarlet.booksearcher.rest.service.BookService#findBookByFilter(java.lang.String)
  88.      */
  89.     @Override
  90.     public List<Book> findBookByFilter(String filter) {
  91.         log.info( "Finding books that match {} ...", filter );
  92.        
  93.         List<Book> books = bookDAO.findByFilters( filter );
  94.  
  95.         return books;
  96.  
  97.     }
  98.  
  99. }
RAW Paste Data
Top