use of org.talend.esb.examples.ebook.model.Format 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.Format 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.Format in project tesb-rt-se by Talend.
the class BookParser method parseFormat.
private Format parseFormat(Element file) throws XPathExpressionException {
Format format = new Format();
String about = xpath.evaluate("@rdf:about", file);
try {
format.setFile(new URI(about));
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
format.setExtent(new Integer(xpath.evaluate("dcterms:extent", file)));
format.setMediaType(xpath.evaluate("dcterms:format/rdf:Description/rdf:value", file));
format.setModified(xpath.evaluate("dcterms:modified", file));
return format;
}
use of org.talend.esb.examples.ebook.model.Format 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.Format in project tesb-rt-se by Talend.
the class BookRepositoryImpl method add.
@Override
public void add(Book book) {
if (getBook(book.getId()) != null) {
LOG.info("Ignoring book {} as it already exists.", book.getId());
return;
}
for (Format fomat : book.getFormats()) {
em.persist(fomat);
}
persistSubjects(book);
em.persist(book);
if ("error1".equals(book.getTitle())) {
throw new RuntimeException("Test for error handling. Should cause tx rollback");
}
}
Aggregations