Enable rescan library

This commit is contained in:
aditya.chandel
2025-02-08 06:48:19 -07:00
parent 25e2147aa0
commit f540679af9
3 changed files with 12 additions and 12 deletions
@@ -54,9 +54,9 @@ public class LibraryController {
return ResponseEntity.ok(books); return ResponseEntity.ok(books);
} }
/*@PutMapping("/{libraryId}/refresh") @PutMapping("/{libraryId}/refresh")
public ResponseEntity<?> refreshLibrary(@PathVariable long libraryId) { public ResponseEntity<?> refreshLibrary(@PathVariable long libraryId) {
libraryService.refreshLibrary(libraryId); libraryService.refreshLibrary(libraryId);
return ResponseEntity.noContent().build(); return ResponseEntity.noContent().build();
}*/ }
} }
@@ -101,14 +101,14 @@ public class LibraryProcessingService {
} }
} }
/*@Transactional @Transactional
public void refreshLibrary(long libraryId) throws IOException { public void refreshLibrary(long libraryId) throws IOException {
LibraryEntity libraryEntity = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId)); LibraryEntity libraryEntity = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
notificationService.sendMessage(Topic.LOG, createLogNotification("Started refreshing library: " + libraryEntity.getName())); notificationService.sendMessage(Topic.LOG, createLogNotification("Started refreshing library: " + libraryEntity.getName()));
processLibraryFiles(getUnProcessedFiles(libraryEntity)); processLibraryFiles(getUnProcessedFiles(libraryEntity));
deleteRemovedBooks(getRemovedBooks(libraryEntity)); deleteRemovedBooks(getRemovedBooks(libraryEntity));
notificationService.sendMessage(Topic.LOG, createLogNotification("Finished refreshing library: " + libraryEntity.getName())); notificationService.sendMessage(Topic.LOG, createLogNotification("Finished refreshing library: " + libraryEntity.getName()));
}*/ }
@Transactional @Transactional
protected void deleteRemovedBooks(List<BookEntity> removedBookEntities) { protected void deleteRemovedBooks(List<BookEntity> removedBookEntities) {
@@ -143,7 +143,7 @@ public class LibraryProcessingService {
return null; return null;
} }
/*@Transactional @Transactional
protected List<BookEntity> getRemovedBooks(LibraryEntity libraryEntity) throws IOException { protected List<BookEntity> getRemovedBooks(LibraryEntity libraryEntity) throws IOException {
List<LibraryFile> libraryFiles = getLibraryFiles(libraryEntity); List<LibraryFile> libraryFiles = getLibraryFiles(libraryEntity);
List<BookEntity> bookEntities = libraryEntity.getBookEntities(); List<BookEntity> bookEntities = libraryEntity.getBookEntities();
@@ -151,21 +151,21 @@ public class LibraryProcessingService {
.map(LibraryFile::getFileName) .map(LibraryFile::getFileName)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
return bookEntities.stream() return bookEntities.stream()
.filter(book -> !libraryFilePaths.contains(book.getPath())) .filter(book -> !libraryFilePaths.contains(book.getFileName()))
.collect(Collectors.toList()); .collect(Collectors.toList());
}*/ }
/*@Transactional @Transactional
protected List<LibraryFile> getUnProcessedFiles(LibraryEntity libraryEntity) throws IOException { protected List<LibraryFile> getUnProcessedFiles(LibraryEntity libraryEntity) throws IOException {
List<LibraryFile> libraryFiles = getLibraryFiles(libraryEntity); List<LibraryFile> libraryFiles = getLibraryFiles(libraryEntity);
List<BookEntity> bookEntities = libraryEntity.getBookEntities(); List<BookEntity> bookEntities = libraryEntity.getBookEntities();
Set<String> processedPaths = bookEntities.stream() Set<String> processedPaths = bookEntities.stream()
.map(BookEntity::getPath) .map(BookEntity::getFileName)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
return libraryFiles.stream() return libraryFiles.stream()
.filter(libraryFile -> !processedPaths.contains(libraryFile.getFileName())) .filter(libraryFile -> !processedPaths.contains(libraryFile.getFileName()))
.collect(Collectors.toList()); .collect(Collectors.toList());
}*/ }
private List<LibraryFile> getLibraryFiles(LibraryEntity libraryEntity) throws IOException { private List<LibraryFile> getLibraryFiles(LibraryEntity libraryEntity) throws IOException {
List<LibraryFile> libraryFiles = new ArrayList<>(); List<LibraryFile> libraryFiles = new ArrayList<>();
@@ -170,7 +170,7 @@ public class LibraryService {
return libraryMapper.toLibrary(libraryEntity); return libraryMapper.toLibrary(libraryEntity);
} }
/*public void refreshLibrary(long libraryId) { public void refreshLibrary(long libraryId) {
libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId)); libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
Thread.startVirtualThread(() -> { Thread.startVirtualThread(() -> {
try { try {
@@ -182,7 +182,7 @@ public class LibraryService {
} }
log.info("Parsing task completed!"); log.info("Parsing task completed!");
}); });
}*/ }
public Library getLibrary(long libraryId) { public Library getLibrary(long libraryId) {
LibraryEntity libraryEntity = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId)); LibraryEntity libraryEntity = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));