feat(kobo): add subtitle to KoboBookMetadata (#1543)
This commit is contained in:
@@ -57,6 +57,9 @@ public class KoboBookMetadata {
|
|||||||
private String title;
|
private String title;
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
private String subtitle;
|
||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private List<String> categories = List.of("00000000-0000-0000-0000-000000000001");
|
private List<String> categories = List.of("00000000-0000-0000-0000-000000000001");
|
||||||
|
|
||||||
|
|||||||
@@ -406,6 +406,7 @@ public class KoboEntitlementService {
|
|||||||
.contributorRoles(Collections.emptyList())
|
.contributorRoles(Collections.emptyList())
|
||||||
.entitlementId(String.valueOf(book.getId()))
|
.entitlementId(String.valueOf(book.getId()))
|
||||||
.title(metadata.getTitle())
|
.title(metadata.getTitle())
|
||||||
|
.subtitle(metadata.getSubtitle())
|
||||||
.description(metadata.getDescription())
|
.description(metadata.getDescription())
|
||||||
.contributors(authors)
|
.contributors(authors)
|
||||||
.series(series)
|
.series(series)
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package org.booklore.model.dto.kobo;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import tools.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class KoboBookMetadataTest {
|
||||||
|
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldIncludeSubtitleWhenNotNull() {
|
||||||
|
// Given: Book has a subtitle
|
||||||
|
KoboBookMetadata metadata = KoboBookMetadata.builder()
|
||||||
|
.title("Test Book")
|
||||||
|
.subtitle("A Subtitle")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// When: Serializing to JSON
|
||||||
|
String json = objectMapper.writeValueAsString(metadata);
|
||||||
|
Map<String, Object> result = objectMapper.readValue(json, Map.class);
|
||||||
|
|
||||||
|
// Then: Subtitle should be included
|
||||||
|
assertThat(result)
|
||||||
|
.containsKey("Title")
|
||||||
|
.containsKey("Subtitle");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldExcludeSubtitleWhenNull() {
|
||||||
|
// Given: Book does not have a subtitle
|
||||||
|
KoboBookMetadata metadata = KoboBookMetadata.builder()
|
||||||
|
.title("Test Book")
|
||||||
|
.subtitle(null)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// When: Serializing to JSON
|
||||||
|
String json = objectMapper.writeValueAsString(metadata);
|
||||||
|
Map<String, Object> result = objectMapper.readValue(json, Map.class);
|
||||||
|
|
||||||
|
// Then: Subtitle should be excluded
|
||||||
|
assertThat(result)
|
||||||
|
.containsKey("Title")
|
||||||
|
.doesNotContainKey("Subtitle");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.booklore.service;
|
package org.booklore.service;
|
||||||
|
|
||||||
import org.booklore.config.security.service.AuthenticationService;
|
import org.booklore.config.security.service.AuthenticationService;
|
||||||
import org.booklore.model.dto.Book;
|
|
||||||
import org.booklore.model.dto.BookLoreUser;
|
import org.booklore.model.dto.BookLoreUser;
|
||||||
import org.booklore.model.dto.settings.AppSettings;
|
import org.booklore.model.dto.settings.AppSettings;
|
||||||
import org.booklore.model.dto.kobo.KoboBookMetadata;
|
import org.booklore.model.dto.kobo.KoboBookMetadata;
|
||||||
@@ -219,6 +218,51 @@ class KoboEntitlementServiceTest {
|
|||||||
assertEquals(KoboBookFormat.KEPUB.toString(), result.getDownloadUrls().getFirst().getFormat());
|
assertEquals(KoboBookFormat.KEPUB.toString(), result.getDownloadUrls().getFirst().getFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void mapToKoboMetadata_subtitleNull() {
|
||||||
|
long bookId = 1L;
|
||||||
|
BookEntity epubBook = createEpubBookEntity(bookId);
|
||||||
|
epubBook.getMetadata().setSubtitle(null);
|
||||||
|
String token = "test-token";
|
||||||
|
|
||||||
|
when(bookQueryService.findAllWithMetadataByIds(Set.of(bookId)))
|
||||||
|
.thenReturn(List.of(epubBook));
|
||||||
|
when(koboCompatibilityService.isBookSupportedForKobo(epubBook))
|
||||||
|
.thenReturn(true);
|
||||||
|
when(koboUrlBuilder.downloadUrl(token, epubBook.getId()))
|
||||||
|
.thenReturn("http://test.com/download/" + epubBook.getId());
|
||||||
|
when(appSettingService.getAppSettings())
|
||||||
|
.thenReturn(createAppSettingsWithKoboSettings());
|
||||||
|
|
||||||
|
KoboBookMetadata result = koboEntitlementService.getMetadataForBook(bookId, token);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertNull(result.getSubtitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void mapToKoboMetadata_shouldIncludeSubtitleWhenNotNull() {
|
||||||
|
long bookId = 1L;
|
||||||
|
String subtitle = "A test subtitle";
|
||||||
|
BookEntity epubBook = createEpubBookEntity(bookId);
|
||||||
|
epubBook.getMetadata().setSubtitle(subtitle);
|
||||||
|
String token = "test-token";
|
||||||
|
|
||||||
|
when(bookQueryService.findAllWithMetadataByIds(Set.of(bookId)))
|
||||||
|
.thenReturn(List.of(epubBook));
|
||||||
|
when(koboCompatibilityService.isBookSupportedForKobo(epubBook))
|
||||||
|
.thenReturn(true);
|
||||||
|
when(koboUrlBuilder.downloadUrl(token, epubBook.getId()))
|
||||||
|
.thenReturn("http://test.com/download/" + epubBook.getId());
|
||||||
|
when(appSettingService.getAppSettings())
|
||||||
|
.thenReturn(createAppSettingsWithKoboSettings());
|
||||||
|
|
||||||
|
KoboBookMetadata result = koboEntitlementService.getMetadataForBook(bookId, token);
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(subtitle, result.getSubtitle());
|
||||||
|
}
|
||||||
|
|
||||||
private BookEntity createCbxBookEntity(Long id) {
|
private BookEntity createCbxBookEntity(Long id) {
|
||||||
BookEntity book = new BookEntity();
|
BookEntity book = new BookEntity();
|
||||||
book.setId(id);
|
book.setId(id);
|
||||||
|
|||||||
Reference in New Issue
Block a user