public Book processBook(Book book) {
Metadata metadata = book.getMetadata();
if(book.getCoverPage() == null && book.getCoverImage() == null) {
return book;
}
Resource coverPage = book.getCoverPage();
if (coverPage == null) {
coverPage = findCoverPage(book);
book.setCoverPage(coverPage);
}
Resource coverImage = book.getCoverImage();
if(coverPage == null) {
if(coverImage == null) {
// give up
} else { // coverImage != null
if(StringUtils.isBlank(coverImage.getHref())) {
coverImage.setHref(getCoverImageHref(coverImage, book));
}
String coverPageHtml = createCoverpageHtml(CollectionUtil.first(metadata.getTitles()), coverImage.getHref());
coverPage = new Resource(null, coverPageHtml.getBytes(), getCoverPageHref(book), MediatypeService.XHTML);
fixCoverResourceId(book, coverPage, DEFAULT_COVER_PAGE_ID);
}
} else { // coverPage != null
if(book.getCoverImage() == null) {
coverImage = getFirstImageSource(coverPage, book.getResources());
book.setCoverImage(coverImage);
if (coverImage != null) {
book.getResources().remove(coverImage.getHref());
}
} else { // coverImage != null
}
}