Search in sources :

Example 1 with Book

use of org.talend.esb.examples.ebook.model.Book in project tesb-rt-se by Talend.

the class BookService method sendBook.

@POST
@Path("{id}")
public Response sendBook(@PathParam("id") String id) {
    String recipient = "root@localhost";
    LOG.info("Sending book {} to {}.", id, recipient);
    Book book = bookRepo.getBook(id);
    Format format = getMobiFormat(book);
    if (format == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    URI uri = format.getFile();
    new MailSender().send(recipient, uri);
    LOG.info("Mail sent successfully");
    return Response.ok().build();
}
Also used : Format(org.talend.esb.examples.ebook.model.Format) Book(org.talend.esb.examples.ebook.model.Book) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with Book

use of org.talend.esb.examples.ebook.model.Book in project tesb-rt-se by Talend.

the class BookParser method parse.

public Book parse(Document doc) throws XPathExpressionException, URISyntaxException {
    Book book = new Book();
    String id = xpath.evaluate("//pgterms:ebook/@rdf:about", doc);
    book.setId(id);
    book.setTitle(xpath.evaluate("//dcterms:title/text()", doc));
    book.setCreator(xpath.evaluate("//dcterms:creator//pgterms:name/text()", doc));
    NodeList files = (NodeList) xpath.evaluate("//pgterms:file", doc, XPathConstants.NODESET);
    // NodeList subjects = (NodeList)xpath.evaluate("//dcterms:subject/rdf:Description/rdf:value", doc, XPathConstants.NODESET);
    for (int c = 0; c < files.getLength(); c++) {
        Format format = parseFormat((Element) files.item(c));
        if (format.getMediaType().startsWith("image")) {
            book.setCover(format.getFile());
        }
        book.getFormats().add(format);
    }
    return book;
}
Also used : Format(org.talend.esb.examples.ebook.model.Format) Book(org.talend.esb.examples.ebook.model.Book) NodeList(org.w3c.dom.NodeList)

Example 3 with Book

use of org.talend.esb.examples.ebook.model.Book in project tesb-rt-se by Talend.

the class BookRepositoryTest method testTransactionRollback.

/**
 * Shows that bookRepository can take part in an outer transaction
 */
@Test
public void testTransactionRollback() throws Exception {
    ut.begin();
    Book book = createBook("My title");
    bookRepository.add(book);
    ut.rollback();
    Book book2 = bookRepository.getBook(book.getId());
    Assert.assertNull(book2);
}
Also used : Book(org.talend.esb.examples.ebook.model.Book) Test(org.junit.Test)

Example 4 with Book

use of org.talend.esb.examples.ebook.model.Book in project tesb-rt-se by Talend.

the class BookRepositoryTest method testEMLifecycleWithCoordination.

/**
 * Test EntityManager life cycle can be extended by outer Coordination
 */
@Test
public void testEMLifecycleWithCoordination() throws Exception {
    Coordination coordination = coordinator.begin("coord", 10000);
    Book book = createBook("My title");
    try {
        bookRepository.add(book);
        Book book2 = bookRepository.getBook(book.getId());
        Format format = book2.getFormats().get(0);
        Assert.assertEquals(book.getFormats().get(0).getFile().toString(), format.getFile().toString());
    } finally {
        bookRepository.delete(book.getId());
        coordination.end();
    }
}
Also used : Format(org.talend.esb.examples.ebook.model.Format) Coordination(org.osgi.service.coordinator.Coordination) Book(org.talend.esb.examples.ebook.model.Book) Test(org.junit.Test)

Example 5 with Book

use of org.talend.esb.examples.ebook.model.Book in project tesb-rt-se by Talend.

the class BookRepositoryTest method testEMLifecycle.

/**
 * Test default EntityManager life cycle ends at borders of BookRepository
 */
@Test(expected = LazyInitializationException.class)
public void testEMLifecycle() throws Exception {
    Book book = createBook("My title");
    try {
        bookRepository.add(book);
        Book book2 = bookRepository.getBook(book.getId());
        book2.getFormats().get(0);
    } finally {
        bookRepository.delete(book.getId());
    }
}
Also used : Book(org.talend.esb.examples.ebook.model.Book) Test(org.junit.Test)

Aggregations

Book (org.talend.esb.examples.ebook.model.Book)12 Test (org.junit.Test)7 Format (org.talend.esb.examples.ebook.model.Format)5 URI (java.net.URI)2 TimeoutException (java.util.concurrent.TimeoutException)2 JMSException (javax.jms.JMSException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 JAXBException (javax.xml.bind.JAXBException)2 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 POST (javax.ws.rs.POST)1 Coordination (org.osgi.service.coordinator.Coordination)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1