fix(bookdrop): fix 'Select All' query logic and improve filename fallback for missing metadata (#1828)
* fix(bookdrop): fix 'Select All' query logic and improve filename fallback for missing metadata Signed-off-by: Balázs Szücs <bszucs1209@gmail.com> * fix(tests): update BookDropServiceTest and PathPatternResolverTest to use findAllIds method 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:
+3
@@ -31,5 +31,8 @@ public interface BookdropFileRepository extends JpaRepository<BookdropFileEntity
|
||||
|
||||
@Query("SELECT f.id FROM BookdropFileEntity f WHERE f.id NOT IN :excludedIds")
|
||||
List<Long> findAllExcludingIdsFlat(@Param("excludedIds") List<Long> excludedIds);
|
||||
|
||||
@Query("SELECT f.id FROM BookdropFileEntity f")
|
||||
List<Long> findAllIds();
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -186,7 +186,12 @@ public class BookDropService {
|
||||
AtomicInteger failedCount,
|
||||
AtomicInteger totalFilesProcessed) {
|
||||
List<Long> excludedIds = Optional.ofNullable(request.getExcludedIds()).orElse(List.of());
|
||||
List<Long> allIds = bookdropFileRepository.findAllExcludingIdsFlat(excludedIds);
|
||||
List<Long> allIds;
|
||||
if (excludedIds.isEmpty()) {
|
||||
allIds = bookdropFileRepository.findAllIds();
|
||||
} else {
|
||||
allIds = bookdropFileRepository.findAllExcludingIdsFlat(excludedIds);
|
||||
}
|
||||
log.info("SelectAll: Total files to finalize (after exclusions): {}, Excluded IDs: {}", allIds.size(), excludedIds);
|
||||
|
||||
processFileChunks(allIds, metadataById, defaultLibraryId, defaultPathId, results, failedCount, totalFilesProcessed);
|
||||
|
||||
+11
-1
@@ -55,9 +55,19 @@ public class PathPatternResolver {
|
||||
return filename;
|
||||
}
|
||||
|
||||
String filenameBase = "Untitled";
|
||||
if (filename != null && !filename.isBlank()) {
|
||||
int lastDot = filename.lastIndexOf('.');
|
||||
if (lastDot > 0) {
|
||||
filenameBase = filename.substring(0, lastDot);
|
||||
} else {
|
||||
filenameBase = filename;
|
||||
}
|
||||
}
|
||||
|
||||
String title = sanitize(metadata != null && metadata.getTitle() != null
|
||||
? metadata.getTitle()
|
||||
: "Untitled");
|
||||
: filenameBase);
|
||||
|
||||
String subtitle = sanitize(metadata != null ? metadata.getSubtitle() : "");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user