Package cz.muni.fi.pa165.library.web_layer.readerPages

Examples of cz.muni.fi.pa165.library.web_layer.readerPages.ShowAllBookReader


    private List<BookTO> listSelectedBook = new ArrayList();

    public AddBorrow(final PageParameters parameters) {
        super(parameters);
        ReaderService readerService = (ReaderService) ApplicationContextProvider.getApplicationContext().getBean("readerService");
        final BookService bookService = (BookService) ApplicationContextProvider.getApplicationContext().getBean("bookService");

        borrow = new BorrowTO();

        Form<?> form;
        form = new Form("form") {
            @Override
            protected void onSubmit() {
                BorrowService borrowService = (BorrowService) ApplicationContextProvider.getApplicationContext().getBean("borrowService");
                if (borrow.getBorrowID() == null) {
                    borrow.setBorrowDate(new Date(System.currentTimeMillis()));
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(new Date(System.currentTimeMillis()));
                    cal.add(Calendar.MONTH, 1); // add 1 month 
                    borrow.setExpirationDate(cal.getTime());
                    if (selectedBook != null) {
                        listSelectedBook.add(selectedBook);
                    }
                    if (selectedBook2 != null) {
                        listSelectedBook.add(selectedBook2);
                    }
                    if (selectedBook3 != null) {
                        listSelectedBook.add(selectedBook3);
                    }
                    if (selectedBook4 != null) {
                        listSelectedBook.add(selectedBook4);
                    }
                    if (selectedBook5 != null) {
                        listSelectedBook.add(selectedBook5);
                    }
                    if (selectedBook6 != null) {
                        listSelectedBook.add(selectedBook6);
                    }
                    for (int i = 0; i < listSelectedBook.size(); i++) {
                        for (int j = i + 1; j < listSelectedBook.size(); j++) {
                            if (listSelectedBook.get(i).equals(listSelectedBook.get(j))) {
                                listSelectedBook.remove(listSelectedBook.get(j));
                                j--;
                            }
                        }
                    }
                    borrow.setTitlesTO(listSelectedBook);
                    borrowService.createBorrow(borrow);
                }
                setResponsePage(ShowAllBorrow.class);
            }
        };
        add(form);

        List<ReaderTO> readers = readerService.findAllReaders();
        DropDownChoice choiceReaders = new DropDownChoice("reader", new PropertyModel(borrow, "readerTO"), readers);
        form.add(choiceReaders);

        List<BookTO> books = bookService.findAllAvailableBooks();

        DropDownChoice choiceBooks = new DropDownChoice("title", new PropertyModel(this, "selectedBook"), books);
        form.add(choiceBooks);
        DropDownChoice choiceBooks2 = new DropDownChoice("title2", new PropertyModel(this, "selectedBook2"), books);
        form.add(choiceBooks2);
View Full Code Here


    private static final List<State> STATES = Arrays.asList(State.values());
    private static final List<Genre> GENRES = Arrays.asList(Genre.values());
   
    public EditBook(final PageParameters parameters) {
  super(parameters);
        BookService bookService = (BookService) ApplicationContextProvider.getApplicationContext().getBean("bookService");
        StringValue bookId = parameters.get("bookId");
        if (bookId.isEmpty()) {
           book = new BookTO();
           add(new Label("titleMessage", new Model("Create book")));
        } else {
            book = bookService.findBookById(bookId.toLong());
            add(new Label("titleMessage", new Model("Edit book")));
        }
       
        Form<?> form = new Form("form") {
            @Override
            protected void onSubmit() {
                BookService bookService = (BookService) ApplicationContextProvider.getApplicationContext().getBean("bookService");
                if (book.getId() == null) {
                    book.setAvailability(Available.AVAILABLE);
                    bookService.createBook(book);
                } else {
                    bookService.updateBook(book);
                }
                setResponsePage(ShowAllBook.class);
            }
        };
        add(form);
View Full Code Here

  super(parameters);
       
        // DELETE ITEM
        StringValue bookId = parameters.get("bookId");
        if (!bookId.isEmpty()) {
            BookService bookService = (BookService) ApplicationContextProvider.getApplicationContext().getBean("bookService");
            bookService.deleteBook(bookService.findBookById(bookId.toLong()));
            setResponsePage(ShowAllBook.class);
        }
       
       BookService bookService = (BookService) ApplicationContextProvider.getApplicationContext().getBean("bookService");
       RepeatingView repeating = new RepeatingView("repeating");
       add(repeating);      
      
       for (BookTO book : bookService.findAllBooks()) {
            AbstractItem item = new AbstractItem(repeating.newChildId());
            PageParameters pageParameters = new PageParameters();
            pageParameters.add("bookId", book.getId());
            item.add(new BookmarkablePageLink<Void>("edit", EditBook.class, pageParameters));
            item.add(new BookmarkablePageLink<Void>("delete", ShowAllBook.class, pageParameters));
View Full Code Here

    private StringValue readerId;

    public EditReservation(final PageParameters parameters) {
        super(parameters);
        ReaderService readerService = (ReaderService) ApplicationContextProvider.getApplicationContext().getBean("readerService");
        BookService bookService = (BookService) ApplicationContextProvider.getApplicationContext().getBean("bookService");
        readerId = parameters.get("readerId");
        reservation = new ReservationTO();
        add(new Label("title", new Model("Create reservation for "
                + readerService.findReaderById(readerId.toLong()).getSurname() + " "
                + readerService.findReaderById(readerId.toLong()).getFirstName())));

        Form<?> form = new Form("form") {
            @Override
            protected void onSubmit() {
                ReservationService reservationService = (ReservationService) ApplicationContextProvider.getApplicationContext().getBean("reservationService");
                ReaderService readerService = (ReaderService) ApplicationContextProvider.getApplicationContext().getBean("readerService");
                java.util.Date date = new java.util.Date();
                reservation.setReservationDate(new Timestamp(date.getTime()));
                reservation.setReaderTO(readerService.findReaderById(readerId.toLong()));
                reservationService.insertReservation(reservation);
                setResponsePage(ShowAllReservation.class);
            }
        };
        add(form);
        List<BookTO> books = bookService.findAllAvailableBooks();
        DropDownChoice choiceState = new DropDownChoice("bookTO", new PropertyModel(reservation, "bookTO"), books);
        form.add(choiceState);

        BookmarkablePageLink homeLink = new BookmarkablePageLink<>(
                "list", ShowAllReader.class);
View Full Code Here

    public static BookTO convertBookEntityToTO(Book book) {
        if (book == null) {
            return null;
        }
        BookTO bookTO = new BookTO(book.getTitle(), book.getAuthor(), book.getGenre(), book.getPublicationYear(), book.getPublicationPlace(), book.getPublisher(), book.getISBN(), book.getState(), book.getAvailability());
        bookTO.setId(book.getId());
        return bookTO;
    }
View Full Code Here

    }

    private void parseBook(List<BookTO> list) {
        Iterator it = list.listIterator();
        while (it.hasNext()) {
            BookTO bookTO = (BookTO) it.next();
            Object[] bookRow = {
                bookTO.getId(), bookTO.getAuthor(), bookTO.getTitle(), bookTO.getISBN(), bookTO.getAvailability(), bookTO.getGenre(),
                bookTO.getPublicationPlace(), bookTO.getPublicationYear(), bookTO.getPublisher(), bookTO.getStatus()
            };
            model.addRow(bookRow);
        }
    }
View Full Code Here

    }

    private JPanel updateBook() {
        Long id = (Long) model.getValueAt(table.getSelectedRow(), 0);
        createPanel = new JPanel();
        book = new BookTO();
        try {
            book = bookWebService.findBookById(id);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(bookPanel, "Cannot update book.\nServer connection problem.",
                    "Oops!", JOptionPane.ERROR_MESSAGE);
View Full Code Here

                if (publisherField.getText().equals("")) {
                    publisherField.setBackground(Color.getHSBColor(243, 102, 78));
                    check = false;
                }
                if (check) {
                    BookTO book = new BookTO();
                    book.setAuthor(authorField.getText());
                    book.setTitle(titleField.getText());
                    book.setISBN(isbnField.getText());
                    book.setAvailability(Available.AVAILABLE);
                    book.setGenre(Genre.valueOf(genreField.getSelectedItem().toString()));
                    book.setPublicationPlace(publicationPlaceField.getText());
                    book.setPublicationYear(publicationYearField.getText());
                    book.setPublisher(publisherField.getText());
                    book.setStatus(State.NEW);
                    try {
                        bookWebService.createBook(book);
                        Object[] arr = {
                            book.getId(), book.getAuthor(), book.getTitle(), book.getISBN(), book.getAvailability(), book.getGenre(),
                            book.getPublicationPlace(), book.getPublicationYear(), book.getPublisher(), book.getStatus()
                        };
                        model.addRow(arr);
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(bookPanel, "Cannot create book.\nServer connection problem.",
                                "Oops!", JOptionPane.ERROR_MESSAGE);
View Full Code Here

    public EditBook(final PageParameters parameters) {
  super(parameters);
        BookService bookService = (BookService) ApplicationContextProvider.getApplicationContext().getBean("bookService");
        StringValue bookId = parameters.get("bookId");
        if (bookId.isEmpty()) {
           book = new BookTO();
           add(new Label("titleMessage", new Model("Create book")));
        } else {
            book = bookService.findBookById(bookId.toLong());
            add(new Label("titleMessage", new Model("Edit book")));
        }
View Full Code Here

                      @Override
                      public void onClick() {
                          ReservationService reservationService = (ReservationService) ApplicationContextProvider.getApplicationContext().getBean("reservationService");
                          AuthenticatedSession session = ((AuthenticatedSession)Session.get());
                          ReaderTO reader = session.getReader();
                          BookTO book2 = bookService.findBookById(book.getId());
                          java.util.Date date = new java.util.Date();
                          if (reader != null && book != null){
                              ReservationTO reservation = new ReservationTO(reader, book2,new Timestamp(date.getTime()));
                              reservationService.insertReservation(reservation);
                              setResponsePage(ShowAllBookReader.class);
View Full Code Here

TOP

Related Classes of cz.muni.fi.pa165.library.web_layer.readerPages.ShowAllBookReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.