Merge pull request #522 from adityachandelgit/develop
Merge Develop into Master for Release
This commit is contained in:
+4
-4
@@ -42,11 +42,11 @@ public class MetadataController {
|
||||
|
||||
@PutMapping("/{bookId}/metadata")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<BookMetadata> updateMetadata(
|
||||
@RequestBody BookMetadata setMetadataRequest, @PathVariable long bookId,
|
||||
@RequestParam(defaultValue = "true") boolean mergeCategories) {
|
||||
public ResponseEntity<BookMetadata> updateMetadata(@RequestBody BookMetadata setMetadataRequest, @PathVariable long bookId, @RequestParam(defaultValue = "true") boolean mergeCategories) {
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookMetadata bookMetadata = bookMetadataMapper.toBookMetadata(bookMetadataUpdater.setBookMetadata(bookEntity, setMetadataRequest, true, mergeCategories), true);
|
||||
bookMetadataUpdater.setBookMetadata(bookEntity, setMetadataRequest, true, mergeCategories);
|
||||
bookRepository.save(bookEntity);
|
||||
BookMetadata bookMetadata = bookMetadataMapper.toBookMetadata(bookEntity.getMetadata(), true);
|
||||
return ResponseEntity.ok(bookMetadata);
|
||||
}
|
||||
|
||||
|
||||
-4
@@ -131,9 +131,6 @@ public class BookMetadataEntity {
|
||||
@Column(name = "page_count_locked")
|
||||
private Boolean pageCountLocked = Boolean.FALSE;
|
||||
|
||||
@Column(name = "thumbnail_locked")
|
||||
private Boolean thumbnailLocked = Boolean.FALSE;
|
||||
|
||||
@Column(name = "language_locked")
|
||||
private Boolean languageLocked = Boolean.FALSE;
|
||||
|
||||
@@ -215,7 +212,6 @@ public class BookMetadataEntity {
|
||||
this.isbn10Locked = lock;
|
||||
this.asinLocked = lock;
|
||||
this.pageCountLocked = lock;
|
||||
this.thumbnailLocked = lock;
|
||||
this.languageLocked = lock;
|
||||
this.coverLocked = lock;
|
||||
this.seriesNameLocked = lock;
|
||||
|
||||
+2
-11
@@ -28,19 +28,14 @@ import com.adityachandel.booklore.service.fileprocessor.PdfProcessor;
|
||||
import com.adityachandel.booklore.service.metadata.parser.BookParser;
|
||||
import com.adityachandel.booklore.service.BookQueryService;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -140,17 +135,13 @@ public class BookMetadataService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
protected BookMetadataEntity updateBookMetadata(BookEntity bookEntity, BookMetadata metadata, boolean replaceCover, boolean mergeCategories) {
|
||||
protected void updateBookMetadata(BookEntity bookEntity, BookMetadata metadata, boolean replaceCover, boolean mergeCategories) {
|
||||
if (metadata != null) {
|
||||
BookMetadataEntity bookMetadata = bookMetadataUpdater.setBookMetadata(bookEntity, metadata, replaceCover, mergeCategories);
|
||||
bookEntity.setMetadata(bookMetadata);
|
||||
bookRepository.save(bookEntity);
|
||||
bookMetadataUpdater.setBookMetadata(bookEntity, metadata, replaceCover, mergeCategories);
|
||||
Book book = bookMapper.toBook(bookEntity);
|
||||
notificationService.sendMessage(Topic.BOOK_METADATA_UPDATE, book);
|
||||
notificationService.sendMessage(Topic.LOG, createLogNotification("Book metadata updated: " + book.getMetadata().getTitle()));
|
||||
return bookMetadata;
|
||||
}
|
||||
return bookEntity.getMetadata();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
+7
-12
@@ -7,6 +7,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.model.entity.CategoryEntity;
|
||||
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.repository.AuthorRepository;
|
||||
import com.adityachandel.booklore.repository.BookMetadataRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
@@ -35,9 +36,7 @@ import java.util.stream.Collectors;
|
||||
@AllArgsConstructor
|
||||
public class BookMetadataUpdater {
|
||||
|
||||
private final BookRepository bookRepository;
|
||||
private final AuthorRepository authorRepository;
|
||||
private final BookMetadataRepository bookMetadataRepository;
|
||||
private final CategoryRepository categoryRepository;
|
||||
private final FileService fileService;
|
||||
private final MetadataMatchService metadataMatchService;
|
||||
@@ -46,22 +45,23 @@ public class BookMetadataUpdater {
|
||||
private final EpubMetadataWriter epubMetadataWriter;
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public BookMetadataEntity setBookMetadata(BookEntity bookEntity, BookMetadata newMetadata, boolean setThumbnail, boolean mergeCategories) {
|
||||
public void setBookMetadata(BookEntity bookEntity, BookMetadata newMetadata, boolean setThumbnail, boolean mergeCategories) {
|
||||
BookMetadataEntity metadata = bookEntity.getMetadata();
|
||||
|
||||
updateLocks(newMetadata, metadata);
|
||||
|
||||
if (metadata.areAllFieldsLocked()) {
|
||||
log.warn("Attempted to update metadata for book with ID {}, but all fields are locked. No update performed.", bookEntity.getId());
|
||||
return metadata;
|
||||
return;
|
||||
}
|
||||
|
||||
MetadataPersistenceSettings settings = appSettingService.getAppSettings().getMetadataPersistenceSettings();
|
||||
boolean writeToFile = settings.isSaveToOriginalFile();
|
||||
boolean backupEnabled = settings.isBackupMetadata();
|
||||
boolean backupCover = settings.isBackupCover();
|
||||
BookFileType bookType = bookEntity.getBookType();
|
||||
|
||||
if (writeToFile && backupEnabled) {
|
||||
if (writeToFile && backupEnabled && bookType == BookFileType.EPUB) {
|
||||
try {
|
||||
metadataBackupRestoreService.backupEmbeddedMetadataIfNotExists(bookEntity, backupCover);
|
||||
} catch (Exception e) {
|
||||
@@ -74,17 +74,14 @@ public class BookMetadataUpdater {
|
||||
updateCategoriesIfNeeded(newMetadata, metadata, mergeCategories);
|
||||
updateThumbnailIfNeeded(bookEntity.getId(), newMetadata, metadata, setThumbnail);
|
||||
|
||||
bookMetadataRepository.save(metadata);
|
||||
|
||||
try {
|
||||
Float score = metadataMatchService.calculateMatchScore(bookEntity);
|
||||
bookEntity.setMetadataMatchScore(score);
|
||||
bookRepository.save(bookEntity);
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to calculate/save metadata match score for book ID {}: {}", bookEntity.getId(), e.getMessage());
|
||||
}
|
||||
|
||||
if (writeToFile) {
|
||||
if (writeToFile && bookType == BookFileType.EPUB) {
|
||||
try {
|
||||
File bookFile = new File(bookEntity.getFullFilePath().toUri());
|
||||
epubMetadataWriter.writeMetadataToFile(bookFile, metadata);
|
||||
@@ -93,8 +90,6 @@ public class BookMetadataUpdater {
|
||||
log.warn("Failed to write metadata to EPUB for book ID {}: {}", bookEntity.getId(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private void updateBasicFields(BookMetadata newMetadata, BookMetadataEntity metadata) {
|
||||
@@ -155,7 +150,7 @@ public class BookMetadataUpdater {
|
||||
}
|
||||
|
||||
private void updateThumbnailIfNeeded(long bookId, BookMetadata newMetadata, BookMetadataEntity metadata, boolean setThumbnail) {
|
||||
if (setThumbnail && shouldUpdateField(metadata.getThumbnailLocked(), newMetadata.getThumbnailUrl()) && !newMetadata.getThumbnailUrl().isEmpty()) {
|
||||
if (setThumbnail && shouldUpdateField(metadata.getCoverLocked(), newMetadata.getThumbnailUrl()) && !newMetadata.getThumbnailUrl().isEmpty()) {
|
||||
String thumbnailPath = null;
|
||||
try {
|
||||
thumbnailPath = fileService.createThumbnail(bookId, newMetadata.getThumbnailUrl());
|
||||
|
||||
@@ -150,6 +150,7 @@ export class AppMenuComponent implements OnInit {
|
||||
top: '10%',
|
||||
bottom: '10%',
|
||||
minWidth: '800px',
|
||||
maxWidth: '800px',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user