From f540679af977846396157fd019b7ad1371462ec3 Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Sat, 8 Feb 2025 06:48:19 -0700 Subject: [PATCH] Enable rescan library --- .../booklore/controller/LibraryController.java | 4 ++-- .../service/LibraryProcessingService.java | 16 ++++++++-------- .../booklore/service/LibraryService.java | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/controller/LibraryController.java b/booklore-api/src/main/java/com/adityachandel/booklore/controller/LibraryController.java index 52f07883e..de43ddc70 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/controller/LibraryController.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/controller/LibraryController.java @@ -54,9 +54,9 @@ public class LibraryController { return ResponseEntity.ok(books); } - /*@PutMapping("/{libraryId}/refresh") + @PutMapping("/{libraryId}/refresh") public ResponseEntity refreshLibrary(@PathVariable long libraryId) { libraryService.refreshLibrary(libraryId); return ResponseEntity.noContent().build(); - }*/ + } } \ No newline at end of file diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java index 36d508760..e487754d7 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java @@ -101,14 +101,14 @@ public class LibraryProcessingService { } } - /*@Transactional + @Transactional public void refreshLibrary(long libraryId) throws IOException { LibraryEntity libraryEntity = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId)); notificationService.sendMessage(Topic.LOG, createLogNotification("Started refreshing library: " + libraryEntity.getName())); processLibraryFiles(getUnProcessedFiles(libraryEntity)); deleteRemovedBooks(getRemovedBooks(libraryEntity)); notificationService.sendMessage(Topic.LOG, createLogNotification("Finished refreshing library: " + libraryEntity.getName())); - }*/ + } @Transactional protected void deleteRemovedBooks(List removedBookEntities) { @@ -143,7 +143,7 @@ public class LibraryProcessingService { return null; } - /*@Transactional + @Transactional protected List getRemovedBooks(LibraryEntity libraryEntity) throws IOException { List libraryFiles = getLibraryFiles(libraryEntity); List bookEntities = libraryEntity.getBookEntities(); @@ -151,21 +151,21 @@ public class LibraryProcessingService { .map(LibraryFile::getFileName) .collect(Collectors.toSet()); return bookEntities.stream() - .filter(book -> !libraryFilePaths.contains(book.getPath())) + .filter(book -> !libraryFilePaths.contains(book.getFileName())) .collect(Collectors.toList()); - }*/ + } - /*@Transactional + @Transactional protected List getUnProcessedFiles(LibraryEntity libraryEntity) throws IOException { List libraryFiles = getLibraryFiles(libraryEntity); List bookEntities = libraryEntity.getBookEntities(); Set processedPaths = bookEntities.stream() - .map(BookEntity::getPath) + .map(BookEntity::getFileName) .collect(Collectors.toSet()); return libraryFiles.stream() .filter(libraryFile -> !processedPaths.contains(libraryFile.getFileName())) .collect(Collectors.toList()); - }*/ + } private List getLibraryFiles(LibraryEntity libraryEntity) throws IOException { List libraryFiles = new ArrayList<>(); diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryService.java index d84d918f9..2e459ade4 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryService.java @@ -170,7 +170,7 @@ public class LibraryService { return libraryMapper.toLibrary(libraryEntity); } - /*public void refreshLibrary(long libraryId) { + public void refreshLibrary(long libraryId) { libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId)); Thread.startVirtualThread(() -> { try { @@ -182,7 +182,7 @@ public class LibraryService { } log.info("Parsing task completed!"); }); - }*/ + } public Library getLibrary(long libraryId) { LibraryEntity libraryEntity = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));