Fix kobo auto add on bookdrop. (#2116)
This commit is contained in:
+3
@@ -28,6 +28,7 @@ import com.adityachandel.booklore.service.NotificationService;
|
|||||||
import com.adityachandel.booklore.service.file.FileMovingHelper;
|
import com.adityachandel.booklore.service.file.FileMovingHelper;
|
||||||
import com.adityachandel.booklore.service.fileprocessor.BookFileProcessor;
|
import com.adityachandel.booklore.service.fileprocessor.BookFileProcessor;
|
||||||
import com.adityachandel.booklore.service.fileprocessor.BookFileProcessorRegistry;
|
import com.adityachandel.booklore.service.fileprocessor.BookFileProcessorRegistry;
|
||||||
|
import com.adityachandel.booklore.service.kobo.KoboAutoShelfService;
|
||||||
import com.adityachandel.booklore.service.metadata.MetadataRefreshService;
|
import com.adityachandel.booklore.service.metadata.MetadataRefreshService;
|
||||||
import com.adityachandel.booklore.service.monitoring.MonitoringRegistrationService;
|
import com.adityachandel.booklore.service.monitoring.MonitoringRegistrationService;
|
||||||
import com.adityachandel.booklore.util.FileUtils;
|
import com.adityachandel.booklore.util.FileUtils;
|
||||||
@@ -76,6 +77,7 @@ public class BookDropService {
|
|||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
private final FileMovingHelper fileMovingHelper;
|
private final FileMovingHelper fileMovingHelper;
|
||||||
private final MonitoringRegistrationService monitoringRegistrationService;
|
private final MonitoringRegistrationService monitoringRegistrationService;
|
||||||
|
private final KoboAutoShelfService koboAutoShelfService;
|
||||||
|
|
||||||
private static final int CHUNK_SIZE = 100;
|
private static final int CHUNK_SIZE = 100;
|
||||||
|
|
||||||
@@ -476,6 +478,7 @@ public class BookDropService {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
metadataRefreshService.updateBookMetadata(context);
|
metadataRefreshService.updateBookMetadata(context);
|
||||||
|
koboAutoShelfService.autoAddBookToKoboShelves(bookEntity.getId());
|
||||||
|
|
||||||
cleanupBookdropData(bookdropFile);
|
cleanupBookdropData(bookdropFile);
|
||||||
|
|
||||||
|
|||||||
+5
@@ -15,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -66,6 +67,10 @@ public class KoboAutoShelfService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (book.getShelves() == null) {
|
||||||
|
book.setShelves(new HashSet<>());
|
||||||
|
}
|
||||||
|
|
||||||
if (book.getShelves().contains(shelf)) {
|
if (book.getShelves().contains(shelf)) {
|
||||||
log.debug("Book {} already on Kobo shelf for user {}", book.getId(), setting.getUserId());
|
log.debug("Book {} already on Kobo shelf for user {}", book.getId(), setting.getUserId());
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
+3
@@ -6,6 +6,7 @@ import com.adityachandel.booklore.repository.BookdropFileRepository;
|
|||||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||||
import com.adityachandel.booklore.service.NotificationService;
|
import com.adityachandel.booklore.service.NotificationService;
|
||||||
import com.adityachandel.booklore.service.file.FileMovingHelper;
|
import com.adityachandel.booklore.service.file.FileMovingHelper;
|
||||||
|
import com.adityachandel.booklore.service.kobo.KoboAutoShelfService;
|
||||||
import com.adityachandel.booklore.service.monitoring.MonitoringRegistrationService;
|
import com.adityachandel.booklore.service.monitoring.MonitoringRegistrationService;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -40,6 +41,8 @@ class BookDropServiceFinalizeTest {
|
|||||||
private AppProperties appProperties;
|
private AppProperties appProperties;
|
||||||
@Mock
|
@Mock
|
||||||
private BookdropNotificationService bookdropNotificationService;
|
private BookdropNotificationService bookdropNotificationService;
|
||||||
|
@Mock
|
||||||
|
private KoboAutoShelfService koboAutoShelfService;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private BookDropService bookDropService;
|
private BookDropService bookDropService;
|
||||||
|
|||||||
+3
@@ -21,6 +21,7 @@ import com.adityachandel.booklore.service.NotificationService;
|
|||||||
import com.adityachandel.booklore.service.file.FileMovingHelper;
|
import com.adityachandel.booklore.service.file.FileMovingHelper;
|
||||||
import com.adityachandel.booklore.service.fileprocessor.BookFileProcessor;
|
import com.adityachandel.booklore.service.fileprocessor.BookFileProcessor;
|
||||||
import com.adityachandel.booklore.service.fileprocessor.BookFileProcessorRegistry;
|
import com.adityachandel.booklore.service.fileprocessor.BookFileProcessorRegistry;
|
||||||
|
import com.adityachandel.booklore.service.kobo.KoboAutoShelfService;
|
||||||
import com.adityachandel.booklore.service.metadata.MetadataRefreshService;
|
import com.adityachandel.booklore.service.metadata.MetadataRefreshService;
|
||||||
import com.adityachandel.booklore.service.monitoring.MonitoringRegistrationService;
|
import com.adityachandel.booklore.service.monitoring.MonitoringRegistrationService;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -84,6 +85,8 @@ class BookDropServiceTest {
|
|||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
@Mock
|
@Mock
|
||||||
private FileMovingHelper fileMovingHelper;
|
private FileMovingHelper fileMovingHelper;
|
||||||
|
@Mock
|
||||||
|
private KoboAutoShelfService koboAutoShelfService;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private BookDropService bookDropService;
|
private BookDropService bookDropService;
|
||||||
|
|||||||
+6
-4
@@ -259,9 +259,11 @@ class KoboAutoShelfServiceTest {
|
|||||||
when(shelfRepository.findByUserIdInAndName(List.of(100L), ShelfType.KOBO.getName()))
|
when(shelfRepository.findByUserIdInAndName(List.of(100L), ShelfType.KOBO.getName()))
|
||||||
.thenReturn(List.of(koboShelf1));
|
.thenReturn(List.of(koboShelf1));
|
||||||
|
|
||||||
try {
|
koboAutoShelfService.autoAddBookToKoboShelves(1L);
|
||||||
koboAutoShelfService.autoAddBookToKoboShelves(1L);
|
|
||||||
} catch (NullPointerException e) {
|
verify(bookRepository).save(testBook);
|
||||||
}
|
assert testBook.getShelves() != null;
|
||||||
|
assert testBook.getShelves().contains(koboShelf1);
|
||||||
|
assert testBook.getShelves().size() == 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user