Package cz.muni.fi.pa165.ddtroops.serviceinterfaces

Examples of cz.muni.fi.pa165.ddtroops.serviceinterfaces.RaceService


       
        try
        {
            String url = "http://" + options.getServer() + ":" + options.getPort() + "/pa165/api/";
            SkillService ss = new SkillServiceImpl(url+"skill/");
            RaceService rs = new RaceServiceImpl(url+"race/");           
            switch(jc.getParsedCommand())
            {
                case "createrace":
                    rs.create(
                            rs.createNewRace(
                                createRace.getName(),
                                createRace.getDescription(),
                                createRace.getStrength(),
                                createRace.getDexterity(),
                                createRace.getConstitution(),
                                createRace.getIntelligence(),
                                createRace.getWisdom(),
                                createRace.getCharisma()));
                    break;
                case "updaterace":
                    RaceDTO r = rs.createNewRace(
                                updateRace.getName(),
                                updateRace.getDescription(),
                                updateRace.getStrength(),
                                updateRace.getDexterity(),
                                updateRace.getConstitution(),
                                updateRace.getIntelligence(),
                                updateRace.getWisdom(),
                                updateRace.getCharisma());
                    r.id = updateRace.getId();
                    rs.update(r);
                    break;
                case "createskill":
                    ss.create(
                            ss.createNewSkill(
                                createSkill.getName(),
                                createSkill.getDescription(),
                                createSkill.getProfession(),
                                createSkill.getMinXP()));
                    break;
                case "updateskill":
                    SkillDTO s = ss.createNewSkill(
                                updateSkill.getName(),
                                updateSkill.getDescription(),
                                updateSkill.getProfession(),
                                updateSkill.getMinXP());
                    s.id = updateSkill.getId();
                    ss.update(s);
                    break;
                case "find":
                    if(findCommand.getType().equals("skill"))
                        System.out.println("Returned object: " + ss.getById(findCommand.getId()));
                    else
                        System.out.println("Returned object: " + rs.getById(findCommand.getId()));
                    break;
                case "delete":
                    if(deleteCommand.getType().equals("skill"))
                    {
                        SkillDTO s1 = new SkillDTO();
                        s1.id = deleteCommand.getId();
                        ss.delete(s1);
                    }
                    else
                    {
                        RaceDTO r1 = new RaceDTO();
                        r1.id = deleteCommand.getId();
                        rs.delete(r1);
                    }
                    break;
            }
        }
        catch(Exception ex)
View Full Code Here


    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

TOP

Related Classes of cz.muni.fi.pa165.ddtroops.serviceinterfaces.RaceService

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.