refactor(exception): modernize exception handling and method signatures across services and controllers (#1670)

* refactor(exception): modernize exception handling and method signatures across services and controllers

- Remove unnecessary checked exceptions from method signatures
- Replace IOException with UncheckedIOException where appropriate
- Update test methods to match new signatures and remove throws declarations
- Improve converter classes with type safety, logging, and null handling
- Simplify collection assignment logic in metadata and book services
- Enhance author and category tokenization in HardcoverParser
- Add equals/hashCode to ShelfEntity for proper set behavior
- Add comprehensive unit tests for converter and service classes

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* refactor(entity): update equality and hashCode for JPA entities to use ID; add comprehensive tests and adjust test data to set IDs

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

---------

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
Balázs Szücs
2025-11-30 09:41:15 -07:00
committed by GitHub
parent 965aa9dfab
commit 2336d04a46
46 changed files with 586 additions and 103 deletions
@@ -90,7 +90,7 @@ public class SecurityConfig {
@Bean
@Order(2)
public SecurityFilterChain koreaderSecurityChain(HttpSecurity http, KoreaderAuthFilter koreaderAuthFilter) throws Exception {
public SecurityFilterChain koreaderSecurityChain(HttpSecurity http, KoreaderAuthFilter koreaderAuthFilter) {
http
.securityMatcher("/api/koreader/**")
.csrf(AbstractHttpConfigurer::disable)
@@ -64,7 +64,7 @@ public class AdditionalFileController {
@PreAuthorize("@securityUtil.canDeleteBook() or @securityUtil.isAdmin()")
public ResponseEntity<Void> deleteAdditionalFile(
@PathVariable Long bookId,
@PathVariable Long fileId) throws IOException {
@PathVariable Long fileId) {
additionalFileService.deleteAdditionalFile(fileId);
return ResponseEntity.noContent().build();
}
@@ -33,7 +33,7 @@ public class FileUploadController {
public ResponseEntity<?> uploadFile(
@Parameter(description = "File to upload") @RequestParam("file") MultipartFile file,
@Parameter(description = "Library ID") @RequestParam("libraryId") long libraryId,
@Parameter(description = "Path ID") @RequestParam("pathId") long pathId) throws IOException {
@Parameter(description = "Path ID") @RequestParam("pathId") long pathId) {
if (file.isEmpty()) {
throw new IllegalArgumentException("Uploaded file is missing.");
}
@@ -165,7 +165,7 @@ public class KoboController {
@ApiResponse(responseCode = "200", description = "Book downloaded successfully")
@GetMapping("/v1/books/{bookId}/download")
public void downloadBook(
@Parameter(description = "Book ID") @PathVariable String bookId, HttpServletResponse response) throws IOException {
@Parameter(description = "Book ID") @PathVariable String bookId, HttpServletResponse response) {
if (StringUtils.isNumeric(bookId)) {
bookDownloadService.downloadKoboBook(Long.parseLong(bookId), response);
} else {
@@ -7,14 +7,17 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.util.Set;
@Converter
@Slf4j
public class BookRecommendationIdsListConverter implements AttributeConverter<Set<BookRecommendationLite>, String> {
private static final ObjectMapper objectMapper = new ObjectMapper();
private static final TypeReference<Set<BookRecommendationLite>> SET_TYPE_REF = new TypeReference<>() {};
static {
objectMapper.registerModule(new JavaTimeModule());
@@ -22,9 +25,13 @@ public class BookRecommendationIdsListConverter implements AttributeConverter<Se
@Override
public String convertToDatabaseColumn(Set<BookRecommendationLite> recommendations) {
if (recommendations == null) {
return null;
}
try {
return objectMapper.writeValueAsString(recommendations);
} catch (JsonProcessingException e) {
log.error("Failed to convert BookRecommendation set to JSON string: {}", recommendations, e);
throw new RuntimeException("Error converting BookRecommendation list to JSON", e);
}
}
@@ -35,9 +42,9 @@ public class BookRecommendationIdsListConverter implements AttributeConverter<Se
return Set.of();
}
try {
return objectMapper.readValue(json, new TypeReference<Set<BookRecommendationLite>>() {
});
return objectMapper.readValue(json, SET_TYPE_REF);
} catch (Exception e) {
log.error("Failed to convert JSON string to BookRecommendation set: {}", json, e);
throw new RuntimeException("Error converting JSON to BookRecommendation list", e);
}
}
@@ -1,6 +1,7 @@
package com.adityachandel.booklore.convertor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
@@ -10,12 +11,13 @@ import java.util.Map;
@Converter
@Slf4j
public class JpaJsonConverter implements AttributeConverter<Map, String> {
public class JpaJsonConverter implements AttributeConverter<Map<String, Object>, String> {
private static final ObjectMapper objectMapper = new ObjectMapper();
private static final TypeReference<Map<String, Object>> MAP_TYPE_REF = new TypeReference<>() {};
@Override
public String convertToDatabaseColumn(Map attribute) {
public String convertToDatabaseColumn(Map<String, Object> attribute) {
if (attribute == null) {
return null;
}
@@ -28,12 +30,12 @@ public class JpaJsonConverter implements AttributeConverter<Map, String> {
}
@Override
public Map convertToEntityAttribute(String dbData) {
public Map<String, Object> convertToEntityAttribute(String dbData) {
if (dbData == null || dbData.isEmpty()) {
return null;
}
try {
return objectMapper.readValue(dbData, Map.class);
return objectMapper.readValue(dbData, MAP_TYPE_REF);
} catch (JsonProcessingException e) {
log.error("Error converting JSON to map", e);
return null;
@@ -1,31 +1,43 @@
package com.adityachandel.booklore.convertor;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.Map;
@Converter(autoApply = true)
public class MapToStringConverter implements AttributeConverter<Map, String> {
@Slf4j
public class MapToStringConverter implements AttributeConverter<Map<String, Object>, String> {
private static final ObjectMapper objectMapper = new ObjectMapper();
private static final TypeReference<Map<String, Object>> MAP_TYPE_REF = new TypeReference<>() {};
@Override
public String convertToDatabaseColumn(Map attribute) {
public String convertToDatabaseColumn(Map<String, Object> attribute) {
if (attribute == null) {
return null;
}
try {
return objectMapper.writeValueAsString(attribute);
} catch (IOException e) {
log.error("Failed to convert map to JSON string: {}", attribute, e);
throw new IllegalArgumentException("Error converting Map to String", e);
}
}
@Override
public Map convertToEntityAttribute(String dbData) {
public Map<String, Object> convertToEntityAttribute(String dbData) {
if (dbData == null || dbData.trim().isEmpty()) {
return null;
}
try {
return objectMapper.readValue(dbData, Map.class);
return objectMapper.readValue(dbData, MAP_TYPE_REF);
} catch (IOException e) {
log.error("Failed to convert JSON string to map: {}", dbData, e);
throw new IllegalArgumentException("Error converting String to Map", e);
}
}
@@ -28,13 +28,12 @@ public class AuthorEntity {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AuthorEntity authorEntity = (AuthorEntity) o;
return Objects.equals(name, authorEntity.name);
if (!(o instanceof AuthorEntity that)) return false;
return getId() != null && Objects.equals(getId(), that.getId());
}
@Override
public int hashCode() {
return name != null ? name.hashCode() : 0;
return getClass().hashCode();
}
}
@@ -3,6 +3,7 @@ package com.adityachandel.booklore.model.entity;
import jakarta.persistence.Embeddable;
import lombok.*;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
@@ -13,6 +14,9 @@ import java.util.Objects;
@AllArgsConstructor
public class BookMetadataAuthorKey implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Long bookId;
private Long authorId;
@@ -3,6 +3,7 @@ package com.adityachandel.booklore.model.entity;
import jakarta.persistence.Embeddable;
import lombok.*;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
@@ -13,6 +14,9 @@ import java.util.Objects;
@AllArgsConstructor
public class BookMetadataCategoryKey implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Long bookId;
private Long categoryId;
@@ -3,6 +3,7 @@ package com.adityachandel.booklore.model.entity;
import jakarta.persistence.Embeddable;
import lombok.*;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
@@ -13,6 +14,9 @@ import java.util.Objects;
@AllArgsConstructor
public class BookShelfKey implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Long bookId;
private Long shelfId;
@@ -4,6 +4,7 @@ import jakarta.persistence.*;
import lombok.*;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
@Entity
@@ -30,12 +31,12 @@ public class CategoryEntity {
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CategoryEntity that)) return false;
return name != null && name.equalsIgnoreCase(that.name);
return getId() != null && Objects.equals(getId(), that.getId());
}
@Override
public int hashCode() {
return name != null ? name.toLowerCase().hashCode() : 0;
return getClass().hashCode();
}
}
@@ -4,6 +4,7 @@ import jakarta.persistence.*;
import lombok.*;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
@Entity
@@ -30,12 +31,12 @@ public class MoodEntity {
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MoodEntity that)) return false;
return name != null && name.equalsIgnoreCase(that.name);
return getId() != null && Objects.equals(getId(), that.getId());
}
@Override
public int hashCode() {
return name != null ? name.toLowerCase().hashCode() : 0;
return getClass().hashCode();
}
}
@@ -13,6 +13,7 @@ import java.util.Set;
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(of = "id")
@Entity
@Table(name = "shelf")
public class ShelfEntity {
@@ -4,6 +4,7 @@ import jakarta.persistence.*;
import lombok.*;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
@Entity
@@ -30,11 +31,11 @@ public class TagEntity {
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TagEntity that)) return false;
return name != null && name.equalsIgnoreCase(that.name);
return getId() != null && Objects.equals(getId(), that.getId());
}
@Override
public int hashCode() {
return name != null ? name.toLowerCase().hashCode() : 0;
return getClass().hashCode();
}
}
@@ -86,7 +86,8 @@ public class AppSettingService {
builder.remoteAuthEnabled(appProperties.getRemoteAuth().isEnabled());
builder.defaultMetadataRefreshOptions(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.QUICK_BOOK_MATCH, MetadataRefreshOptions.class, settingPersistenceHelper.getDefaultMetadataRefreshOptions(), true));
builder.libraryMetadataRefreshOptions(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.LIBRARY_METADATA_REFRESH_OPTIONS, new TypeReference<List<MetadataRefreshOptions>>() {}, List.of(), true));
builder.libraryMetadataRefreshOptions(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.LIBRARY_METADATA_REFRESH_OPTIONS, new TypeReference<>() {
}, List.of(), true));
builder.oidcProviderDetails(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.OIDC_PROVIDER_DETAILS, OidcProviderDetails.class, null, false));
builder.oidcAutoProvisionDetails(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.OIDC_AUTO_PROVISION_DETAILS, OidcAutoProvisionDetails.class, null, false));
builder.metadataProviderSettings(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.METADATA_PROVIDER_SETTINGS, MetadataProviderSettings.class, settingPersistenceHelper.getDefaultMetadataProviderSettings(), true));
@@ -23,6 +23,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -124,10 +125,12 @@ public class BookDownloadService {
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);
}
private void streamFileToResponse(File file, HttpServletResponse response) throws IOException {
private void streamFileToResponse(File file, HttpServletResponse response) {
try (InputStream in = Files.newInputStream(file.toPath())) {
in.transferTo(response.getOutputStream());
response.getOutputStream().flush();
} catch (IOException e) {
throw new UncheckedIOException("Failed to stream file to response", e);
}
}
@@ -500,11 +500,7 @@ public class BookService {
List<ShelfEntity> shelvesToAssign = shelfRepository.findAllById(shelfIdsToAssign);
for (BookEntity bookEntity : bookEntities) {
bookEntity.getShelves().removeIf(shelf -> shelfIdsToUnassign.contains(shelf.getId()));
for (ShelfEntity shelf : shelvesToAssign) {
if (!bookEntity.getShelves().contains(shelf)) {
bookEntity.getShelves().add(shelf);
}
}
bookEntity.getShelves().addAll(shelvesToAssign);
}
bookRepository.saveAll(bookEntities);
@@ -604,7 +600,7 @@ public class BookService {
: ResponseEntity.status(HttpStatus.MULTI_STATUS).body(response);
}
public void deleteEmptyParentDirsUpToLibraryFolders(Path currentDir, Set<Path> libraryRoots) throws IOException {
public void deleteEmptyParentDirsUpToLibraryFolders(Path currentDir, Set<Path> libraryRoots) {
Path dir = currentDir;
Set<String> ignoredFilenames = Set.of(".DS_Store", "Thumbs.db");
dir = dir.toAbsolutePath().normalize();
@@ -34,7 +34,7 @@ import com.adityachandel.booklore.util.FileUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.PathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -97,7 +97,7 @@ public class BookDropService {
String coverPath = Paths.get(appProperties.getPathConfig(), "bookdrop_temp", bookdropId + ".jpg").toString();
File coverFile = new File(coverPath);
if (coverFile.exists() && coverFile.isFile()) {
return new PathResource(coverFile.toPath());
return new FileSystemResource(coverFile.toPath());
} else {
return null;
}
@@ -442,7 +442,7 @@ public class BookDropService {
File targetFile,
LibraryEntity library,
LibraryPathEntity path,
BookMetadata metadata) throws Exception {
BookMetadata metadata) {
FileProcessResult fileProcessResult = processFileInLibrary(targetFile.getName(), library, path, targetFile,
BookFileExtension.fromFileName(bookdropFile.getFileName())
.orElseThrow(() -> ApiError.INVALID_FILE_FORMAT.createException("Unsupported file extension"))
@@ -106,7 +106,7 @@ public class FileMoveHelper {
return Paths.get(path, newRelativePathStr);
}
public void deleteEmptyParentDirsUpToLibraryFolders(Path currentDir, Set<Path> libraryRoots) throws IOException {
public void deleteEmptyParentDirsUpToLibraryFolders(Path currentDir, Set<Path> libraryRoots) {
Path dir = currentDir;
Set<String> ignoredFilenames = Set.of(".DS_Store", "Thumbs.db");
dir = dir.toAbsolutePath().normalize();
@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;
@@ -39,13 +40,19 @@ public class LibraryProcessingService {
private final EntityManager entityManager;
@Transactional
public void processLibrary(long libraryId) throws IOException {
public void processLibrary(long libraryId) {
LibraryEntity libraryEntity = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
notificationService.sendMessage(Topic.LOG, LogNotification.info("Started processing library: " + libraryEntity.getName()));
LibraryFileProcessor processor = fileProcessorRegistry.getProcessor(libraryEntity);
List<LibraryFile> libraryFiles = libraryFileHelper.getLibraryFiles(libraryEntity, processor);
processor.processLibraryFiles(libraryFiles, libraryEntity);
notificationService.sendMessage(Topic.LOG, LogNotification.info("Finished processing library: " + libraryEntity.getName()));
try {
List<LibraryFile> libraryFiles = libraryFileHelper.getLibraryFiles(libraryEntity, processor);
processor.processLibraryFiles(libraryFiles, libraryEntity);
notificationService.sendMessage(Topic.LOG, LogNotification.info("Finished processing library: " + libraryEntity.getName()));
} catch (IOException e) {
log.error("Failed to process library {}: {}", libraryEntity.getName(), e.getMessage(), e);
notificationService.sendMessage(Topic.LOG, LogNotification.error("Failed to process library: " + libraryEntity.getName() + " - " + e.getMessage()));
throw new UncheckedIOException("Library processing failed", e);
}
}
@Transactional
@@ -130,8 +130,6 @@ public class LibraryService {
libraryProcessingService.processLibrary(libraryId);
} catch (InvalidDataAccessApiUsageException e) {
log.debug("InvalidDataAccessApiUsageException - Library id: {}", libraryId);
} catch (IOException e) {
log.error("Error while parsing library books", e);
}
log.info("Parsing task completed!");
});
@@ -171,8 +169,6 @@ public class LibraryService {
libraryProcessingService.processLibrary(libraryId);
} catch (InvalidDataAccessApiUsageException e) {
log.debug("InvalidDataAccessApiUsageException - Library id: {}", libraryId);
} catch (IOException e) {
log.error("Error while parsing library books", e);
}
log.info("Parsing task completed!");
});
@@ -111,11 +111,7 @@ public class MetadataManagementService {
for (BookMetadataEntity metadata : booksWithOldAuthor) {
metadata.getAuthors().remove(oldAuthor);
for (AuthorEntity targetAuthor : targetAuthors) {
if (!metadata.getAuthors().contains(targetAuthor)) {
metadata.getAuthors().add(targetAuthor);
}
}
metadata.getAuthors().addAll(targetAuthors);
}
bookMetadataRepository.saveAll(booksWithOldAuthor);
@@ -156,11 +152,7 @@ public class MetadataManagementService {
for (BookMetadataEntity metadata : booksWithOldCategory) {
metadata.getCategories().remove(oldCategory);
for (CategoryEntity targetCategory : targetCategories) {
if (!metadata.getCategories().contains(targetCategory)) {
metadata.getCategories().add(targetCategory);
}
}
metadata.getCategories().addAll(targetCategories);
}
bookMetadataRepository.saveAll(booksWithOldCategory);
@@ -201,11 +193,7 @@ public class MetadataManagementService {
for (BookMetadataEntity metadata : booksWithOldMood) {
metadata.getMoods().remove(oldMood);
for (MoodEntity targetMood : targetMoods) {
if (!metadata.getMoods().contains(targetMood)) {
metadata.getMoods().add(targetMood);
}
}
metadata.getMoods().addAll(targetMoods);
}
bookMetadataRepository.saveAll(booksWithOldMood);
@@ -246,11 +234,7 @@ public class MetadataManagementService {
for (BookMetadataEntity metadata : booksWithOldTag) {
metadata.getTags().remove(oldTag);
for (TagEntity targetTag : targetTags) {
if (!metadata.getTags().contains(targetTag)) {
metadata.getTags().add(targetTag);
}
}
metadata.getTags().addAll(targetTags);
}
bookMetadataRepository.saveAll(booksWithOldTag);
@@ -672,7 +672,7 @@ public class CbxMetadataExtractor implements FileMetadataExtractor {
}
// ==== 7z (.cb7) helpers ====
private SevenZArchiveEntry findSevenZComicInfoEntry(SevenZFile sevenZ) throws IOException {
private SevenZArchiveEntry findSevenZComicInfoEntry(SevenZFile sevenZ) {
for (SevenZArchiveEntry e : sevenZ.getEntries()) {
if (e == null || e.isDirectory()) continue;
String name = e.getName();
@@ -683,7 +683,7 @@ public class CbxMetadataExtractor implements FileMetadataExtractor {
return null;
}
private SevenZArchiveEntry findSevenZEntryByName(SevenZFile sevenZ, String imageName) throws IOException {
private SevenZArchiveEntry findSevenZEntryByName(SevenZFile sevenZ, String imageName) {
if (imageName == null) return null;
for (SevenZArchiveEntry e : sevenZ.getEntries()) {
if (e == null || e.isDirectory()) continue;
@@ -696,7 +696,7 @@ public class CbxMetadataExtractor implements FileMetadataExtractor {
return null;
}
private SevenZArchiveEntry findSevenZImageEntryByIndex(SevenZFile sevenZ, int index) throws IOException {
private SevenZArchiveEntry findSevenZImageEntryByIndex(SevenZFile sevenZ, int index) {
int count = 0;
for (SevenZArchiveEntry e : sevenZ.getEntries()) {
if (!e.isDirectory() && isImageEntry(e.getName())) {
@@ -707,7 +707,7 @@ public class CbxMetadataExtractor implements FileMetadataExtractor {
return null;
}
private SevenZArchiveEntry findFirstAlphabeticalSevenZImageEntry(SevenZFile sevenZ) throws IOException {
private SevenZArchiveEntry findFirstAlphabeticalSevenZImageEntry(SevenZFile sevenZ) {
List<SevenZArchiveEntry> images = new ArrayList<>();
for (SevenZArchiveEntry e : sevenZ.getEntries()) {
if (!e.isDirectory() && isImageEntry(e.getName())) {
@@ -741,7 +741,7 @@ public class CbxMetadataExtractor implements FileMetadataExtractor {
return images;
}
private java.util.List<SevenZArchiveEntry> listSevenZImageEntries(SevenZFile sevenZ) throws IOException {
private java.util.List<SevenZArchiveEntry> listSevenZImageEntries(SevenZFile sevenZ) {
java.util.List<SevenZArchiveEntry> images = new java.util.ArrayList<>();
for (SevenZArchiveEntry e : sevenZ.getEntries()) {
if (!e.isDirectory() && isImageEntry(e.getName())) images.add(e);
@@ -137,14 +137,14 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
if ("calibre:pages".equals(name) || "pagecount".equals(name) || "schema:pagecount".equals(prop) || "media:pagecount".equals(prop) || "booklore:page_count".equals(prop)) {
safeParseInt(content, builderMeta::pageCount);
} else if (name.equals("calibre:user_metadata:#pagecount")) {
} else if ("calibre:user_metadata:#pagecount".equals(name)) {
try {
JSONObject jsonroot = new JSONObject(content);
Object value = jsonroot.opt("#value#");
safeParseInt(String.valueOf(value), builderMeta::pageCount);
} catch (JSONException ignored) {
}
} else if (prop.equals("calibre:user_metadata")) {
} else if ("calibre:user_metadata".equals(prop)) {
try {
JSONObject jsonroot = new JSONObject(content);
JSONObject pages = jsonroot.getJSONObject("#pagecount");
@@ -236,7 +236,6 @@ public class DoubanBookParser implements BookParser {
}
} catch (Exception e) {
log.warn("Error parsing search result item: {}", e.getMessage());
continue;
}
}
@@ -20,6 +20,7 @@ import java.util.Locale;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Slf4j
@Service
@@ -59,7 +60,8 @@ public class HardcoverParser implements BookParser {
if (doc.getAuthorNames() == null || doc.getAuthorNames().isEmpty()) return false;
List<String> actualAuthorTokens = doc.getAuthorNames().stream()
.flatMap(name -> List.of(WHITESPACE_PATTERN.split(name.toLowerCase())).stream())
.map(String::toLowerCase)
.flatMap(WHITESPACE_PATTERN::splitAsStream)
.toList();
List<String> searchAuthorTokens = List.of(WHITESPACE_PATTERN.split(searchAuthor.toLowerCase()));
@@ -46,7 +46,6 @@ public class MonitoringTask {
log.warn("WatchKey is no longer valid: {}", directory);
// Clean up but DO NOT break
eventPublisher.publishEvent(new WatchKeyInvalidatedEvent(this, directory));
continue;
}
}
} catch (InterruptedException e) {
@@ -86,7 +86,7 @@ public class FileUploadService {
}
@Transactional
public AdditionalFile uploadAdditionalFile(Long bookId, MultipartFile file, AdditionalFileType additionalFileType, String description) throws IOException {
public AdditionalFile uploadAdditionalFile(Long bookId, MultipartFile file, AdditionalFileType additionalFileType, String description) {
final BookEntity book = findBookById(bookId);
final String originalFileName = getValidatedFileName(file);
@@ -225,7 +225,7 @@ public class FileUploadService {
}
}
private BookMetadata extractMetadata(BookFileExtension fileExt, File file) throws IOException {
private BookMetadata extractMetadata(BookFileExtension fileExt, File file) {
return metadataExtractorFactory.extractMetadata(fileExt, file);
}