Implement task scheduling system (#1427)
* Implement task scheduling system * Remove tests
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.adityachandel.booklore.config;
|
||||
|
||||
import com.adityachandel.booklore.service.task.TaskService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class TaskSchedulerConfig {
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void initializeScheduledTasks() {
|
||||
log.info("Application ready, initializing scheduled tasks");
|
||||
taskService.initializeScheduledTasks();
|
||||
}
|
||||
}
|
||||
+39
-3
@@ -8,6 +8,7 @@ import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.request.UserLoginRequest;
|
||||
import com.adityachandel.booklore.model.entity.BookLoreUserEntity;
|
||||
import com.adityachandel.booklore.model.entity.RefreshTokenEntity;
|
||||
import com.adityachandel.booklore.model.enums.ProvisioningMethod;
|
||||
import com.adityachandel.booklore.repository.RefreshTokenRepository;
|
||||
import com.adityachandel.booklore.repository.UserRepository;
|
||||
import com.adityachandel.booklore.service.user.DefaultSettingInitializer;
|
||||
@@ -21,6 +22,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -39,14 +41,48 @@ public class AuthenticationService {
|
||||
|
||||
public BookLoreUser getAuthenticatedUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication == null) {
|
||||
return null;
|
||||
}
|
||||
Object principal = authentication.getPrincipal();
|
||||
if (principal instanceof BookLoreUser) {
|
||||
defaultSettingInitializer.ensureDefaultSettings((BookLoreUser) principal);
|
||||
return (BookLoreUser) principal;
|
||||
if (principal instanceof BookLoreUser user) {
|
||||
if (user.getId() != null && user.getId() != -1L) {
|
||||
defaultSettingInitializer.ensureDefaultSettings(user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
throw new IllegalStateException("Authenticated principal is not of type BookLoreUser");
|
||||
}
|
||||
|
||||
public BookLoreUser getSystemUser() {
|
||||
return createSystemUser();
|
||||
}
|
||||
|
||||
private BookLoreUser createSystemUser() {
|
||||
BookLoreUser.UserPermissions permissions = new BookLoreUser.UserPermissions();
|
||||
permissions.setAdmin(true);
|
||||
permissions.setCanUpload(true);
|
||||
permissions.setCanDownload(true);
|
||||
permissions.setCanEditMetadata(true);
|
||||
permissions.setCanManipulateLibrary(true);
|
||||
permissions.setCanSyncKoReader(true);
|
||||
permissions.setCanSyncKobo(true);
|
||||
permissions.setCanEmailBook(true);
|
||||
permissions.setCanDeleteBook(true);
|
||||
permissions.setCanAccessOpds(true);
|
||||
|
||||
return BookLoreUser.builder()
|
||||
.id(-1L)
|
||||
.username("system")
|
||||
.name("System User")
|
||||
.email("system@booklore.internal")
|
||||
.provisioningMethod(ProvisioningMethod.LOCAL)
|
||||
.isDefaultPassword(false)
|
||||
.permissions(permissions)
|
||||
.assignedLibraries(List.of())
|
||||
.userSettings(new BookLoreUser.UserSettings())
|
||||
.build();
|
||||
}
|
||||
|
||||
public OpdsUserDetails getOpdsUser() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package com.adityachandel.booklore.controller;
|
||||
import com.adityachandel.booklore.config.security.annotation.CheckBookAccess;
|
||||
import com.adityachandel.booklore.model.dto.AdditionalFile;
|
||||
import com.adityachandel.booklore.model.enums.AdditionalFileType;
|
||||
import com.adityachandel.booklore.service.AdditionalFileService;
|
||||
import com.adityachandel.booklore.service.file.AdditionalFileService;
|
||||
import com.adityachandel.booklore.service.upload.FileUploadService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
+1
-3
@@ -4,7 +4,7 @@ import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.UploadResponse;
|
||||
import com.adityachandel.booklore.model.dto.UrlRequest;
|
||||
import com.adityachandel.booklore.service.BackgroundUploadService;
|
||||
import com.adityachandel.booklore.service.file.BackgroundUploadService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
@@ -14,8 +14,6 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Tag(name = "Background Upload", description = "Endpoints for uploading and managing background images")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/background")
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import com.adityachandel.booklore.model.dto.request.ReadStatusUpdateRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.ShelvesAssignmentRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.BookDeletionResponse;
|
||||
import com.adityachandel.booklore.model.enums.ResetProgressType;
|
||||
import com.adityachandel.booklore.service.BookService;
|
||||
import com.adityachandel.booklore.service.book.BookService;
|
||||
import com.adityachandel.booklore.service.metadata.BookMetadataService;
|
||||
import com.adityachandel.booklore.service.recommender.BookRecommendationService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.service.BookService;
|
||||
import com.adityachandel.booklore.service.book.BookService;
|
||||
import com.adityachandel.booklore.service.bookdrop.BookDropService;
|
||||
import com.adityachandel.booklore.service.reader.CbxReaderService;
|
||||
import com.adityachandel.booklore.service.reader.PdfReaderService;
|
||||
|
||||
+1
-2
@@ -2,11 +2,10 @@ package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.BookNote;
|
||||
import com.adityachandel.booklore.model.dto.CreateBookNoteRequest;
|
||||
import com.adityachandel.booklore.service.BookNoteService;
|
||||
import com.adityachandel.booklore.service.book.BookNoteService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.BookReview;
|
||||
import com.adityachandel.booklore.service.BookReviewService;
|
||||
import com.adityachandel.booklore.service.book.BookReviewService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
|
||||
+2
-2
@@ -7,6 +7,8 @@ import com.adityachandel.booklore.model.dto.kobo.KoboReadingStateWrapper;
|
||||
import com.adityachandel.booklore.model.dto.kobo.KoboResources;
|
||||
import com.adityachandel.booklore.model.dto.kobo.KoboTestResponse;
|
||||
import com.adityachandel.booklore.service.*;
|
||||
import com.adityachandel.booklore.service.book.BookDownloadService;
|
||||
import com.adityachandel.booklore.service.book.BookService;
|
||||
import com.adityachandel.booklore.service.kobo.*;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
@@ -26,8 +28,6 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.KoboSyncSettings;
|
||||
import com.adityachandel.booklore.service.KoboSettingsService;
|
||||
import com.adityachandel.booklore.service.kobo.KoboSettingsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.progress.KoreaderProgress;
|
||||
import com.adityachandel.booklore.service.KoreaderService;
|
||||
import com.adityachandel.booklore.service.koreader.KoreaderService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.KoreaderUser;
|
||||
import com.adityachandel.booklore.service.KoreaderUserService;
|
||||
import com.adityachandel.booklore.service.koreader.KoreaderUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.MetadataBatchProgressNotification;
|
||||
import com.adityachandel.booklore.model.dto.response.MetadataTaskDetailsResponse;
|
||||
import com.adityachandel.booklore.service.MetadataTaskService;
|
||||
import com.adityachandel.booklore.service.metadata.MetadataTaskService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.service.BookService;
|
||||
import com.adityachandel.booklore.service.book.BookService;
|
||||
import com.adityachandel.booklore.service.opds.OpdsFeedService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
|
||||
+1
-2
@@ -1,9 +1,8 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
|
||||
import com.adityachandel.booklore.model.dto.OpdsUserV2;
|
||||
import com.adityachandel.booklore.model.dto.request.OpdsUserV2CreateRequest;
|
||||
import com.adityachandel.booklore.service.OpdsUserV2Service;
|
||||
import com.adityachandel.booklore.service.opds.OpdsUserV2Service;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.TaskInfo;
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCronConfigRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.CronConfig;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCancelResponse;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
||||
import com.adityachandel.booklore.model.dto.response.TasksHistoryResponse;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.service.task.TaskCronService;
|
||||
import com.adityachandel.booklore.service.task.TaskHistoryService;
|
||||
import com.adityachandel.booklore.service.task.TaskService;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/tasks")
|
||||
public class TaskController {
|
||||
|
||||
private final TaskService service;
|
||||
private final TaskHistoryService taskHistoryService;
|
||||
private final TaskCronService taskCronService;
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<List<TaskInfo>> getAvailableTasks() {
|
||||
List<TaskInfo> taskInfos = service.getAvailableTasks();
|
||||
return ResponseEntity.ok(taskInfos);
|
||||
}
|
||||
|
||||
@PostMapping("/start")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<TaskCreateResponse> startTask(@RequestBody TaskCreateRequest request) {
|
||||
TaskCreateResponse response = service.runAsUser(request);
|
||||
if (response.getStatus() == TaskStatus.ACCEPTED) {
|
||||
return ResponseEntity.status(HttpStatus.ACCEPTED).body(response);
|
||||
}
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{taskId}/cancel")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<TaskCancelResponse> cancelTask(@PathVariable String taskId) {
|
||||
TaskCancelResponse response = service.cancelTask(taskId);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@GetMapping("/last")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<TasksHistoryResponse> getLatestTasksForEachType() {
|
||||
TasksHistoryResponse response = taskHistoryService.getLatestTasksForEachType();
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@PatchMapping("/{taskType}/cron")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<CronConfig> patchCronConfig(@PathVariable TaskType taskType, @RequestBody TaskCronConfigRequest request) {
|
||||
CronConfig response = taskCronService.patchCronConfig(taskType, request);
|
||||
service.rescheduleTask(taskType);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCancelResponse;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskStatusResponse;
|
||||
import com.adityachandel.booklore.service.TaskHistoryService;
|
||||
import com.adityachandel.booklore.service.TaskService;
|
||||
import com.adityachandel.booklore.task.*;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v2/tasks")
|
||||
@Tag(name = "Tasks", description = "Endpoints for managing background tasks")
|
||||
public class TaskV2Controller {
|
||||
|
||||
private final TaskService service;
|
||||
private final TaskHistoryService taskHistoryService;
|
||||
|
||||
@Operation(summary = "Start a new task", description = "Start a new background task. Requires admin.")
|
||||
@ApiResponse(responseCode = "202", description = "Task accepted")
|
||||
@PostMapping
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<TaskCreateResponse> startTask(
|
||||
@Parameter(description = "Task creation request") @RequestBody TaskCreateRequest request) {
|
||||
TaskCreateResponse response = service.run(request);
|
||||
if (response.getStatus() == TaskStatus.ACCEPTED) {
|
||||
return ResponseEntity.status(HttpStatus.ACCEPTED).body(response);
|
||||
}
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Operation(summary = "Cancel a task", description = "Cancel a running task by its ID. Requires admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Task cancelled successfully")
|
||||
@DeleteMapping("/{taskId}")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<TaskCancelResponse> cancelTask(
|
||||
@Parameter(description = "ID of the task to cancel") @PathVariable String taskId) {
|
||||
TaskCancelResponse response = service.cancelTask(taskId);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get latest tasks for each type", description = "Retrieve the latest tasks for each type. Requires admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Latest tasks returned successfully")
|
||||
@GetMapping("/latest")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<TaskStatusResponse> getLatestTasksForEachType() {
|
||||
TaskStatusResponse response = taskHistoryService.getLatestTasksForEachType();
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,9 @@ public enum ApiError {
|
||||
UNSUPPORTED_FILE_TYPE(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "%s"),
|
||||
CONFLICT(HttpStatus.CONFLICT, "%s"),
|
||||
FILE_NOT_FOUND(HttpStatus.NOT_FOUND, "File not found: %s"),
|
||||
SHELF_CANNOT_BE_DELETED(HttpStatus.FORBIDDEN, "'%s' shelf can't be deleted" ),;
|
||||
SHELF_CANNOT_BE_DELETED(HttpStatus.FORBIDDEN, "'%s' shelf can't be deleted" ),
|
||||
TASK_NOT_FOUND(HttpStatus.NOT_FOUND, "Scheduled task not found: %s"),
|
||||
TASK_ALREADY_RUNNING(HttpStatus.CONFLICT, "Task is already running: %s"),;
|
||||
|
||||
private final HttpStatus status;
|
||||
private final String message;
|
||||
|
||||
@@ -10,6 +10,9 @@ import lombok.NoArgsConstructor;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class BookLoreUser {
|
||||
private Long id;
|
||||
private String username;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.adityachandel.booklore.model.dto;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.response.CronConfig;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class TaskInfo {
|
||||
private TaskType taskType;
|
||||
private String name;
|
||||
private String description;
|
||||
private boolean parallel;
|
||||
private boolean async;
|
||||
private boolean cronSupported;
|
||||
private CronConfig cronConfig;
|
||||
private String metadata;
|
||||
|
||||
public static TaskInfo fromTaskType(TaskType taskType) {
|
||||
return TaskInfo.builder()
|
||||
.taskType(taskType)
|
||||
.name(taskType.getName())
|
||||
.description(taskType.getDescription())
|
||||
.parallel(taskType.isParallel())
|
||||
.async(taskType.isAsync())
|
||||
.cronSupported(taskType.isCronSupported())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+3
-7
@@ -1,9 +1,7 @@
|
||||
package com.adityachandel.booklore.model.dto.request;
|
||||
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.task.tasks.options.ClearCbxCacheOptions;
|
||||
import com.adityachandel.booklore.task.tasks.options.ClearPdfCacheOptions;
|
||||
import com.adityachandel.booklore.task.tasks.options.LibraryRescanOptions;
|
||||
import com.adityachandel.booklore.task.options.LibraryRescanOptions;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -22,10 +20,8 @@ public class TaskCreateRequest {
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "taskType", include = JsonTypeInfo.As.EXTERNAL_PROPERTY)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = ClearCbxCacheOptions.class, name = "CLEAR_CBX_CACHE"),
|
||||
@JsonSubTypes.Type(value = ClearPdfCacheOptions.class, name = "CLEAR_PDF_CACHE"),
|
||||
@JsonSubTypes.Type(value = LibraryRescanOptions.class, name = "RE_SCAN_LIBRARY"),
|
||||
@JsonSubTypes.Type(value = MetadataRefreshRequest.class, name = "REFRESH_METADATA"),
|
||||
@JsonSubTypes.Type(value = LibraryRescanOptions.class, name = "REFRESH_LIBRARY_METADATA"),
|
||||
@JsonSubTypes.Type(value = MetadataRefreshRequest.class, name = "REFRESH_METADATA_MANUAL"),
|
||||
})
|
||||
private Object options;
|
||||
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.adityachandel.booklore.model.dto.request;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TaskCronConfigRequest {
|
||||
private String cronExpression;
|
||||
private Boolean enabled;
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.adityachandel.booklore.model.dto.response;
|
||||
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CronConfig {
|
||||
private Long id;
|
||||
private TaskType taskType;
|
||||
private String cronExpression;
|
||||
private Boolean enabled;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
|
||||
+3
-5
@@ -9,20 +9,19 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TaskStatusResponse {
|
||||
private List<TaskInfo> tasks;
|
||||
public class TasksHistoryResponse {
|
||||
private List<TaskHistory> taskHistories;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class TaskInfo {
|
||||
public static class TaskHistory {
|
||||
private String id;
|
||||
private TaskType type;
|
||||
private TaskStatus status;
|
||||
@@ -31,6 +30,5 @@ public class TaskStatusResponse {
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
private LocalDateTime completedAt;
|
||||
private Map<String, Object> metadata;
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package com.adityachandel.booklore.model.entity;
|
||||
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "task_cron_configuration")
|
||||
public class TaskCronConfigurationEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "task_type", nullable = false, unique = true)
|
||||
private TaskType taskType;
|
||||
|
||||
@Column(name = "cron_expression", nullable = false)
|
||||
private String cronExpression;
|
||||
|
||||
@Column(name = "enabled", nullable = false)
|
||||
private Boolean enabled;
|
||||
|
||||
@Column(name = "created_by", nullable = false)
|
||||
private Long createdBy;
|
||||
|
||||
@Column(name = "created_at", nullable = false, updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(name = "updated_at", nullable = false)
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
createdAt = LocalDateTime.now();
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
protected void onUpdate() {
|
||||
updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-11
@@ -16,7 +16,7 @@ import java.util.Map;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TaskEntity {
|
||||
public class TaskHistoryEntity {
|
||||
|
||||
@Id
|
||||
@Column(length = 36)
|
||||
@@ -54,14 +54,4 @@ public class TaskEntity {
|
||||
@Convert(converter = JpaJsonConverter.class)
|
||||
@Column(name = "task_options", columnDefinition = "TEXT")
|
||||
private Map<String, Object> taskOptions;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return this == o || (o instanceof TaskEntity other && id != null && id.equals(other.id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id != null ? id.hashCode() : System.identityHashCode(this);
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,70 @@ import lombok.Getter;
|
||||
|
||||
public enum TaskType {
|
||||
|
||||
CLEAR_CBX_CACHE(false, false),
|
||||
CLEAR_PDF_CACHE(false, false),
|
||||
RE_SCAN_LIBRARY(false, true),
|
||||
REFRESH_METADATA(false, true);
|
||||
CLEAR_CBX_CACHE(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
"Clear CBX Cache",
|
||||
"Clears temporarily extracted comic book files used by the reader."
|
||||
),
|
||||
CLEAR_PDF_CACHE(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
"Clear PDF Cache",
|
||||
"Clears temporarily generated images used by the streaming PDF reader."
|
||||
),
|
||||
REFRESH_LIBRARY_METADATA(
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
"Refresh Metadata",
|
||||
"Re-reads book information (title, author, cover, etc.) from your files and updates the Booklore database."
|
||||
),
|
||||
UPDATE_BOOK_RECOMMENDATIONS(
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
"Update Book Recommendations",
|
||||
"Analyzes your library to generate personalized book recommendations based on the books you own."
|
||||
),
|
||||
CLEANUP_DELETED_BOOKS(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
"Cleanup Deleted Books",
|
||||
"Permanently removes database entries for books you previously deleted from your libraries."
|
||||
),
|
||||
SYNC_LIBRARY_FILES(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
"Sync Library Files",
|
||||
"Scans your library folders to detect new books and removes entries for files that no longer exist."
|
||||
),
|
||||
CLEANUP_TEMP_METADATA(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
"Cleanup Temporary Metadata",
|
||||
"Removes temporary metadata files created during the bookdrop and manual metadata review processes."
|
||||
),
|
||||
REFRESH_METADATA_MANUAL(
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
"Refresh Metadata",
|
||||
"Updates metadata information for your selected books."
|
||||
);
|
||||
|
||||
@Getter
|
||||
private final boolean parallel;
|
||||
@@ -15,8 +75,24 @@ public enum TaskType {
|
||||
@Getter
|
||||
private final boolean async;
|
||||
|
||||
TaskType(boolean parallel, boolean async) {
|
||||
@Getter
|
||||
private final boolean cronSupported;
|
||||
|
||||
@Getter
|
||||
private final boolean hiddenFromUI;
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
@Getter
|
||||
private final String description;
|
||||
|
||||
TaskType(boolean parallel, boolean async, boolean cronSupported, boolean hiddenFromUI, String name, String description) {
|
||||
this.parallel = parallel;
|
||||
this.async = async;
|
||||
this.cronSupported = cronSupported;
|
||||
this.hiddenFromUI = hiddenFromUI;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
+5
-11
@@ -63,19 +63,10 @@ public interface BookRepository extends JpaRepository<BookEntity, Long>, JpaSpec
|
||||
@Query("SELECT b FROM BookEntity b WHERE b.library.id IN :libraryIds AND (b.deleted IS NULL OR b.deleted = false)")
|
||||
List<BookEntity> findAllWithMetadataByLibraryIds(@Param("libraryIds") Collection<Long> libraryIds);
|
||||
|
||||
@EntityGraph(attributePaths = {"metadata", "shelves", "libraryPath"})
|
||||
@Query(value = "SELECT b FROM BookEntity b WHERE b.library.id IN :libraryIds AND (b.deleted IS NULL OR b.deleted = false)")
|
||||
Page<BookEntity> findAllWithMetadataByLibraryIds(@Param("libraryIds") Collection<Long> libraryIds, Pageable pageable);
|
||||
|
||||
@EntityGraph(attributePaths = {"metadata", "shelves", "libraryPath"})
|
||||
@Query("SELECT DISTINCT b FROM BookEntity b JOIN b.shelves s WHERE s.id = :shelfId AND (b.deleted IS NULL OR b.deleted = false)")
|
||||
List<BookEntity> findAllWithMetadataByShelfId(@Param("shelfId") Long shelfId);
|
||||
|
||||
@EntityGraph(attributePaths = {"metadata", "shelves", "libraryPath"})
|
||||
@Query(value = "SELECT DISTINCT b FROM BookEntity b JOIN b.shelves s WHERE s.id = :shelfId AND (b.deleted IS NULL OR b.deleted = false)",
|
||||
countQuery = "SELECT COUNT(DISTINCT b.id) FROM BookEntity b JOIN b.shelves s WHERE s.id = :shelfId AND (b.deleted IS NULL OR b.deleted = false)")
|
||||
Page<BookEntity> findAllWithMetadataByShelfId(@Param("shelfId") Long shelfId, Pageable pageable);
|
||||
|
||||
@EntityGraph(attributePaths = {"metadata", "shelves", "libraryPath"})
|
||||
@Query("SELECT b FROM BookEntity b WHERE b.fileSizeKb IS NULL AND (b.deleted IS NULL OR b.deleted = false)")
|
||||
List<BookEntity> findAllWithMetadataByFileSizeKbIsNull();
|
||||
@@ -116,8 +107,11 @@ public interface BookRepository extends JpaRepository<BookEntity, Long>, JpaSpec
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("DELETE FROM BookEntity b WHERE b.deletedAt IS NOT NULL AND b.deletedAt < :cutoff")
|
||||
int deleteAllByDeletedAtBefore(Instant cutoff);
|
||||
@Query("DELETE FROM BookEntity b WHERE b.deleted IS TRUE")
|
||||
int deleteAllSoftDeleted();
|
||||
|
||||
@Query("SELECT COUNT(b) FROM BookEntity b WHERE b.deleted = TRUE")
|
||||
long countAllSoftDeleted();
|
||||
|
||||
@Modifying
|
||||
@Query("""
|
||||
|
||||
+3
@@ -13,6 +13,9 @@ public interface MetadataFetchJobRepository extends JpaRepository<MetadataFetchJ
|
||||
|
||||
int deleteAllByCompletedAtBefore(Instant cutoff);
|
||||
|
||||
@Query("SELECT COUNT(m) FROM MetadataFetchJobEntity m")
|
||||
long countAll();
|
||||
|
||||
@Query("SELECT DISTINCT t FROM MetadataFetchJobEntity t LEFT JOIN FETCH t.proposals")
|
||||
List<MetadataFetchJobEntity> findAllWithProposals();
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.adityachandel.booklore.repository;
|
||||
|
||||
import com.adityachandel.booklore.model.entity.TaskCronConfigurationEntity;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface TaskCronConfigurationRepository extends JpaRepository<TaskCronConfigurationEntity, Long> {
|
||||
|
||||
Optional<TaskCronConfigurationEntity> findByTaskType(TaskType taskType);
|
||||
|
||||
List<TaskCronConfigurationEntity> findByEnabledTrue();
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.adityachandel.booklore.repository;
|
||||
|
||||
import com.adityachandel.booklore.model.entity.TaskHistoryEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface TaskHistoryRepository extends JpaRepository<TaskHistoryEntity, String> {
|
||||
|
||||
@Query("SELECT t FROM TaskHistoryEntity t WHERE t.createdAt = " +
|
||||
"(SELECT MAX(t2.createdAt) FROM TaskHistoryEntity t2 WHERE t2.type = t.type) " +
|
||||
"ORDER BY t.createdAt DESC")
|
||||
List<TaskHistoryEntity> findLatestTaskForEachType();
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.adityachandel.booklore.repository;
|
||||
|
||||
import com.adityachandel.booklore.model.entity.TaskEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface TaskRepository extends JpaRepository<TaskEntity, String> {
|
||||
|
||||
@Query("SELECT t FROM TaskEntity t WHERE t.createdAt = " +
|
||||
"(SELECT MAX(t2.createdAt) FROM TaskEntity t2 WHERE t2.type = t.type) " +
|
||||
"ORDER BY t.createdAt DESC")
|
||||
List<TaskEntity> findLatestTaskForEachType();
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class TaskMetadataService {
|
||||
|
||||
private final FileService fileService;
|
||||
|
||||
public Map<String, Object> getMetadataForTaskType(TaskType taskType) {
|
||||
Map<String, Object> metadata = new HashMap<>();
|
||||
|
||||
switch (taskType) {
|
||||
case CLEAR_CBX_CACHE:
|
||||
metadata.putAll(getCacheMetadata(fileService.getCbxCachePath(), "CBX"));
|
||||
break;
|
||||
case CLEAR_PDF_CACHE:
|
||||
metadata.putAll(getCacheMetadata(fileService.getPdfCachePath(), "PDF"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private Map<String, Object> getCacheMetadata(String cachePathStr, String cacheType) {
|
||||
Map<String, Object> metadata = new HashMap<>();
|
||||
|
||||
try {
|
||||
Path cachePath = Paths.get(cachePathStr);
|
||||
|
||||
if (Files.exists(cachePath) && Files.isDirectory(cachePath)) {
|
||||
long sizeInBytes = calculateDirectorySize(cachePath);
|
||||
String formattedSize = formatBytes(sizeInBytes);
|
||||
|
||||
metadata.put("currentCacheSize", formattedSize);
|
||||
metadata.put("currentCacheSizeBytes", sizeInBytes);
|
||||
} else {
|
||||
metadata.put("currentCacheSize", "0 B");
|
||||
metadata.put("currentCacheSizeBytes", 0L);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error calculating {} cache size", cacheType, e);
|
||||
metadata.put("currentCacheSize", "Unknown");
|
||||
metadata.put("currentCacheSizeBytes", -1L);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private long calculateDirectorySize(Path path) throws IOException {
|
||||
try (Stream<Path> walk = Files.walk(path)) {
|
||||
return walk
|
||||
.filter(Files::isRegularFile)
|
||||
.mapToLong(p -> {
|
||||
try {
|
||||
return Files.size(p);
|
||||
} catch (IOException e) {
|
||||
log.warn("Could not get size of file: {}", p, e);
|
||||
return 0L;
|
||||
}
|
||||
})
|
||||
.sum();
|
||||
}
|
||||
}
|
||||
|
||||
private String formatBytes(long bytes) {
|
||||
if (bytes < 1024) return bytes + " B";
|
||||
int exp = (int) (Math.log(bytes) / Math.log(1024));
|
||||
String pre = "KMGTPE".charAt(exp - 1) + "";
|
||||
return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre);
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.book;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.settings.LibraryFile;
|
||||
import com.adityachandel.booklore.model.entity.*;
|
||||
@@ -9,8 +9,6 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.book;
|
||||
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.model.dto.settings.KoboSettings;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.book;
|
||||
|
||||
import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
+1
-29
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.book;
|
||||
|
||||
import com.adityachandel.booklore.mapper.v2.BookMapperV2;
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
@@ -24,12 +24,6 @@ public class BookQueryService {
|
||||
return mapBooksToDto(books, includeDescription, null);
|
||||
}
|
||||
|
||||
public Page<Book> getAllBooksPage(boolean includeDescription, int page, int size) {
|
||||
Pageable pageable = PageRequest.of(Math.max(page - 1, 0), size);
|
||||
Page<BookEntity> books = bookRepository.findAllWithMetadata(pageable);
|
||||
return createPageFromBooks(books, pageable, includeDescription, null);
|
||||
}
|
||||
|
||||
public List<Book> getAllBooksByLibraryIds(Set<Long> libraryIds, boolean includeDescription, Long userId) {
|
||||
List<BookEntity> books = bookRepository.findAllWithMetadataByLibraryIds(libraryIds);
|
||||
return mapBooksToDto(books, includeDescription, userId);
|
||||
@@ -48,27 +42,10 @@ public class BookQueryService {
|
||||
return bookRepository.findAllFullBooks();
|
||||
}
|
||||
|
||||
public Page<Book> searchBooksByMetadataPage(String text, int page, int size) {
|
||||
Pageable pageable = PageRequest.of(Math.max(page - 1, 0), size);
|
||||
Page<BookEntity> books = bookRepository.searchByMetadata(text, pageable);
|
||||
List<Book> mapped = books.getContent().stream()
|
||||
.map(bookMapperV2::toDTO)
|
||||
.collect(Collectors.toList());
|
||||
return new PageImpl<>(mapped, pageable, books.getTotalElements());
|
||||
}
|
||||
|
||||
public void saveAll(List<BookEntity> books) {
|
||||
bookRepository.saveAll(books);
|
||||
}
|
||||
|
||||
public List<Book> searchBooksByMetadata(String text) {
|
||||
Pageable pageable = PageRequest.of(0, Integer.MAX_VALUE);
|
||||
Page<BookEntity> books = bookRepository.searchByMetadata(text, pageable);
|
||||
return books.getContent().stream()
|
||||
.map(bookMapperV2::toDTO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<Book> mapBooksToDto(List<BookEntity> books, boolean includeDescription, Long userId) {
|
||||
return books.stream()
|
||||
.map(book -> mapBookToDto(book, includeDescription, userId))
|
||||
@@ -90,9 +67,4 @@ public class BookQueryService {
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private Page<Book> createPageFromBooks(Page<BookEntity> books, Pageable pageable, boolean includeDescription, Long userId) {
|
||||
List<Book> mapped = mapBooksToDto(books.getContent(), includeDescription, userId);
|
||||
return new PageImpl<>(mapped, pageable, books.getTotalElements());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.book;
|
||||
|
||||
import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.book;
|
||||
|
||||
import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
@@ -15,6 +15,7 @@ import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.model.enums.ReadStatus;
|
||||
import com.adityachandel.booklore.model.enums.ResetProgressType;
|
||||
import com.adityachandel.booklore.repository.*;
|
||||
import com.adityachandel.booklore.service.user.UserProgressService;
|
||||
import com.adityachandel.booklore.service.monitoring.MonitoringRegistrationService;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
import com.adityachandel.booklore.util.FileUtils;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.file;
|
||||
|
||||
import com.adityachandel.booklore.mapper.AdditionalFileMapper;
|
||||
import com.adityachandel.booklore.model.dto.AdditionalFile;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.file;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.UploadResponse;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.file;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
+2
-2
@@ -9,8 +9,8 @@ import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.enums.FileProcessStatus;
|
||||
import com.adityachandel.booklore.repository.BookAdditionalFileRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.service.BookCreatorService;
|
||||
import com.adityachandel.booklore.service.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.book.BookCreatorService;
|
||||
import com.adityachandel.booklore.service.file.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.metadata.MetadataMatchService;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.repository.BookAdditionalFileRepository;
|
||||
import com.adityachandel.booklore.repository.BookMetadataRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.service.BookCreatorService;
|
||||
import com.adityachandel.booklore.service.book.BookCreatorService;
|
||||
import com.adityachandel.booklore.service.metadata.extractor.CbxMetadataExtractor;
|
||||
import com.adityachandel.booklore.service.metadata.MetadataMatchService;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.repository.BookAdditionalFileRepository;
|
||||
import com.adityachandel.booklore.repository.BookMetadataRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.service.BookCreatorService;
|
||||
import com.adityachandel.booklore.service.book.BookCreatorService;
|
||||
import com.adityachandel.booklore.service.metadata.MetadataMatchService;
|
||||
import com.adityachandel.booklore.service.metadata.extractor.EpubMetadataExtractor;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.repository.BookAdditionalFileRepository;
|
||||
import com.adityachandel.booklore.repository.BookMetadataRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.service.BookCreatorService;
|
||||
import com.adityachandel.booklore.service.book.BookCreatorService;
|
||||
import com.adityachandel.booklore.service.metadata.MetadataMatchService;
|
||||
import com.adityachandel.booklore.service.metadata.extractor.PdfMetadataExtractor;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.kobo;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.kobo.*;
|
||||
import com.adityachandel.booklore.model.dto.settings.KoboSettings;
|
||||
@@ -9,6 +9,7 @@ import com.adityachandel.booklore.model.entity.CategoryEntity;
|
||||
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.model.enums.KoboBookFormat;
|
||||
import com.adityachandel.booklore.model.enums.KoboReadStatus;
|
||||
import com.adityachandel.booklore.service.book.BookQueryService;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import com.adityachandel.booklore.util.kobo.KoboUrlBuilder;
|
||||
import lombok.AllArgsConstructor;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.kobo;
|
||||
|
||||
import com.adityachandel.booklore.mapper.BookEntityToKoboSnapshotBookMapper;
|
||||
import com.adityachandel.booklore.model.entity.KoboDeletedBookProgressEntity;
|
||||
-2
@@ -7,8 +7,6 @@ import com.adityachandel.booklore.model.dto.kobo.*;
|
||||
import com.adityachandel.booklore.model.entity.KoboSnapshotBookEntity;
|
||||
import com.adityachandel.booklore.model.entity.KoboLibrarySnapshotEntity;
|
||||
import com.adityachandel.booklore.repository.KoboDeletedBookProgressRepository;
|
||||
import com.adityachandel.booklore.service.KoboEntitlementService;
|
||||
import com.adityachandel.booklore.service.KoboLibrarySnapshotService;
|
||||
import com.adityachandel.booklore.util.RequestUtils;
|
||||
import com.adityachandel.booklore.util.kobo.BookloreSyncTokenGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.kobo;
|
||||
|
||||
import com.adityachandel.booklore.mapper.KoboReadingStateMapper;
|
||||
import com.adityachandel.booklore.model.dto.kobo.KoboReadingState;
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.kobo;
|
||||
|
||||
import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
@@ -9,6 +9,7 @@ import com.adityachandel.booklore.model.entity.KoboUserSettingsEntity;
|
||||
import com.adityachandel.booklore.model.entity.ShelfEntity;
|
||||
import com.adityachandel.booklore.model.enums.ShelfType;
|
||||
import com.adityachandel.booklore.repository.KoboUserSettingsRepository;
|
||||
import com.adityachandel.booklore.service.ShelfService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.adityachandel.booklore.service.kobo;
|
||||
|
||||
import com.adityachandel.booklore.service.BookService;
|
||||
import com.adityachandel.booklore.service.book.BookService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.koreader;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.koreader;
|
||||
|
||||
import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
+1
-1
@@ -12,7 +12,7 @@ import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.model.enums.LibraryScanMode;
|
||||
import com.adityachandel.booklore.repository.BookAdditionalFileRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.service.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.file.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.event.AdminEventBroadcaster;
|
||||
import com.adityachandel.booklore.service.event.BookEventBroadcaster;
|
||||
import com.adityachandel.booklore.service.fileprocessor.BookFileProcessor;
|
||||
|
||||
+1
-3
@@ -10,7 +10,7 @@ import com.adityachandel.booklore.model.websocket.Topic;
|
||||
import com.adityachandel.booklore.repository.BookAdditionalFileRepository;
|
||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import com.adityachandel.booklore.service.NotificationService;
|
||||
import com.adityachandel.booklore.task.RescanLibraryContext;
|
||||
import com.adityachandel.booklore.task.options.RescanLibraryContext;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -23,8 +23,6 @@ import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.adityachandel.booklore.model.websocket.LogNotification.createLogNotification;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
@Slf4j
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import com.adityachandel.booklore.service.NotificationService;
|
||||
import com.adityachandel.booklore.service.metadata.BookMetadataUpdater;
|
||||
import com.adityachandel.booklore.service.metadata.extractor.MetadataExtractorFactory;
|
||||
import com.adityachandel.booklore.task.RescanLibraryContext;
|
||||
import com.adityachandel.booklore.task.options.RescanLibraryContext;
|
||||
import com.adityachandel.booklore.task.TaskCancellationManager;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
@@ -110,7 +110,7 @@ public class LibraryRescanHelper {
|
||||
try {
|
||||
TaskProgressPayload payload = TaskProgressPayload.builder()
|
||||
.taskId(taskId)
|
||||
.taskType(TaskType.RE_SCAN_LIBRARY)
|
||||
.taskType(TaskType.REFRESH_LIBRARY_METADATA)
|
||||
.message(message)
|
||||
.progress(progress)
|
||||
.taskStatus(taskStatus)
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import com.adityachandel.booklore.repository.UserRepository;
|
||||
import com.adityachandel.booklore.service.NotificationService;
|
||||
import com.adityachandel.booklore.service.monitoring.MonitoringService;
|
||||
import com.adityachandel.booklore.task.RescanLibraryContext;
|
||||
import com.adityachandel.booklore.task.options.RescanLibraryContext;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
import com.adityachandel.booklore.util.SecurityContextVirtualThread;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
+1
-3
@@ -22,7 +22,7 @@ import com.adityachandel.booklore.model.websocket.LogNotification;
|
||||
import com.adityachandel.booklore.model.websocket.Topic;
|
||||
import com.adityachandel.booklore.repository.BookMetadataRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.service.BookQueryService;
|
||||
import com.adityachandel.booklore.service.book.BookQueryService;
|
||||
import com.adityachandel.booklore.service.NotificationService;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import com.adityachandel.booklore.service.fileprocessor.BookFileProcessor;
|
||||
@@ -51,8 +51,6 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.adityachandel.booklore.model.websocket.LogNotification.createLogNotification;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.CategoryRepository;
|
||||
import com.adityachandel.booklore.repository.MoodRepository;
|
||||
import com.adityachandel.booklore.repository.TagRepository;
|
||||
import com.adityachandel.booklore.service.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.file.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import com.adityachandel.booklore.service.file.FileMoveService;
|
||||
import com.adityachandel.booklore.service.metadata.writer.MetadataWriterFactory;
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import com.adityachandel.booklore.model.dto.settings.AppSettings;
|
||||
import com.adityachandel.booklore.model.dto.settings.MetadataMatchWeights;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.service.BookQueryService;
|
||||
import com.adityachandel.booklore.service.book.BookQueryService;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.metadata;
|
||||
|
||||
import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.mapper.FetchedProposalMapper;
|
||||
+2
-2
@@ -5,8 +5,8 @@ import com.adityachandel.booklore.model.entity.AppMigrationEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.repository.AppMigrationRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.service.BookQueryService;
|
||||
import com.adityachandel.booklore.service.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.book.BookQueryService;
|
||||
import com.adityachandel.booklore.service.file.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.metadata.MetadataMatchService;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
import com.adityachandel.booklore.util.FileUtils;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.opds;
|
||||
|
||||
import com.adityachandel.booklore.config.security.userdetails.OpdsUserDetails;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
-1
@@ -4,7 +4,6 @@ import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.config.security.userdetails.OpdsUserDetails;
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.dto.Library;
|
||||
import com.adityachandel.booklore.service.OpdsBookService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.opds;
|
||||
|
||||
import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.mapper.OpdsUserV2Mapper;
|
||||
+1
-81
@@ -1,20 +1,13 @@
|
||||
package com.adityachandel.booklore.service.recommender;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.BookRecommendationLite;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.service.book.BookQueryService;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import com.adityachandel.booklore.service.BookQueryService;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@@ -29,79 +22,6 @@ public class BookRecommendationScheduler {
|
||||
@Scheduled(cron = "0 0 2 * * *")
|
||||
@Transactional
|
||||
public void updateAllSimilarBooks() {
|
||||
if (!appSettingService.getAppSettings().isSimilarBookRecommendation()) {
|
||||
log.info("Similar book recommendations are disabled. Skipping scheduled task.");
|
||||
return;
|
||||
}
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("Scheduled task 'updateAllSimilarBooks' started at: {}. Current timestamp: {}", startTime, startTime);
|
||||
|
||||
List<BookEntity> allBooks = bookQueryService.getAllFullBookEntities();
|
||||
|
||||
Map<Long, double[]> embeddings = new HashMap<>();
|
||||
List<BookEntity> booksToUpdate = new ArrayList<>();
|
||||
|
||||
for (BookEntity book : allBooks) {
|
||||
double[] embedding = vectorService.generateEmbedding(book);
|
||||
embeddings.put(book.getId(), embedding);
|
||||
|
||||
if (book.getMetadata() != null) {
|
||||
String embeddingJson = vectorService.serializeVector(embedding);
|
||||
if (!Objects.equals(book.getMetadata().getEmbeddingVector(), embeddingJson)) {
|
||||
book.getMetadata().setEmbeddingVector(embeddingJson);
|
||||
book.getMetadata().setEmbeddingUpdatedAt(Instant.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (BookEntity targetBook : allBooks) {
|
||||
try {
|
||||
double[] targetVector = embeddings.get(targetBook.getId());
|
||||
if (targetVector == null) continue;
|
||||
|
||||
String targetSeries = Optional.ofNullable(targetBook.getMetadata())
|
||||
.map(BookMetadataEntity::getSeriesName)
|
||||
.map(String::toLowerCase)
|
||||
.orElse(null);
|
||||
|
||||
List<BookVectorService.ScoredBook> candidates = allBooks.stream()
|
||||
.filter(candidate -> !candidate.getId().equals(targetBook.getId()))
|
||||
.filter(candidate -> {
|
||||
String candidateSeries = Optional.ofNullable(candidate.getMetadata())
|
||||
.map(BookMetadataEntity::getSeriesName)
|
||||
.map(String::toLowerCase)
|
||||
.orElse(null);
|
||||
return targetSeries == null || !targetSeries.equals(candidateSeries);
|
||||
})
|
||||
.map(candidate -> {
|
||||
double[] candidateVector = embeddings.get(candidate.getId());
|
||||
double similarity = vectorService.cosineSimilarity(targetVector, candidateVector);
|
||||
return new BookVectorService.ScoredBook(candidate.getId(), similarity);
|
||||
})
|
||||
.filter(scored -> scored.getScore() > 0.1)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<BookVectorService.ScoredBook> topSimilar = vectorService.findTopKSimilar(
|
||||
targetVector,
|
||||
candidates,
|
||||
RECOMMENDATION_LIMIT
|
||||
);
|
||||
|
||||
Set<BookRecommendationLite> recommendations = topSimilar.stream()
|
||||
.map(scored -> new BookRecommendationLite(scored.getBookId(), scored.getScore()))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
targetBook.setSimilarBooksJson(recommendations);
|
||||
booksToUpdate.add(targetBook);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error updating similar books for book ID {}: {}", targetBook.getId(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
bookQueryService.saveAll(booksToUpdate);
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("Completed scheduled task 'updateAllSimilarBooks' at: {}. Duration: {} ms", endTime, endTime - startTime);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ import com.adityachandel.booklore.model.entity.AuthorEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.service.BookQueryService;
|
||||
import com.adityachandel.booklore.service.book.BookQueryService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
package com.adityachandel.booklore.service.scheduler;
|
||||
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeletedBooksCleanupService {
|
||||
|
||||
private final BookRepository bookRepository;
|
||||
|
||||
@Scheduled(cron = "0 0 0 * * MON") // At 00:00 every Monday
|
||||
public void cleanupDeletedBooks() {
|
||||
Instant cutoff = Instant.now().minus(7, ChronoUnit.DAYS);
|
||||
int deletedCount = bookRepository.deleteAllByDeletedAtBefore(cutoff);
|
||||
log.info("DeletedBooksCleanupService: Removed {} deleted books older than {}", deletedCount, cutoff);
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
package com.adityachandel.booklore.service.scheduler;
|
||||
|
||||
import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.model.dto.Library;
|
||||
import com.adityachandel.booklore.service.library.LibraryService;
|
||||
import com.adityachandel.booklore.task.RescanLibraryContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class LibraryRescanScheduler {
|
||||
|
||||
private final LibraryService libraryService;
|
||||
|
||||
@Scheduled(cron = "0 0 0 * * *") // At 00:00 every day
|
||||
public void rescanLibraries() {
|
||||
log.info("Starting scheduled library rescan at midnight");
|
||||
|
||||
for (Library library : libraryService.getAllLibraries()) {
|
||||
try {
|
||||
libraryService.rescanLibrary(library.getId());
|
||||
log.info("Rescanned library '{}'", library.getName());
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to rescan library '{}': {}", library.getName(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
log.info("Completed scheduled library rescan");
|
||||
}
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
package com.adityachandel.booklore.service.scheduler;
|
||||
|
||||
import com.adityachandel.booklore.repository.MetadataFetchJobRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MetadataFetchCleanupService {
|
||||
|
||||
private final MetadataFetchJobRepository metadataFetchJobRepository;
|
||||
|
||||
@Scheduled(cron = "0 30 0 * * *") // Runs every day at 00:30 AM
|
||||
public void cleanupOldMetadataFetchJobs() {
|
||||
Instant cutoff = Instant.now().minus(5, ChronoUnit.DAYS);
|
||||
int deleted = metadataFetchJobRepository.deleteAllByCompletedAtBefore(cutoff);
|
||||
log.info("MetadataFetchCleanupService: Removed {} metadata fetch jobs older than {}", deleted, cutoff);
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
package com.adityachandel.booklore.service.task;
|
||||
|
||||
import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.exception.APIException;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCronConfigRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.CronConfig;
|
||||
import com.adityachandel.booklore.model.entity.TaskCronConfigurationEntity;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.repository.TaskCronConfigurationRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class TaskCronService {
|
||||
|
||||
private final TaskCronConfigurationRepository repository;
|
||||
private final AuthenticationService authService;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<TaskCronConfigurationEntity> getAllEnabledCronConfigs() {
|
||||
return repository.findByEnabledTrue();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public CronConfig getCronConfigOrDefault(TaskType taskType) {
|
||||
validateTaskTypeForCron(taskType);
|
||||
return repository.findByTaskType(taskType)
|
||||
.map(this::mapToResponse)
|
||||
.orElse(CronConfig.builder()
|
||||
.taskType(taskType)
|
||||
.enabled(false)
|
||||
.build());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public CronConfig patchCronConfig(TaskType taskType, TaskCronConfigRequest request) {
|
||||
validateTaskTypeForCron(taskType);
|
||||
BookLoreUser user = authService.getAuthenticatedUser();
|
||||
TaskCronConfigurationEntity config = repository.findByTaskType(taskType)
|
||||
.orElse(TaskCronConfigurationEntity.builder()
|
||||
.taskType(taskType)
|
||||
.createdBy(user.getId())
|
||||
.enabled(false)
|
||||
.build());
|
||||
if (request.getCronExpression() != null) {
|
||||
validateCronExpression(request.getCronExpression());
|
||||
config.setCronExpression(request.getCronExpression());
|
||||
}
|
||||
if (request.getEnabled() != null) {
|
||||
config.setEnabled(request.getEnabled());
|
||||
}
|
||||
config = repository.save(config);
|
||||
log.info("Updated cron configuration for task type: {}", taskType);
|
||||
return mapToResponse(config);
|
||||
}
|
||||
|
||||
private void validateTaskTypeForCron(TaskType taskType) {
|
||||
if (taskType == null) {
|
||||
throw new APIException("Task type is required", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (!taskType.isCronSupported()) {
|
||||
throw new APIException("Task type " + taskType + " does not support cron scheduling", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateCronExpression(String cronExpression) {
|
||||
if (cronExpression == null || cronExpression.trim().isEmpty()) {
|
||||
throw new APIException("Cron expression is required", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
String[] fields = cronExpression.trim().split("\\s+");
|
||||
if (fields.length != 6) {
|
||||
throw new APIException("Invalid cron expression format. Expected 6 fields (second minute hour day month day-of-week)", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
new CronTrigger(cronExpression);
|
||||
} catch (Exception e) {
|
||||
throw new APIException("Invalid cron expression: " + cronExpression + ". Error: " + e.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
private CronConfig mapToResponse(TaskCronConfigurationEntity config) {
|
||||
return CronConfig.builder()
|
||||
.id(config.getId())
|
||||
.taskType(config.getTaskType())
|
||||
.cronExpression(config.getCronExpression())
|
||||
.enabled(config.getEnabled())
|
||||
.createdAt(config.getCreatedAt())
|
||||
.updatedAt(config.getUpdatedAt())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+42
-34
@@ -1,9 +1,9 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.task;
|
||||
|
||||
import com.adityachandel.booklore.repository.TaskRepository;
|
||||
import com.adityachandel.booklore.model.entity.TaskEntity;
|
||||
import com.adityachandel.booklore.repository.TaskHistoryRepository;
|
||||
import com.adityachandel.booklore.model.entity.TaskHistoryEntity;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskStatusResponse;
|
||||
import com.adityachandel.booklore.model.dto.response.TasksHistoryResponse;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -19,12 +19,11 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
public class TaskHistoryService {
|
||||
|
||||
private final TaskRepository taskRepository;
|
||||
private final TaskMetadataService taskMetadataService;
|
||||
private final TaskHistoryRepository taskHistoryRepository;
|
||||
|
||||
@Transactional
|
||||
public TaskEntity createTask(String taskId, TaskType type, Long userId, Map<String, Object> options) {
|
||||
TaskEntity task = TaskEntity.builder()
|
||||
public void createTask(String taskId, TaskType type, Long userId, Map<String, Object> options) {
|
||||
TaskHistoryEntity task = TaskHistoryEntity.builder()
|
||||
.id(taskId)
|
||||
.type(type)
|
||||
.status(TaskStatus.ACCEPTED)
|
||||
@@ -33,14 +32,12 @@ public class TaskHistoryService {
|
||||
.progressPercentage(0)
|
||||
.taskOptions(options)
|
||||
.build();
|
||||
|
||||
log.info("Creating task history: id={}, type={}, userId={}", taskId, type, userId);
|
||||
return taskRepository.save(task);
|
||||
taskHistoryRepository.save(task);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateTaskStatus(String taskId, TaskStatus status, String message) {
|
||||
taskRepository.findById(taskId).ifPresent(task -> {
|
||||
taskHistoryRepository.findById(taskId).ifPresent(task -> {
|
||||
task.setStatus(status);
|
||||
task.setMessage(message);
|
||||
task.setUpdatedAt(LocalDateTime.now());
|
||||
@@ -50,34 +47,51 @@ public class TaskHistoryService {
|
||||
task.setProgressPercentage(100);
|
||||
}
|
||||
|
||||
taskRepository.save(task);
|
||||
log.info("Updated task status: id={}, status={}", taskId, status);
|
||||
taskHistoryRepository.save(task);
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateTaskError(String taskId, String errorDetails) {
|
||||
taskRepository.findById(taskId).ifPresent(task -> {
|
||||
taskHistoryRepository.findById(taskId).ifPresent(task -> {
|
||||
task.setStatus(TaskStatus.FAILED);
|
||||
task.setErrorDetails(errorDetails);
|
||||
task.setCompletedAt(LocalDateTime.now());
|
||||
task.setUpdatedAt(LocalDateTime.now());
|
||||
taskRepository.save(task);
|
||||
taskHistoryRepository.save(task);
|
||||
log.error("Task failed: id={}", taskId);
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public TaskStatusResponse getLatestTasksForEachType() {
|
||||
List<TaskEntity> latestTasks = taskRepository.findLatestTaskForEachType();
|
||||
public TasksHistoryResponse getLatestTasksForEachType() {
|
||||
List<TaskHistoryEntity> latestTasks;
|
||||
try {
|
||||
latestTasks = taskHistoryRepository.findLatestTaskForEachType();
|
||||
} catch (Exception e) {
|
||||
log.warn("Error fetching latest tasks, possibly due to removed enum values: {}", e.getMessage());
|
||||
latestTasks = Collections.emptyList();
|
||||
}
|
||||
|
||||
Map<TaskType, TaskEntity> taskHistoryMap = latestTasks.stream()
|
||||
.collect(Collectors.toMap(TaskEntity::getType, task -> task));
|
||||
Map<TaskType, TaskHistoryEntity> taskHistoryMap = latestTasks.stream()
|
||||
.filter(task -> {
|
||||
try {
|
||||
return task.getType() != null;
|
||||
} catch (Exception e) {
|
||||
log.warn("Skipping task with invalid type: taskId={}", task.getId());
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toMap(TaskHistoryEntity::getType, task -> task, (existing, replacement) -> existing));
|
||||
|
||||
List<TaskStatusResponse.TaskInfo> allTasks = new ArrayList<>();
|
||||
List<TasksHistoryResponse.TaskHistory> allTasks = new ArrayList<>();
|
||||
|
||||
for (TaskType taskType : TaskType.values()) {
|
||||
TaskEntity existingTask = taskHistoryMap.get(taskType);
|
||||
if (taskType.isHiddenFromUI()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TaskHistoryEntity existingTask = taskHistoryMap.get(taskType);
|
||||
|
||||
if (existingTask != null) {
|
||||
allTasks.add(mapToTaskInfo(existingTask));
|
||||
@@ -86,15 +100,13 @@ public class TaskHistoryService {
|
||||
}
|
||||
}
|
||||
|
||||
return TaskStatusResponse.builder()
|
||||
.tasks(allTasks)
|
||||
return TasksHistoryResponse.builder()
|
||||
.taskHistories(allTasks)
|
||||
.build();
|
||||
}
|
||||
|
||||
private TaskStatusResponse.TaskInfo mapToTaskInfo(TaskEntity task) {
|
||||
Map<String, Object> metadata = taskMetadataService.getMetadataForTaskType(task.getType());
|
||||
|
||||
return TaskStatusResponse.TaskInfo.builder()
|
||||
private TasksHistoryResponse.TaskHistory mapToTaskInfo(TaskHistoryEntity task) {
|
||||
return TasksHistoryResponse.TaskHistory.builder()
|
||||
.id(task.getId())
|
||||
.type(task.getType())
|
||||
.status(task.getStatus())
|
||||
@@ -103,14 +115,11 @@ public class TaskHistoryService {
|
||||
.createdAt(task.getCreatedAt())
|
||||
.updatedAt(task.getUpdatedAt())
|
||||
.completedAt(task.getCompletedAt())
|
||||
.metadata(metadata)
|
||||
.build();
|
||||
}
|
||||
|
||||
private TaskStatusResponse.TaskInfo createMetadataOnlyTaskInfo(TaskType taskType) {
|
||||
Map<String, Object> metadata = taskMetadataService.getMetadataForTaskType(taskType);
|
||||
|
||||
return TaskStatusResponse.TaskInfo.builder()
|
||||
private TasksHistoryResponse.TaskHistory createMetadataOnlyTaskInfo(TaskType taskType) {
|
||||
return TasksHistoryResponse.TaskHistory.builder()
|
||||
.id(null)
|
||||
.type(taskType)
|
||||
.status(null)
|
||||
@@ -119,7 +128,6 @@ public class TaskHistoryService {
|
||||
.createdAt(null)
|
||||
.updatedAt(null)
|
||||
.completedAt(null)
|
||||
.metadata(metadata)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+125
-9
@@ -1,28 +1,37 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.task;
|
||||
|
||||
import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.exception.APIException;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.TaskInfo;
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCancelResponse;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
||||
import com.adityachandel.booklore.model.entity.TaskCronConfigurationEntity;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.task.*;
|
||||
import com.adityachandel.booklore.task.tasks.Task;
|
||||
import com.adityachandel.booklore.task.TaskCancellationManager;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import com.adityachandel.booklore.util.SecurityContextVirtualThread;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -32,22 +41,120 @@ public class TaskService {
|
||||
|
||||
private final AuthenticationService authenticationService;
|
||||
private final TaskHistoryService taskHistoryService;
|
||||
private final TaskCronService taskCronService;
|
||||
private final Map<TaskType, Task> taskRegistry;
|
||||
private final ConcurrentMap<TaskType, String> runningTasks = new ConcurrentHashMap<>();
|
||||
private final TaskCancellationManager cancellationManager;
|
||||
private final Executor taskExecutor;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final TaskScheduler taskScheduler;
|
||||
private final Map<TaskType, ScheduledFuture<?>> scheduledTasks = new ConcurrentHashMap<>();
|
||||
|
||||
public TaskService(AuthenticationService authenticationService, TaskHistoryService taskHistoryService, List<Task> tasks, TaskCancellationManager cancellationManager, Executor taskExecutor, ObjectMapper objectMapper) {
|
||||
public TaskService(
|
||||
AuthenticationService authenticationService,
|
||||
TaskHistoryService taskHistoryService,
|
||||
@Lazy TaskCronService taskCronService,
|
||||
List<Task> tasks,
|
||||
TaskCancellationManager cancellationManager,
|
||||
Executor taskExecutor,
|
||||
ObjectMapper objectMapper,
|
||||
TaskScheduler taskScheduler) {
|
||||
this.authenticationService = authenticationService;
|
||||
this.taskHistoryService = taskHistoryService;
|
||||
this.taskCronService = taskCronService;
|
||||
this.taskRegistry = tasks.stream().collect(Collectors.toMap(Task::getTaskType, Function.identity()));
|
||||
this.cancellationManager = cancellationManager;
|
||||
this.taskExecutor = taskExecutor;
|
||||
this.objectMapper = objectMapper;
|
||||
this.taskScheduler = taskScheduler;
|
||||
}
|
||||
|
||||
public TaskCreateResponse run(TaskCreateRequest request) {
|
||||
public void initializeScheduledTasks() {
|
||||
List<TaskCronConfigurationEntity> enabledConfigs = taskCronService.getAllEnabledCronConfigs();
|
||||
log.info("Initializing {} scheduled tasks", enabledConfigs.size());
|
||||
enabledConfigs.forEach(this::scheduleTask);
|
||||
}
|
||||
|
||||
public void rescheduleTask(TaskType taskType) {
|
||||
cancelScheduledTask(taskType);
|
||||
taskCronService.getCronConfigOrDefault(taskType);
|
||||
var cronConfig = taskCronService.getCronConfigOrDefault(taskType);
|
||||
|
||||
if (cronConfig.getEnabled() != null && cronConfig.getEnabled() && cronConfig.getCronExpression() != null) {
|
||||
TaskCronConfigurationEntity config = TaskCronConfigurationEntity.builder()
|
||||
.taskType(taskType)
|
||||
.cronExpression(cronConfig.getCronExpression())
|
||||
.enabled(cronConfig.getEnabled())
|
||||
.build();
|
||||
scheduleTask(config);
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleTask(TaskCronConfigurationEntity config) {
|
||||
cancelScheduledTask(config.getTaskType());
|
||||
|
||||
try {
|
||||
CronTrigger trigger = new CronTrigger(config.getCronExpression());
|
||||
ScheduledFuture<?> scheduledTask = taskScheduler.schedule(
|
||||
() -> executeCronTask(config.getTaskType()),
|
||||
trigger
|
||||
);
|
||||
|
||||
scheduledTasks.put(config.getTaskType(), scheduledTask);
|
||||
log.info("Scheduled task {} with cron expression: {}", config.getTaskType(), config.getCronExpression());
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to schedule task {}", config.getTaskType(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelScheduledTask(TaskType taskType) {
|
||||
ScheduledFuture<?> scheduledTask = scheduledTasks.remove(taskType);
|
||||
if (scheduledTask != null && !scheduledTask.isCancelled()) {
|
||||
scheduledTask.cancel(false);
|
||||
log.info("Cancelled scheduled task: {}", taskType);
|
||||
}
|
||||
}
|
||||
|
||||
public List<TaskInfo> getAvailableTasks() {
|
||||
return Arrays.stream(TaskType.values())
|
||||
.filter(taskType -> !taskType.isHiddenFromUI())
|
||||
.map(taskType -> {
|
||||
TaskInfo metadata = TaskInfo.fromTaskType(taskType);
|
||||
Task task = taskRegistry.get(taskType);
|
||||
if (task != null) {
|
||||
metadata.setMetadata(task.getMetadata());
|
||||
}
|
||||
if (taskType.isCronSupported()) {
|
||||
var cronConfig = taskCronService.getCronConfigOrDefault(taskType);
|
||||
metadata.setCronConfig(cronConfig);
|
||||
}
|
||||
return metadata;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void executeCronTask(TaskType taskType) {
|
||||
log.info("Executing cron-scheduled task: {}", taskType);
|
||||
try {
|
||||
BookLoreUser systemUser = authenticationService.getSystemUser();
|
||||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(systemUser, null, List.of());
|
||||
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
|
||||
securityContext.setAuthentication(authentication);
|
||||
SecurityContextHolder.setContext(securityContext);
|
||||
|
||||
TaskCreateRequest request = TaskCreateRequest.builder()
|
||||
.taskType(taskType)
|
||||
.build();
|
||||
|
||||
runAsSystemUser(request);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to execute cron-scheduled task: {}", taskType, e);
|
||||
} finally {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
}
|
||||
|
||||
public TaskCreateResponse runAsUser(TaskCreateRequest request) {
|
||||
if (request == null || request.getTaskType() == null) {
|
||||
throw new APIException("Task request and task type cannot be null", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
@@ -60,6 +167,19 @@ public class TaskService {
|
||||
}
|
||||
}
|
||||
|
||||
private void runAsSystemUser(TaskCreateRequest request) {
|
||||
if (request == null || request.getTaskType() == null) {
|
||||
throw new APIException("Task request and task type cannot be null", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
BookLoreUser systemUser = authenticationService.getSystemUser();
|
||||
TaskType taskType = request.getTaskType();
|
||||
if (taskType.isAsync()) {
|
||||
runAsync(request, systemUser, taskType);
|
||||
} else {
|
||||
runSync(request, systemUser, taskType);
|
||||
}
|
||||
}
|
||||
|
||||
private TaskCreateResponse runAsync(TaskCreateRequest request, BookLoreUser user, TaskType taskType) {
|
||||
String taskId = initializeTask(request, user, taskType);
|
||||
TaskCreateResponse response = TaskCreateResponse.builder()
|
||||
@@ -107,7 +227,6 @@ public class TaskService {
|
||||
taskHistoryService.updateTaskStatus(taskId, TaskStatus.CANCELLED, "Task was cancelled");
|
||||
} else {
|
||||
taskHistoryService.updateTaskStatus(taskId, TaskStatus.COMPLETED, "Task completed successfully");
|
||||
log.info("Async task {} of type {} completed successfully", taskId, taskType);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Async task {} of type {} failed", taskId, taskType, e);
|
||||
@@ -128,7 +247,6 @@ public class TaskService {
|
||||
TaskCreateResponse response = executeTask(request);
|
||||
response.setTaskId(taskId);
|
||||
taskHistoryService.updateTaskStatus(taskId, TaskStatus.COMPLETED, "Task completed successfully");
|
||||
log.info("Sync task {} of type {} completed successfully", taskId, taskType);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.error("Sync task {} of type {} failed", taskId, taskType, e);
|
||||
@@ -137,7 +255,6 @@ public class TaskService {
|
||||
} finally {
|
||||
if (!taskType.isParallel()) {
|
||||
runningTasks.remove(taskType);
|
||||
log.info("Released lock for task type: {}", taskType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,7 +273,6 @@ public class TaskService {
|
||||
}
|
||||
Map<String, Object> options = convertOptionsToMap(request.getOptions());
|
||||
taskHistoryService.createTask(taskId, taskType, user.getId(), options);
|
||||
log.info("Initialized task: id={}, type={}, userId={}", taskId, taskType, user.getId());
|
||||
return taskId;
|
||||
}
|
||||
|
||||
@@ -178,7 +294,7 @@ public class TaskService {
|
||||
|
||||
private TaskCreateResponse executeTask(TaskCreateRequest request) {
|
||||
TaskType taskType = request.getTaskType();
|
||||
log.info("Executing task of type: {}", taskType);
|
||||
log.info("{}: Executing task", taskType);
|
||||
Task task = taskRegistry.get(taskType);
|
||||
if (task == null) {
|
||||
throw new UnsupportedOperationException("Task type not implemented: " + taskType);
|
||||
+1
-1
@@ -15,7 +15,7 @@ import com.adityachandel.booklore.model.enums.BookFileExtension;
|
||||
import com.adityachandel.booklore.repository.BookAdditionalFileRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import com.adityachandel.booklore.service.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.file.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import com.adityachandel.booklore.service.file.FileMovingHelper;
|
||||
import com.adityachandel.booklore.service.metadata.extractor.MetadataExtractorFactory;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
package com.adityachandel.booklore.service.user;
|
||||
|
||||
import com.adityachandel.booklore.model.entity.UserBookProgressEntity;
|
||||
import com.adityachandel.booklore.repository.UserBookProgressRepository;
|
||||
+1
-2
@@ -7,7 +7,7 @@ import com.adityachandel.booklore.model.enums.BookFileExtension;
|
||||
import com.adityachandel.booklore.model.enums.PermissionType;
|
||||
import com.adityachandel.booklore.model.websocket.Topic;
|
||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import com.adityachandel.booklore.service.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.file.FileFingerprint;
|
||||
import com.adityachandel.booklore.service.NotificationService;
|
||||
import com.adityachandel.booklore.util.FileUtils;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
@@ -18,7 +18,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.adityachandel.booklore.task;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Slf4j
|
||||
public class TaskMetadataHelper {
|
||||
|
||||
public static String getCacheSizeString(String cachePath) {
|
||||
try {
|
||||
Path path = Paths.get(cachePath);
|
||||
|
||||
if (Files.exists(path) && Files.isDirectory(path)) {
|
||||
long sizeInBytes = calculateDirectorySize(path);
|
||||
return "Current cache size: " + formatBytes(sizeInBytes);
|
||||
} else {
|
||||
return "Current cache size: 0 B";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error calculating cache size for path: {}", cachePath, e);
|
||||
return "Current cache size: Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
private static long calculateDirectorySize(Path directory) throws IOException {
|
||||
try (Stream<Path> walk = Files.walk(directory)) {
|
||||
return walk
|
||||
.filter(Files::isRegularFile)
|
||||
.mapToLong(path -> {
|
||||
try {
|
||||
return Files.size(path);
|
||||
} catch (IOException e) {
|
||||
log.warn("Could not get size of file: {}", path, e);
|
||||
return 0L;
|
||||
}
|
||||
})
|
||||
.sum();
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatBytes(long bytes) {
|
||||
if (bytes < 1024) return bytes + " B";
|
||||
int exp = (int) (Math.log(bytes) / Math.log(1024));
|
||||
String pre = "KMGTPE".charAt(exp - 1) + "";
|
||||
return String.format("%.2f %sB", bytes / Math.pow(1024, exp), pre);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.adityachandel.booklore.task;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum TaskType {
|
||||
|
||||
CLEAR_CBX_CACHE(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
"Clear CBX Cache",
|
||||
"Clears temporarily extracted comic book files used by the reader."
|
||||
),
|
||||
CLEAR_PDF_CACHE(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
"Clear PDF Cache",
|
||||
"Clears temporarily generated images used by the streaming PDF reader."
|
||||
),
|
||||
REFRESH_LIBRARY_METADATA(
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
"Refresh Metadata",
|
||||
"Re-reads book information (title, author, cover, etc.) from your files and updates the Booklore database."
|
||||
),
|
||||
UPDATE_BOOK_RECOMMENDATIONS(
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
"Update Book Recommendations",
|
||||
"Analyzes your library to generate personalized book recommendations based on the books you own."
|
||||
),
|
||||
CLEANUP_DELETED_BOOKS(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
"Cleanup Deleted Books",
|
||||
"Permanently removes database entries for books you previously deleted from your libraries."
|
||||
),
|
||||
SYNC_LIBRARY_FILES(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
"Sync Library Files",
|
||||
"Scans your library folders to detect new books and removes entries for files that no longer exist."
|
||||
),
|
||||
CLEANUP_TEMP_METADATA(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
"Cleanup Temporary Metadata",
|
||||
"Removes temporary metadata files created during the bookdrop and manual metadata review processes."
|
||||
),
|
||||
REFRESH_METADATA_MANUAL(
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
"Refresh Metadata",
|
||||
"Updates metadata information for your selected books."
|
||||
);
|
||||
|
||||
@Getter
|
||||
private final boolean parallel;
|
||||
|
||||
@Getter
|
||||
private final boolean async;
|
||||
|
||||
@Getter
|
||||
private final boolean cronSupported;
|
||||
|
||||
@Getter
|
||||
private final boolean hiddenFromUI;
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
@Getter
|
||||
private final String description;
|
||||
|
||||
TaskType(boolean parallel, boolean async, boolean cronSupported, boolean hiddenFromUI, String name, String description) {
|
||||
this.parallel = parallel;
|
||||
this.async = async;
|
||||
this.cronSupported = cronSupported;
|
||||
this.hiddenFromUI = hiddenFromUI;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.task.tasks.options;
|
||||
package com.adityachandel.booklore.task.options;
|
||||
|
||||
import com.adityachandel.booklore.model.enums.MetadataReplaceMode;
|
||||
import lombok.Builder;
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package com.adityachandel.booklore.task;
|
||||
package com.adityachandel.booklore.task.options;
|
||||
|
||||
import com.adityachandel.booklore.task.tasks.options.LibraryRescanOptions;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
package com.adityachandel.booklore.task.tasks;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.BookRecommendationLite;
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.model.websocket.TaskProgressPayload;
|
||||
import com.adityachandel.booklore.model.websocket.Topic;
|
||||
import com.adityachandel.booklore.service.book.BookQueryService;
|
||||
import com.adityachandel.booklore.service.NotificationService;
|
||||
import com.adityachandel.booklore.service.recommender.BookVectorService;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BookRecommendationUpdaterTask implements Task {
|
||||
|
||||
private final BookQueryService bookQueryService;
|
||||
private final BookVectorService vectorService;
|
||||
private final NotificationService notificationService;
|
||||
|
||||
private static final int RECOMMENDATION_LIMIT = 25;
|
||||
private static final long MIN_NOTIFICATION_INTERVAL_MS = 250;
|
||||
|
||||
@Override
|
||||
public TaskCreateResponse execute(TaskCreateRequest request) {
|
||||
TaskCreateResponse.TaskCreateResponseBuilder builder = TaskCreateResponse.builder()
|
||||
.taskId(request.getTaskId())
|
||||
.taskType(TaskType.UPDATE_BOOK_RECOMMENDATIONS);
|
||||
|
||||
String taskId = builder.build().getTaskId();
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("{}: Task started", getTaskType());
|
||||
|
||||
long lastNotificationTime = 0;
|
||||
|
||||
lastNotificationTime = sendTaskProgressNotification(taskId, 0, "Starting book recommendation update", TaskStatus.IN_PROGRESS, lastNotificationTime, true);
|
||||
|
||||
List<BookEntity> allBooks = bookQueryService.getAllFullBookEntities();
|
||||
int totalBooks = allBooks.size();
|
||||
|
||||
lastNotificationTime = sendTaskProgressNotification(taskId, 5, String.format("Loaded %d books, generating embeddings...", totalBooks), TaskStatus.IN_PROGRESS, lastNotificationTime, false);
|
||||
|
||||
Map<Long, double[]> embeddings = new HashMap<>();
|
||||
List<BookEntity> booksToUpdate = new ArrayList<>();
|
||||
|
||||
int embeddingProgress = 0;
|
||||
for (BookEntity book : allBooks) {
|
||||
double[] embedding = vectorService.generateEmbedding(book);
|
||||
embeddings.put(book.getId(), embedding);
|
||||
|
||||
if (book.getMetadata() != null) {
|
||||
String embeddingJson = vectorService.serializeVector(embedding);
|
||||
if (!Objects.equals(book.getMetadata().getEmbeddingVector(), embeddingJson)) {
|
||||
book.getMetadata().setEmbeddingVector(embeddingJson);
|
||||
book.getMetadata().setEmbeddingUpdatedAt(Instant.now());
|
||||
}
|
||||
}
|
||||
|
||||
embeddingProgress++;
|
||||
if (embeddingProgress % 10 == 0 || embeddingProgress == totalBooks) {
|
||||
int progress = 5 + (embeddingProgress * 30 / totalBooks);
|
||||
lastNotificationTime = sendTaskProgressNotification(taskId, progress,
|
||||
String.format("Generated embeddings: %d/%d books", embeddingProgress, totalBooks),
|
||||
TaskStatus.IN_PROGRESS, lastNotificationTime, false);
|
||||
}
|
||||
}
|
||||
|
||||
lastNotificationTime = sendTaskProgressNotification(taskId, 35, "Computing book similarities...", TaskStatus.IN_PROGRESS, lastNotificationTime, false);
|
||||
|
||||
int processedBooks = 0;
|
||||
for (BookEntity targetBook : allBooks) {
|
||||
try {
|
||||
double[] targetVector = embeddings.get(targetBook.getId());
|
||||
if (targetVector == null) continue;
|
||||
|
||||
String targetSeries = Optional.ofNullable(targetBook.getMetadata())
|
||||
.map(BookMetadataEntity::getSeriesName)
|
||||
.map(String::toLowerCase)
|
||||
.orElse(null);
|
||||
|
||||
List<BookVectorService.ScoredBook> candidates = allBooks.stream()
|
||||
.filter(candidate -> !candidate.getId().equals(targetBook.getId()))
|
||||
.filter(candidate -> {
|
||||
String candidateSeries = Optional.ofNullable(candidate.getMetadata())
|
||||
.map(BookMetadataEntity::getSeriesName)
|
||||
.map(String::toLowerCase)
|
||||
.orElse(null);
|
||||
return targetSeries == null || !targetSeries.equals(candidateSeries);
|
||||
})
|
||||
.map(candidate -> {
|
||||
double[] candidateVector = embeddings.get(candidate.getId());
|
||||
double similarity = vectorService.cosineSimilarity(targetVector, candidateVector);
|
||||
return new BookVectorService.ScoredBook(candidate.getId(), similarity);
|
||||
})
|
||||
.filter(scored -> scored.getScore() > 0.1)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<BookVectorService.ScoredBook> topSimilar = vectorService.findTopKSimilar(
|
||||
targetVector,
|
||||
candidates,
|
||||
RECOMMENDATION_LIMIT
|
||||
);
|
||||
|
||||
Set<BookRecommendationLite> recommendations = topSimilar.stream()
|
||||
.map(scored -> new BookRecommendationLite(scored.getBookId(), scored.getScore()))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
targetBook.setSimilarBooksJson(recommendations);
|
||||
booksToUpdate.add(targetBook);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("{}: Error updating similar books for book ID {}", getTaskType(), targetBook.getId(), e);
|
||||
}
|
||||
|
||||
processedBooks++;
|
||||
if (processedBooks % 10 == 0 || processedBooks == totalBooks) {
|
||||
int progress = 35 + (processedBooks * 50 / totalBooks);
|
||||
lastNotificationTime = sendTaskProgressNotification(taskId, progress,
|
||||
String.format("Computing similarities: %d/%d books", processedBooks, totalBooks),
|
||||
TaskStatus.IN_PROGRESS, lastNotificationTime, false);
|
||||
}
|
||||
}
|
||||
|
||||
lastNotificationTime = sendTaskProgressNotification(taskId, 85, String.format("Saving recommendations for %d books...", booksToUpdate.size()), TaskStatus.IN_PROGRESS, lastNotificationTime, false);
|
||||
|
||||
bookQueryService.saveAll(booksToUpdate);
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("{}: Task completed. Duration: {} ms", getTaskType(), endTime - startTime);
|
||||
|
||||
sendTaskProgressNotification(taskId, 100, String.format("Updated recommendations for %d books in %d ms", totalBooks, endTime - startTime), TaskStatus.COMPLETED, lastNotificationTime, true);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private long sendTaskProgressNotification(String taskId, int progress, String message, TaskStatus taskStatus, long lastNotificationTime, boolean force) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
// Send if forced (start/end) or if enough time has passed
|
||||
if (force || (currentTime - lastNotificationTime) >= MIN_NOTIFICATION_INTERVAL_MS) {
|
||||
try {
|
||||
TaskProgressPayload payload = TaskProgressPayload.builder()
|
||||
.taskId(taskId)
|
||||
.taskType(TaskType.UPDATE_BOOK_RECOMMENDATIONS)
|
||||
.message(message)
|
||||
.progress(progress)
|
||||
.taskStatus(taskStatus)
|
||||
.build();
|
||||
|
||||
notificationService.sendMessage(Topic.TASK_PROGRESS, payload);
|
||||
return currentTime;
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to send task progress notification for taskId={}: {}", taskId, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
return lastNotificationTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskType getTaskType() {
|
||||
return TaskType.UPDATE_BOOK_RECOMMENDATIONS;
|
||||
}
|
||||
}
|
||||
+16
-7
@@ -2,8 +2,9 @@ package com.adityachandel.booklore.task.tasks;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.task.TaskMetadataHelper;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -26,12 +27,13 @@ public class ClearCbxCacheTask implements Task {
|
||||
|
||||
@Override
|
||||
public TaskCreateResponse execute(TaskCreateRequest request) {
|
||||
log.info("Starting CBX cache clearing task");
|
||||
|
||||
TaskCreateResponse.TaskCreateResponseBuilder builder = TaskCreateResponse.builder()
|
||||
.taskId(UUID.randomUUID().toString())
|
||||
.taskType(TaskType.CLEAR_CBX_CACHE);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("{}: Task started", getTaskType());
|
||||
|
||||
try {
|
||||
String cbxCachePath = fileService.getCbxCachePath();
|
||||
Path cachePath = Paths.get(cbxCachePath);
|
||||
@@ -49,19 +51,21 @@ public class ClearCbxCacheTask implements Task {
|
||||
}
|
||||
|
||||
Files.createDirectories(cachePath);
|
||||
log.info("CBX cache cleared and directory recreated");
|
||||
log.info("{}: Cache cleared and directory recreated", getTaskType());
|
||||
} else {
|
||||
log.warn("CBX cache path does not exist or is not a directory: {}", cbxCachePath);
|
||||
log.warn("{}: Cache path does not exist or is not a directory: {}", getTaskType(), cbxCachePath);
|
||||
}
|
||||
|
||||
builder.status(TaskStatus.COMPLETED);
|
||||
log.info("CBX cache clearing task completed successfully");
|
||||
} catch (Exception e) {
|
||||
log.error("Error clearing CBX cache", e);
|
||||
log.error("{}: Error clearing cache", getTaskType(), e);
|
||||
builder.status(TaskStatus.FAILED);
|
||||
throw new RuntimeException("Failed to clear CBX cache", e);
|
||||
}
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("{}: Task completed. Duration: {} ms", getTaskType(), endTime - startTime);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -69,4 +73,9 @@ public class ClearCbxCacheTask implements Task {
|
||||
public TaskType getTaskType() {
|
||||
return TaskType.CLEAR_CBX_CACHE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMetadata() {
|
||||
return TaskMetadataHelper.getCacheSizeString(fileService.getCbxCachePath());
|
||||
}
|
||||
}
|
||||
|
||||
+16
-8
@@ -2,8 +2,9 @@ package com.adityachandel.booklore.task.tasks;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.task.TaskMetadataHelper;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -26,12 +27,13 @@ public class ClearPdfCacheTask implements Task {
|
||||
|
||||
@Override
|
||||
public TaskCreateResponse execute(TaskCreateRequest request) {
|
||||
log.info("Starting PDF cache clearing task");
|
||||
|
||||
TaskCreateResponse.TaskCreateResponseBuilder builder = TaskCreateResponse.builder()
|
||||
.taskId(UUID.randomUUID().toString())
|
||||
.taskType(TaskType.CLEAR_PDF_CACHE);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("{}: Task started", getTaskType());
|
||||
|
||||
try {
|
||||
String pdfCachePath = fileService.getPdfCachePath();
|
||||
Path cachePath = Paths.get(pdfCachePath);
|
||||
@@ -49,19 +51,21 @@ public class ClearPdfCacheTask implements Task {
|
||||
}
|
||||
|
||||
Files.createDirectories(cachePath);
|
||||
log.info("PDF cache cleared and directory recreated");
|
||||
log.info("{}: Cache cleared and directory recreated", getTaskType());
|
||||
} else {
|
||||
log.warn("PDF cache path does not exist or is not a directory: {}", pdfCachePath);
|
||||
log.warn("{}: Cache path does not exist or is not a directory: {}", getTaskType(), pdfCachePath);
|
||||
}
|
||||
|
||||
builder.status(TaskStatus.COMPLETED);
|
||||
log.info("PDF cache clearing task completed successfully");
|
||||
} catch (Exception e) {
|
||||
log.error("Error clearing PDF cache", e);
|
||||
log.error("{}: Error clearing cache", getTaskType(), e);
|
||||
builder.status(TaskStatus.FAILED);
|
||||
throw new RuntimeException("Failed to clear PDF cache", e);
|
||||
}
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("{}: Task completed. Duration: {} ms", getTaskType(), endTime - startTime);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -69,5 +73,9 @@ public class ClearPdfCacheTask implements Task {
|
||||
public TaskType getTaskType() {
|
||||
return TaskType.CLEAR_PDF_CACHE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMetadata() {
|
||||
return TaskMetadataHelper.getCacheSizeString(fileService.getPdfCachePath());
|
||||
}
|
||||
}
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.adityachandel.booklore.task.tasks;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class DeletedBooksCleanupTask implements Task {
|
||||
|
||||
private final BookRepository bookRepository;
|
||||
|
||||
@Override
|
||||
public TaskCreateResponse execute(TaskCreateRequest request) {
|
||||
TaskCreateResponse.TaskCreateResponseBuilder builder = TaskCreateResponse.builder()
|
||||
.taskId(UUID.randomUUID().toString())
|
||||
.taskType(getTaskType());
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("{}: Task started", getTaskType());
|
||||
|
||||
try {
|
||||
int deletedCount = bookRepository.deleteAllSoftDeleted();
|
||||
log.info("{}: Removed {} deleted books", getTaskType(), deletedCount);
|
||||
|
||||
builder.status(TaskStatus.COMPLETED);
|
||||
} catch (Exception e) {
|
||||
log.error("{}: Error cleaning up deleted books", getTaskType(), e);
|
||||
builder.status(TaskStatus.FAILED);
|
||||
}
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("{}: Task completed. Duration: {} ms", getTaskType(), endTime - startTime);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskType getTaskType() {
|
||||
return TaskType.CLEANUP_DELETED_BOOKS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMetadata() {
|
||||
long deleted = bookRepository.countAllSoftDeleted();
|
||||
return "Book" + (deleted != 1 ? "s" : "") + " pending cleanup: " + deleted;
|
||||
}
|
||||
}
|
||||
+13
-7
@@ -3,12 +3,12 @@ package com.adityachandel.booklore.task.tasks;
|
||||
import com.adityachandel.booklore.model.dto.Library;
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.service.library.LibraryRescanHelper;
|
||||
import com.adityachandel.booklore.service.library.LibraryService;
|
||||
import com.adityachandel.booklore.task.RescanLibraryContext;
|
||||
import com.adityachandel.booklore.task.options.RescanLibraryContext;
|
||||
import com.adityachandel.booklore.task.TaskCancellationManager;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.task.tasks.options.LibraryRescanOptions;
|
||||
import com.adityachandel.booklore.task.options.LibraryRescanOptions;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
@@ -30,12 +30,15 @@ public class LibraryRescanTask implements Task {
|
||||
public TaskCreateResponse execute(TaskCreateRequest request) {
|
||||
LibraryRescanOptions options = request.getOptions(LibraryRescanOptions.class);
|
||||
String taskId = request.getTaskId();
|
||||
log.info("Starting LibraryRescanTask. TaskId: {}, Options: {}", taskId, options);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("{}: Task started. TaskId: {}, Options: {}", getTaskType(), taskId, options);
|
||||
|
||||
List<Library> libraries = libraryService.getAllLibraries();
|
||||
|
||||
for (Library library : libraries) {
|
||||
if (cancellationManager.isTaskCancelled(taskId)) {
|
||||
log.info("LibraryRescanTask {} was cancelled, stopping execution", taskId);
|
||||
log.info("{}: Task {} was cancelled, stopping execution", getTaskType(), taskId);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -49,14 +52,17 @@ public class LibraryRescanTask implements Task {
|
||||
} catch (InvalidDataAccessApiUsageException e) {
|
||||
log.debug("InvalidDataAccessApiUsageException - Library id: {}", libraryId);
|
||||
}
|
||||
log.info("Library rescan completed for library: {}", libraryId);
|
||||
log.info("{}: Library rescan completed for library: {}", getTaskType(), libraryId);
|
||||
}
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("{}: Task completed. Duration: {} ms", getTaskType(), endTime - startTime);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskType getTaskType() {
|
||||
return TaskType.RE_SCAN_LIBRARY;
|
||||
return TaskType.REFRESH_LIBRARY_METADATA;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.adityachandel.booklore.task.tasks;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.Library;
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.service.library.LibraryService;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class LibraryScanTask implements Task {
|
||||
|
||||
private final LibraryService libraryService;
|
||||
|
||||
@Override
|
||||
public TaskCreateResponse execute(TaskCreateRequest request) {
|
||||
TaskCreateResponse.TaskCreateResponseBuilder builder = TaskCreateResponse.builder()
|
||||
.taskId(UUID.randomUUID().toString())
|
||||
.taskType(getTaskType());
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("{}: Task started", getTaskType());
|
||||
|
||||
try {
|
||||
for (Library library : libraryService.getAllLibraries()) {
|
||||
try {
|
||||
libraryService.rescanLibrary(library.getId());
|
||||
log.info("{}: Rescanned library '{}'", getTaskType(), library.getName());
|
||||
} catch (Exception e) {
|
||||
log.error("{}: Failed to rescan library '{}': {}", getTaskType(), library.getName(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
builder.status(TaskStatus.COMPLETED);
|
||||
} catch (Exception e) {
|
||||
log.error("{}: Error scanning libraries", getTaskType(), e);
|
||||
builder.status(TaskStatus.FAILED);
|
||||
}
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("{}: Task completed. Duration: {} ms", getTaskType(), endTime - startTime);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskType getTaskType() {
|
||||
return TaskType.SYNC_LIBRARY_FILES;
|
||||
}
|
||||
}
|
||||
+14
-4
@@ -5,6 +5,7 @@ import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.service.metadata.MetadataRefreshService;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -16,20 +17,29 @@ public class RefreshMetadataTask implements Task {
|
||||
|
||||
private final MetadataRefreshService metadataRefreshService;
|
||||
|
||||
|
||||
@Override
|
||||
public TaskCreateResponse execute(TaskCreateRequest request) {
|
||||
MetadataRefreshRequest refreshRequest = request.getOptions(MetadataRefreshRequest.class);
|
||||
String taskId = request.getTaskId();
|
||||
log.info("Starting RefreshMetadataTask. TaskId: {}, Options: {}", taskId, null);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("{}: Task started. TaskId: {}, Options: {}", getTaskType(), taskId, refreshRequest);
|
||||
|
||||
metadataRefreshService.refreshMetadata(refreshRequest, taskId);
|
||||
|
||||
return null;
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("{}: Task completed. Duration: {} ms", getTaskType(), endTime - startTime);
|
||||
|
||||
return TaskCreateResponse
|
||||
.builder()
|
||||
.taskType(TaskType.REFRESH_METADATA_MANUAL)
|
||||
.taskId(taskId)
|
||||
.status(TaskStatus.COMPLETED)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskType getTaskType() {
|
||||
return TaskType.REFRESH_METADATA;
|
||||
return TaskType.REFRESH_METADATA_MANUAL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,8 @@ public interface Task {
|
||||
TaskCreateResponse execute(TaskCreateRequest request);
|
||||
|
||||
TaskType getTaskType();
|
||||
}
|
||||
|
||||
default String getMetadata() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.adityachandel.booklore.task.tasks;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
||||
import com.adityachandel.booklore.model.enums.TaskType;
|
||||
import com.adityachandel.booklore.repository.MetadataFetchJobRepository;
|
||||
import com.adityachandel.booklore.task.TaskStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class TempFetchedMetadataCleanupTask implements Task {
|
||||
|
||||
private final MetadataFetchJobRepository metadataFetchJobRepository;
|
||||
|
||||
@Override
|
||||
public TaskCreateResponse execute(TaskCreateRequest request) {
|
||||
TaskCreateResponse.TaskCreateResponseBuilder builder = TaskCreateResponse.builder()
|
||||
.taskId(UUID.randomUUID().toString())
|
||||
.taskType(getTaskType());
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("{}: Task started", getTaskType());
|
||||
|
||||
try {
|
||||
Instant cutoff = Instant.now().minus(5, ChronoUnit.DAYS);
|
||||
int deleted = metadataFetchJobRepository.deleteAllByCompletedAtBefore(cutoff);
|
||||
log.info("{}: Removed {} metadata fetch jobs older than {}", getTaskType(), deleted, cutoff);
|
||||
|
||||
builder.status(TaskStatus.COMPLETED);
|
||||
} catch (Exception e) {
|
||||
log.error("{}: Error cleaning up temp metadata", getTaskType(), e);
|
||||
builder.status(TaskStatus.FAILED);
|
||||
}
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("{}: Task completed. Duration: {} ms", getTaskType(), endTime - startTime);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskType getTaskType() {
|
||||
return TaskType.CLEANUP_TEMP_METADATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMetadata() {
|
||||
long count = metadataFetchJobRepository.countAll();
|
||||
return "Metadata " + (count != 1 ? "rows" : "row") + " pending cleanup: " + count;
|
||||
}
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
package com.adityachandel.booklore.task.tasks.options;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ClearCbxCacheOptions {
|
||||
|
||||
}
|
||||
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
package com.adityachandel.booklore.task.tasks.options;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ClearPdfCacheOptions {
|
||||
}
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
CREATE TABLE IF NOT EXISTS task_cron_configuration
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
task_type VARCHAR(100) NOT NULL,
|
||||
cron_expression VARCHAR(100) NOT NULL,
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_by BIGINT NOT NULL DEFAULT -1,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
CONSTRAINT uq_task_type UNIQUE (task_type)
|
||||
);
|
||||
|
||||
INSERT INTO task_cron_configuration (task_type, cron_expression, enabled, created_by)
|
||||
VALUES
|
||||
('CLEAR_CBX_CACHE', '0 30 0 * * 1', FALSE, -1), -- Run CLEAR_CBX_CACHE every Monday at 12:30 AM
|
||||
('CLEAR_PDF_CACHE', '0 35 0 * * 1', FALSE, -1), -- Run CLEAR_PDF_CACHE every Monday at 12:35 AM
|
||||
('CLEANUP_DELETED_BOOKS', '0 40 0 * * 1', TRUE, -1), -- Run CLEANUP_DELETED_BOOKS every Monday at 12:40 AM
|
||||
('CLEANUP_TEMP_METADATA', '0 45 0 * * 1', TRUE, -1), -- Run CLEANUP_TEMP_METADATA every Monday at 12:45 AM
|
||||
('SYNC_LIBRARY_FILES', '0 0 1 * * *', TRUE, -1), -- Run RE_SCAN_LIBRARY every day at 1:00 AM
|
||||
('UPDATE_BOOK_RECOMMENDATIONS', '0 30 1 * * *', TRUE, -1); -- Run UPDATE_BOOK_RECOMMENDATIONS every day at 1:30 AM
|
||||
@@ -3,10 +3,10 @@ package com.adityachandel.booklore;
|
||||
import com.adityachandel.booklore.config.security.service.AuthenticationService;
|
||||
import com.adityachandel.booklore.mapper.BookMapper;
|
||||
import com.adityachandel.booklore.repository.*;
|
||||
import com.adityachandel.booklore.service.BookDownloadService;
|
||||
import com.adityachandel.booklore.service.BookQueryService;
|
||||
import com.adityachandel.booklore.service.BookService;
|
||||
import com.adityachandel.booklore.service.UserProgressService;
|
||||
import com.adityachandel.booklore.service.book.BookDownloadService;
|
||||
import com.adityachandel.booklore.service.book.BookQueryService;
|
||||
import com.adityachandel.booklore.service.book.BookService;
|
||||
import com.adityachandel.booklore.service.user.UserProgressService;
|
||||
import com.adityachandel.booklore.service.monitoring.MonitoringRegistrationService;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.progress.KoreaderProgress;
|
||||
import com.adityachandel.booklore.service.KoreaderService;
|
||||
import com.adityachandel.booklore.service.koreader.KoreaderService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.*;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.KoreaderUser;
|
||||
import com.adityachandel.booklore.service.KoreaderUserService;
|
||||
import com.adityachandel.booklore.service.koreader.KoreaderUserService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.*;
|
||||
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
package com.adityachandel.booklore.scheduler;
|
||||
|
||||
import com.adityachandel.booklore.repository.MetadataFetchJobRepository;
|
||||
import com.adityachandel.booklore.service.scheduler.MetadataFetchCleanupService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.*;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class MetadataFetchCleanupServiceTest {
|
||||
|
||||
@Mock
|
||||
private MetadataFetchJobRepository metadataFetchJobRepository;
|
||||
|
||||
@InjectMocks
|
||||
private MetadataFetchCleanupService cleanupService;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<Instant> instantCaptor;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
void cleanupOldMetadataFetchJobs_shouldCallRepositoryWithCorrectCutoff() {
|
||||
when(metadataFetchJobRepository.deleteAllByCompletedAtBefore(any())).thenReturn(5);
|
||||
|
||||
cleanupService.cleanupOldMetadataFetchJobs();
|
||||
|
||||
verify(metadataFetchJobRepository, times(1)).deleteAllByCompletedAtBefore(instantCaptor.capture());
|
||||
|
||||
Instant cutoff = instantCaptor.getValue();
|
||||
Instant expectedCutoff = Instant.now().minus(5, ChronoUnit.DAYS);
|
||||
|
||||
long deltaSeconds = Math.abs(cutoff.getEpochSecond() - expectedCutoff.getEpochSecond());
|
||||
assert deltaSeconds < 5 : "Cutoff instant should be about 5 days ago";
|
||||
}
|
||||
|
||||
@Test
|
||||
void cleanupOldMetadataFetchJobs_shouldLogDeletedCount() {
|
||||
when(metadataFetchJobRepository.deleteAllByCompletedAtBefore(any())).thenReturn(10);
|
||||
|
||||
cleanupService.cleanupOldMetadataFetchJobs();
|
||||
|
||||
verify(metadataFetchJobRepository, times(1)).deleteAllByCompletedAtBefore(any());
|
||||
}
|
||||
}
|
||||
+1
@@ -7,6 +7,7 @@ import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryPathEntity;
|
||||
import com.adityachandel.booklore.model.enums.AdditionalFileType;
|
||||
import com.adityachandel.booklore.repository.BookAdditionalFileRepository;
|
||||
import com.adityachandel.booklore.service.file.AdditionalFileService;
|
||||
import com.adityachandel.booklore.service.monitoring.MonitoringRegistrationService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.adityachandel.booklore.model.entity.BookNoteEntity;
|
||||
import com.adityachandel.booklore.repository.BookNoteRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.UserRepository;
|
||||
import com.adityachandel.booklore.service.book.BookNoteService;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
+1
@@ -14,6 +14,7 @@ import com.adityachandel.booklore.model.enums.MetadataProvider;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.BookReviewRepository;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import com.adityachandel.booklore.service.book.BookReviewService;
|
||||
import com.adityachandel.booklore.service.metadata.BookReviewUpdateService;
|
||||
import com.adityachandel.booklore.service.metadata.MetadataRefreshService;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user