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();
}
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;
}
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);
}
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();
}
}
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());
}
}
Aggregations