Replace arrow-based author reordering with CDK drag chips and persist author sort order (#3167) (#3175)
This commit is contained in:
@@ -38,11 +38,11 @@ public interface BookMapper {
|
||||
@Mapping(source = "bookFiles", target = "supplementaryFiles", qualifiedByName = "mapSupplementaryFiles")
|
||||
Book toBookWithDescription(BookEntity bookEntity, @Context boolean includeDescription);
|
||||
|
||||
default Set<String> mapAuthors(Set<AuthorEntity> authors) {
|
||||
default List<String> mapAuthors(List<AuthorEntity> authors) {
|
||||
if (authors == null) return null;
|
||||
return authors.stream()
|
||||
.map(AuthorEntity::getName)
|
||||
.collect(Collectors.toSet());
|
||||
.toList();
|
||||
}
|
||||
|
||||
default Set<String> mapCategories(Set<CategoryEntity> categories) {
|
||||
|
||||
@@ -87,9 +87,9 @@ public interface BookMapperV2 {
|
||||
}
|
||||
|
||||
@Named("mapAuthors")
|
||||
default Set<String> mapAuthors(Set<AuthorEntity> authors) {
|
||||
return authors == null ? Set.of() :
|
||||
authors.stream().map(AuthorEntity::getName).collect(Collectors.toSet());
|
||||
default List<String> mapAuthors(List<AuthorEntity> authors) {
|
||||
return authors == null ? List.of() :
|
||||
authors.stream().map(AuthorEntity::getName).toList();
|
||||
}
|
||||
|
||||
@Named("mapCategories")
|
||||
|
||||
@@ -71,13 +71,13 @@ public interface MobileBookMapper {
|
||||
MobileBookDetail toDetail(BookEntity book, UserBookProgressEntity progress, UserBookFileProgressEntity fileProgress);
|
||||
|
||||
@Named("mapAuthors")
|
||||
default List<String> mapAuthors(Set<AuthorEntity> authors) {
|
||||
default List<String> mapAuthors(List<AuthorEntity> authors) {
|
||||
if (authors == null || authors.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return authors.stream()
|
||||
.map(AuthorEntity::getName)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Named("mapCategories")
|
||||
|
||||
@@ -2,10 +2,10 @@ package org.booklore.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UploadedFileMetadata {
|
||||
private String title;
|
||||
private Set<String> authors;
|
||||
private List<String> authors;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class BookMetadata {
|
||||
private String externalUrl;
|
||||
private Instant coverUpdatedOn;
|
||||
private Instant audiobookCoverUpdatedOn;
|
||||
private Set<String> authors;
|
||||
private List<String> authors;
|
||||
private Set<String> categories;
|
||||
private Set<String> moods;
|
||||
private Set<String> tags;
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.booklore.model.dto;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
@@ -37,6 +38,6 @@ public class EpubMetadata {
|
||||
private String googleId;
|
||||
private String ranobedbId;
|
||||
private Double ranobedbRating;
|
||||
private Set<String> authors;
|
||||
private List<String> authors;
|
||||
private Set<String> categories;
|
||||
}
|
||||
|
||||
+2
-1
@@ -3,13 +3,14 @@ package org.booklore.model.dto.request;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
public class BulkMetadataUpdateRequest {
|
||||
private Set<Long> bookIds;
|
||||
|
||||
private Set<String> authors;
|
||||
private List<String> authors;
|
||||
private boolean clearAuthors;
|
||||
|
||||
private String publisher;
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ public class GoogleBooksApiResponse {
|
||||
public static class VolumeInfo {
|
||||
private String title;
|
||||
private String subtitle;
|
||||
private Set<String> authors;
|
||||
private List<String> authors;
|
||||
private String publisher;
|
||||
private String publishedDate;
|
||||
private String description;
|
||||
|
||||
@@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
|
||||
import org.booklore.model.dto.ComicMetadata;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@@ -18,7 +19,7 @@ import java.util.Set;
|
||||
public class SidecarBookMetadata {
|
||||
private String title;
|
||||
private String subtitle;
|
||||
private Set<String> authors;
|
||||
private List<String> authors;
|
||||
private String publisher;
|
||||
private LocalDate publishedDate;
|
||||
private String description;
|
||||
|
||||
@@ -9,7 +9,9 @@ import org.hibernate.annotations.FetchMode;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@@ -369,7 +371,8 @@ public class BookMetadataEntity {
|
||||
joinColumns = @JoinColumn(name = "book_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "author_id"))
|
||||
@Fetch(FetchMode.SUBSELECT)
|
||||
private Set<AuthorEntity> authors;
|
||||
@OrderColumn(name = "sort_order")
|
||||
private List<AuthorEntity> authors;
|
||||
|
||||
@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
@JoinTable(
|
||||
|
||||
@@ -137,10 +137,10 @@ public class BookCreatorService {
|
||||
.forEach(catEntity -> bookEntity.getMetadata().getCategories().add(catEntity));
|
||||
}
|
||||
|
||||
public void addAuthorsToBook(Set<String> authors, BookEntity bookEntity) {
|
||||
public void addAuthorsToBook(Collection<String> authors, BookEntity bookEntity) {
|
||||
if (authors == null || authors.isEmpty()) return;
|
||||
if (bookEntity.getMetadata().getAuthors() == null) {
|
||||
bookEntity.getMetadata().setAuthors(new HashSet<>());
|
||||
bookEntity.getMetadata().setAuthors(new ArrayList<>());
|
||||
}
|
||||
authors.stream()
|
||||
.map(authorName -> truncate(authorName, 255))
|
||||
|
||||
@@ -26,8 +26,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -160,7 +162,7 @@ public class BookFileDetachmentService {
|
||||
copy.setContentRating(source.getContentRating());
|
||||
|
||||
if (source.getAuthors() != null) {
|
||||
copy.setAuthors(new HashSet<>(source.getAuthors()));
|
||||
copy.setAuthors(new ArrayList<>(source.getAuthors()));
|
||||
}
|
||||
if (source.getCategories() != null) {
|
||||
copy.setCategories(new HashSet<>(source.getCategories()));
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
@@ -69,7 +70,7 @@ public class PhysicalBookService {
|
||||
bookEntity.setMetadata(metadata);
|
||||
|
||||
if (request.getAuthors() != null && !request.getAuthors().isEmpty()) {
|
||||
addAuthorsToBook(new HashSet<>(request.getAuthors()), bookEntity);
|
||||
addAuthorsToBook(new ArrayList<>(request.getAuthors()), bookEntity);
|
||||
}
|
||||
|
||||
if (request.getCategories() != null && !request.getCategories().isEmpty()) {
|
||||
@@ -122,9 +123,9 @@ public class PhysicalBookService {
|
||||
return cleaned.length() == 10 ? cleaned : null;
|
||||
}
|
||||
|
||||
private void addAuthorsToBook(Set<String> authors, BookEntity bookEntity) {
|
||||
private void addAuthorsToBook(List<String> authors, BookEntity bookEntity) {
|
||||
if (bookEntity.getMetadata().getAuthors() == null) {
|
||||
bookEntity.getMetadata().setAuthors(new HashSet<>());
|
||||
bookEntity.getMetadata().setAuthors(new ArrayList<>());
|
||||
}
|
||||
authors.stream()
|
||||
.map(authorName -> truncate(authorName, 255))
|
||||
|
||||
+17
-1
@@ -120,7 +120,23 @@ public class BookdropBulkEditService {
|
||||
metadataHelper.updateFetchedMetadata(file, currentMetadata);
|
||||
}
|
||||
|
||||
private void updateArrayField(String fieldName, Set<String> enabledFields,
|
||||
private void updateArrayField(String fieldName, Set<String> enabledFields,
|
||||
List<String> currentValue, List<String> newValue,
|
||||
java.util.function.Consumer<List<String>> setter, boolean mergeArrays) {
|
||||
if (enabledFields.contains(fieldName) && newValue != null) {
|
||||
if (mergeArrays && currentValue != null) {
|
||||
List<String> merged = new ArrayList<>(currentValue);
|
||||
for (String v : newValue) {
|
||||
if (!merged.contains(v)) merged.add(v);
|
||||
}
|
||||
setter.accept(merged);
|
||||
} else {
|
||||
setter.accept(newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateArrayField(String fieldName, Set<String> enabledFields,
|
||||
Set<String> currentValue, Set<String> newValue,
|
||||
java.util.function.Consumer<Set<String>> setter, boolean mergeArrays) {
|
||||
if (enabledFields.contains(fieldName) && newValue != null) {
|
||||
|
||||
+2
-2
@@ -430,9 +430,9 @@ public class FilenamePatternExtractor {
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> parseAuthors(String value) {
|
||||
private List<String> parseAuthors(String value) {
|
||||
String[] parts = PATTERN.split(value);
|
||||
Set<String> authors = new LinkedHashSet<>();
|
||||
List<String> authors = new ArrayList<>();
|
||||
for (String part : parts) {
|
||||
String trimmed = part.trim();
|
||||
if (!trimmed.isEmpty()) {
|
||||
|
||||
@@ -241,37 +241,45 @@ public class BookMetadataUpdater {
|
||||
private void updateAuthorsIfNeeded(BookMetadata m, BookMetadataEntity e, MetadataClearFlags clear, boolean merge, MetadataReplaceMode replaceMode) {
|
||||
if (Boolean.TRUE.equals(e.getAuthorsLocked())) return;
|
||||
|
||||
e.setAuthors(Optional.ofNullable(e.getAuthors()).orElseGet(HashSet::new));
|
||||
e.setAuthors(Optional.ofNullable(e.getAuthors()).orElseGet(ArrayList::new));
|
||||
|
||||
if (clear.isAuthors()) {
|
||||
e.getAuthors().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> authorNames = Optional.ofNullable(m.getAuthors()).orElse(Collections.emptySet());
|
||||
List<String> authorNames = Optional.ofNullable(m.getAuthors()).orElse(Collections.emptyList());
|
||||
if (authorNames.isEmpty()) {
|
||||
if (replaceMode == MetadataReplaceMode.REPLACE_ALL) e.getAuthors().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
Set<AuthorEntity> newAuthors = authorNames.stream()
|
||||
List<AuthorEntity> newAuthors = authorNames.stream()
|
||||
.filter(name -> name != null && !name.isBlank())
|
||||
.map(name -> authorRepository.findByName(name)
|
||||
.orElseGet(() -> authorRepository.save(AuthorEntity.builder().name(name).build())))
|
||||
.collect(Collectors.toSet());
|
||||
.toList();
|
||||
|
||||
if (newAuthors.isEmpty()) return;
|
||||
|
||||
if (replaceMode == MetadataReplaceMode.REPLACE_ALL || replaceMode == MetadataReplaceMode.REPLACE_WHEN_PROVIDED) {
|
||||
if (!merge) e.getAuthors().clear();
|
||||
e.getAuthors().addAll(newAuthors);
|
||||
for (AuthorEntity author : newAuthors) {
|
||||
if (!e.getAuthors().contains(author)) {
|
||||
e.getAuthors().add(author);
|
||||
}
|
||||
}
|
||||
e.updateSearchText();
|
||||
} else if (replaceMode == MetadataReplaceMode.REPLACE_MISSING && e.getAuthors().isEmpty()) {
|
||||
e.getAuthors().addAll(newAuthors);
|
||||
e.updateSearchText();
|
||||
} else if (replaceMode == null) {
|
||||
if (!merge) e.getAuthors().clear();
|
||||
e.getAuthors().addAll(newAuthors);
|
||||
for (AuthorEntity author : newAuthors) {
|
||||
if (!e.getAuthors().contains(author)) {
|
||||
e.getAuthors().add(author);
|
||||
}
|
||||
}
|
||||
e.updateSearchText();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,9 +2,9 @@ package org.booklore.service.metadata;
|
||||
|
||||
import org.booklore.model.dto.BookMetadata;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
|
||||
@FunctionalInterface
|
||||
interface FieldValueExtractorList {
|
||||
Set<String> extract(BookMetadata metadata);
|
||||
Collection<String> extract(BookMetadata metadata);
|
||||
}
|
||||
|
||||
+12
-4
@@ -675,7 +675,7 @@ public class MetadataRefreshService {
|
||||
if (refreshOptions.isMergeCategories()) {
|
||||
metadata.setCategories(getAllCategories(metadataMap, fieldOptions.getCategories(), BookMetadata::getCategories));
|
||||
} else {
|
||||
metadata.setCategories(resolveFieldAsList(metadataMap, fieldOptions.getCategories(), BookMetadata::getCategories));
|
||||
metadata.setCategories(resolveFieldAsSet(metadataMap, fieldOptions.getCategories(), BookMetadata::getCategories));
|
||||
}
|
||||
} else if (isReplaceAll && existingMetadata != null) {
|
||||
metadata.setCategories(existingMetadata.getCategories());
|
||||
@@ -704,8 +704,16 @@ public class MetadataRefreshService {
|
||||
return resolveFieldWithProviders(metadataMap, fieldProvider, fieldValueExtractor::extract, Objects::nonNull);
|
||||
}
|
||||
|
||||
protected Set<String> resolveFieldAsList (Map < MetadataProvider, BookMetadata > metadataMap, MetadataRefreshOptions.FieldProvider fieldProvider, FieldValueExtractorList fieldValueExtractor){
|
||||
return resolveFieldWithProviders(metadataMap, fieldProvider, fieldValueExtractor::extract, (value) -> value != null && !value.isEmpty());
|
||||
protected List<String> resolveFieldAsList (Map < MetadataProvider, BookMetadata > metadataMap, MetadataRefreshOptions.FieldProvider fieldProvider, FieldValueExtractorList fieldValueExtractor){
|
||||
Collection<String> result = resolveFieldWithProviders(metadataMap, fieldProvider, fieldValueExtractor::extract, (value) -> value != null && !value.isEmpty());
|
||||
if (result == null) return null;
|
||||
return result instanceof List<String> list ? list : new ArrayList<>(result);
|
||||
}
|
||||
|
||||
protected Set<String> resolveFieldAsSet (Map < MetadataProvider, BookMetadata > metadataMap, MetadataRefreshOptions.FieldProvider fieldProvider, FieldValueExtractorList fieldValueExtractor){
|
||||
Collection<String> result = resolveFieldWithProviders(metadataMap, fieldProvider, fieldValueExtractor::extract, (value) -> value != null && !value.isEmpty());
|
||||
if (result == null) return null;
|
||||
return result instanceof Set<String> set ? set : new HashSet<>(result);
|
||||
}
|
||||
|
||||
private <T > T resolveFieldWithProviders(Map < MetadataProvider, BookMetadata > metadataMap, MetadataRefreshOptions.FieldProvider fieldProvider, Function < BookMetadata, T > extractor, Predicate < T > isValidValue) {
|
||||
@@ -744,7 +752,7 @@ public class MetadataRefreshService {
|
||||
|
||||
for (MetadataProvider provider : providers) {
|
||||
if (provider != null && metadataMap.containsKey(provider)) {
|
||||
Set<String> extracted = fieldValueExtractor.extract(metadataMap.get(provider));
|
||||
Collection<String> extracted = fieldValueExtractor.extract(metadataMap.get(provider));
|
||||
if (extracted != null) {
|
||||
uniqueCategories.addAll(extracted);
|
||||
}
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ public class AudiobookMetadataExtractor implements FileMetadataExtractor {
|
||||
|
||||
String albumArtist = tag.getFirst(FieldKey.ALBUM_ARTIST);
|
||||
String artist = tag.getFirst(FieldKey.ARTIST);
|
||||
Set<String> authors = new HashSet<>();
|
||||
List<String> authors = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(albumArtist)) {
|
||||
authors.add(albumArtist);
|
||||
} else if (StringUtils.isNotBlank(artist)) {
|
||||
|
||||
+1
-2
@@ -223,8 +223,7 @@ public class CbxMetadataExtractor implements FileMetadataExtractor {
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> authors = new HashSet<>();
|
||||
authors.addAll(splitValues(getTextContent(document, "Writer")));
|
||||
List<String> authors = new ArrayList<>(splitValues(getTextContent(document, "Writer")));
|
||||
if (!authors.isEmpty()) {
|
||||
builder.authors(authors);
|
||||
}
|
||||
|
||||
+4
-4
@@ -243,8 +243,8 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
|
||||
|
||||
Map<String, String> creatorsById = new HashMap<>();
|
||||
Map<String, String> creatorRoleById = new HashMap<>();
|
||||
Map<String, Set<String>> creatorsByRole = new HashMap<>();
|
||||
creatorsByRole.put("aut", new HashSet<>());
|
||||
Map<String, List<String>> creatorsByRole = new HashMap<>();
|
||||
creatorsByRole.put("aut", new ArrayList<>());
|
||||
|
||||
Map<String, String> titlesById = new HashMap<>();
|
||||
Map<String, String> titleTypeById = new HashMap<>();
|
||||
@@ -346,7 +346,7 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
|
||||
case "creator" -> {
|
||||
String role = el.getAttributeNS(OPF_NS, "role");
|
||||
if (StringUtils.isNotBlank(role)) {
|
||||
creatorsByRole.computeIfAbsent(role, k -> new HashSet<>()).add(text);
|
||||
creatorsByRole.computeIfAbsent(role, k -> new ArrayList<>()).add(text);
|
||||
} else {
|
||||
String id = el.getAttribute("id");
|
||||
if (StringUtils.isNotBlank(id)) {
|
||||
@@ -449,7 +449,7 @@ public class EpubMetadataExtractor implements FileMetadataExtractor {
|
||||
String id = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
String role = creatorRoleById.getOrDefault(id, "aut");
|
||||
creatorsByRole.computeIfAbsent(role, k -> new HashSet<>()).add(value);
|
||||
creatorsByRole.computeIfAbsent(role, k -> new ArrayList<>()).add(value);
|
||||
}
|
||||
|
||||
builderMeta.authors(creatorsByRole.get("aut"));
|
||||
|
||||
+4
-2
@@ -16,8 +16,10 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -96,7 +98,7 @@ public class Fb2MetadataExtractor implements FileMetadataExtractor {
|
||||
Document doc = builder.parse(inputStream);
|
||||
|
||||
BookMetadata.BookMetadataBuilder metadataBuilder = BookMetadata.builder();
|
||||
Set<String> authors = new HashSet<>();
|
||||
List<String> authors = new ArrayList<>();
|
||||
Set<String> categories = new HashSet<>();
|
||||
|
||||
// Extract title-info (main metadata section)
|
||||
@@ -128,7 +130,7 @@ public class Fb2MetadataExtractor implements FileMetadataExtractor {
|
||||
}
|
||||
|
||||
private void extractTitleInfo(Element titleInfo, BookMetadata.BookMetadataBuilder builder,
|
||||
Set<String> authors, Set<String> categories) {
|
||||
List<String> authors, Set<String> categories) {
|
||||
// Extract genres (categories)
|
||||
NodeList genres = titleInfo.getElementsByTagNameNS(FB2_NAMESPACE, "genre");
|
||||
for (int i = 0; i < genres.getLength(); i++) {
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ public abstract class MobiBaseMetadataExtractor implements FileMetadataExtractor
|
||||
}
|
||||
|
||||
BookMetadata.BookMetadataBuilder builder = BookMetadata.builder();
|
||||
Set<String> authors = new HashSet<>();
|
||||
List<String> authors = new ArrayList<>();
|
||||
Set<String> categories = new HashSet<>();
|
||||
|
||||
// Extract title
|
||||
|
||||
+8
-8
@@ -87,7 +87,7 @@ public class PdfMetadataExtractor implements FileMetadataExtractor {
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(info.getAuthor())) {
|
||||
Set<String> authors = parseAuthors(info.getAuthor());
|
||||
List<String> authors = parseAuthors(info.getAuthor());
|
||||
if (!authors.isEmpty()) {
|
||||
metadataBuilder.authors(authors);
|
||||
}
|
||||
@@ -271,12 +271,12 @@ public class PdfMetadataExtractor implements FileMetadataExtractor {
|
||||
builder.language(language);
|
||||
}
|
||||
|
||||
Set<String> creators = xpathEvaluateMultiple(xpath, doc, "//dc:creator/rdf:Seq/rdf:li/text()");
|
||||
List<String> creators = xpathEvaluateMultiple(xpath, doc, "//dc:creator/rdf:Seq/rdf:li/text()");
|
||||
if (!creators.isEmpty()) {
|
||||
builder.authors(creators);
|
||||
}
|
||||
|
||||
Set<String> subjects = xpathEvaluateMultiple(xpath, doc, "//dc:subject/rdf:Bag/rdf:li/text()");
|
||||
Set<String> subjects = new HashSet<>(xpathEvaluateMultiple(xpath, doc, "//dc:subject/rdf:Bag/rdf:li/text()"));
|
||||
if (!subjects.isEmpty()) {
|
||||
Set<String> knownNonCategories = new HashSet<>();
|
||||
|
||||
@@ -543,12 +543,12 @@ public class PdfMetadataExtractor implements FileMetadataExtractor {
|
||||
return ids;
|
||||
}
|
||||
|
||||
private Set<String> parseAuthors(String authorString) {
|
||||
if (authorString == null) return Collections.emptySet();
|
||||
private List<String> parseAuthors(String authorString) {
|
||||
if (authorString == null) return Collections.emptyList();
|
||||
return Arrays.stream(COMMA_AMPERSAND_PATTERN.split(authorString))
|
||||
.map(String::trim)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.collect(Collectors.toSet());
|
||||
.toList();
|
||||
}
|
||||
|
||||
private LocalDate convertCalendarToLocalDate(Calendar calendar) {
|
||||
@@ -566,9 +566,9 @@ public class PdfMetadataExtractor implements FileMetadataExtractor {
|
||||
return result == null ? "" : result.trim();
|
||||
}
|
||||
|
||||
private Set<String> xpathEvaluateMultiple(XPath xpath, Document doc, String expression) throws XPathExpressionException {
|
||||
private List<String> xpathEvaluateMultiple(XPath xpath, Document doc, String expression) throws XPathExpressionException {
|
||||
NodeList nodes = (NodeList) xpath.evaluate(expression, doc, XPathConstants.NODESET);
|
||||
Set<String> results = new HashSet<>();
|
||||
List<String> results = new ArrayList<>();
|
||||
if (nodes != null) {
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
String text = nodes.item(i).getNodeValue();
|
||||
|
||||
+6
-6
@@ -288,7 +288,7 @@ public class AmazonBookParser implements BookParser, DetailedMetadataProvider {
|
||||
.provider(MetadataProvider.Amazon)
|
||||
.title(titleInfo.title())
|
||||
.subtitle(titleInfo.subtitle())
|
||||
.authors(new HashSet<>(getAuthors(doc)))
|
||||
.authors(new ArrayList<>(getAuthors(doc)))
|
||||
.categories(new HashSet<>(getBestSellerCategories(doc)))
|
||||
.description(cleanDescriptionHtml(getDescription(doc)))
|
||||
.seriesName(seriesInfo.name())
|
||||
@@ -380,23 +380,23 @@ public class AmazonBookParser implements BookParser, DetailedMetadataProvider {
|
||||
return new TitleInfo(title, subtitle);
|
||||
}
|
||||
|
||||
private Set<String> getAuthors(Document doc) {
|
||||
Set<String> authors = new HashSet<>();
|
||||
private List<String> getAuthors(Document doc) {
|
||||
List<String> authors = new ArrayList<>();
|
||||
try {
|
||||
Element bylineDiv = doc.selectFirst("#bylineInfo_feature_div");
|
||||
if (bylineDiv != null) {
|
||||
authors.addAll(bylineDiv.select(".author a").stream().map(Element::text).collect(Collectors.toSet()));
|
||||
authors.addAll(bylineDiv.select(".author a").stream().map(Element::text).toList());
|
||||
}
|
||||
|
||||
if (authors.isEmpty()) {
|
||||
Element bylineInfo = doc.selectFirst("#bylineInfo");
|
||||
if (bylineInfo != null) {
|
||||
authors.addAll(bylineInfo.select(".author a").stream().map(Element::text).collect(Collectors.toSet()));
|
||||
authors.addAll(bylineInfo.select(".author a").stream().map(Element::text).toList());
|
||||
}
|
||||
}
|
||||
|
||||
if (authors.isEmpty()) {
|
||||
authors.addAll(doc.select(".author a").stream().map(Element::text).collect(Collectors.toSet()));
|
||||
authors.addAll(doc.select(".author a").stream().map(Element::text).toList());
|
||||
}
|
||||
|
||||
if (authors.isEmpty()) {
|
||||
|
||||
@@ -121,7 +121,7 @@ public class AudibleParser implements BookParser, DetailedMetadataProvider {
|
||||
Element container = findProductContainer(link);
|
||||
|
||||
String thumbnailUrl = extractPreviewThumbnail(container, link);
|
||||
Set<String> authors = extractPreviewAuthors(container);
|
||||
List<String> authors = extractPreviewAuthors(container);
|
||||
String narrator = extractPreviewNarrator(container);
|
||||
|
||||
BookMetadata.BookMetadataBuilder builder = BookMetadata.builder()
|
||||
@@ -173,8 +173,8 @@ public class AudibleParser implements BookParser, DetailedMetadataProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Set<String> extractPreviewAuthors(Element container) {
|
||||
Set<String> authors = new LinkedHashSet<>();
|
||||
private List<String> extractPreviewAuthors(Element container) {
|
||||
List<String> authors = new ArrayList<>();
|
||||
if (container == null) return authors;
|
||||
|
||||
for (Element authorLink : container.select("a[href*='/author/']")) {
|
||||
@@ -319,7 +319,7 @@ public class AudibleParser implements BookParser, DetailedMetadataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> authors = extractPersonNames(audiobookNode, "author");
|
||||
List<String> authors = extractPersonNames(audiobookNode, "author");
|
||||
String narrator = extractFirstPersonName(audiobookNode, "readBy");
|
||||
String publisher = getJsonString(audiobookNode, "publisher");
|
||||
String description = getJsonString(audiobookNode, "description");
|
||||
@@ -445,8 +445,8 @@ public class AudibleParser implements BookParser, DetailedMetadataProvider {
|
||||
return fieldNode.asText(null);
|
||||
}
|
||||
|
||||
private Set<String> extractPersonNames(JsonNode node, String field) {
|
||||
Set<String> names = new HashSet<>();
|
||||
private List<String> extractPersonNames(JsonNode node, String field) {
|
||||
List<String> names = new ArrayList<>();
|
||||
if (node == null) return names;
|
||||
|
||||
JsonNode fieldNode = node.path(field);
|
||||
|
||||
+10
-10
@@ -580,7 +580,7 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
||||
}
|
||||
|
||||
String volumeName = comic.getVolume() != null ? comic.getVolume().getName() : null;
|
||||
Set<String> authors = extractAuthors(comic.getPersonCredits());
|
||||
List<String> authors = extractAuthors(comic.getPersonCredits());
|
||||
String formattedTitle = formatTitle(volumeName, comic.getIssueNumber(), comic.getName());
|
||||
String dateToUse = comic.getStoreDate() != null ? comic.getStoreDate() : comic.getCoverDate();
|
||||
|
||||
@@ -622,7 +622,7 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
||||
}
|
||||
|
||||
private BookMetadata buildVolumeMetadata(Comic volume) {
|
||||
Set<String> authors = extractAuthors(volume.getPersonCredits());
|
||||
List<String> authors = extractAuthors(volume.getPersonCredits());
|
||||
|
||||
return BookMetadata.builder()
|
||||
.provider(MetadataProvider.Comicvine)
|
||||
@@ -772,14 +772,14 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
||||
return title;
|
||||
}
|
||||
|
||||
private Set<String> extractAuthors(List<Comic.PersonCredit> personCredits) {
|
||||
private List<String> extractAuthors(List<Comic.PersonCredit> personCredits) {
|
||||
if (personCredits == null || personCredits.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
Set<String> writerRoles = Set.of("writer", "script", "story", "plotter", "plot");
|
||||
|
||||
Set<String> authors = personCredits.stream()
|
||||
List<String> authors = personCredits.stream()
|
||||
.filter(pc -> {
|
||||
if (pc.getRole() == null) return false;
|
||||
String role = pc.getRole().toLowerCase();
|
||||
@@ -787,8 +787,8 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
||||
})
|
||||
.map(Comic.PersonCredit::getName)
|
||||
.filter(name -> name != null && !name.isEmpty())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
.toList();
|
||||
|
||||
if (authors.isEmpty()) {
|
||||
List<String> allRoles = personCredits.stream()
|
||||
.map(pc -> pc.getName() + " (" + pc.getRole() + ")")
|
||||
@@ -799,9 +799,9 @@ public class ComicvineBookParser implements BookParser, DetailedMetadataProvider
|
||||
.filter(pc -> pc.getRole() != null && pc.getRole().toLowerCase().contains("creator"))
|
||||
.map(Comic.PersonCredit::getName)
|
||||
.filter(name -> name != null && !name.isEmpty())
|
||||
.collect(Collectors.toSet());
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
return authors;
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -177,7 +177,7 @@ public class DoubanBookParser implements BookParser {
|
||||
|
||||
// Extract abstract information
|
||||
String abstractText = item.get("abstract").asText();
|
||||
Set<String> authors = Set.of();
|
||||
List<String> authors = List.of();
|
||||
String publisher = null;
|
||||
String pubDate = null;
|
||||
|
||||
@@ -189,12 +189,12 @@ public class DoubanBookParser implements BookParser {
|
||||
authors = Arrays.stream(parts, 0, parts.length - 3)
|
||||
.map(String::trim)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.collect(Collectors.toSet());
|
||||
.toList();
|
||||
publisher = parts[parts.length - 3].trim();
|
||||
pubDate = parts[parts.length - 2].trim();
|
||||
} else if (parts.length >= 2) {
|
||||
// Fallback for shorter abstracts
|
||||
authors = Set.of(parts[1].trim());
|
||||
authors = List.of(parts[1].trim());
|
||||
if (parts.length >= 3) {
|
||||
publisher = parts[2].trim();
|
||||
}
|
||||
@@ -279,7 +279,7 @@ public class DoubanBookParser implements BookParser {
|
||||
.provider(MetadataProvider.Douban)
|
||||
.title(getTitle(doc))
|
||||
.subtitle(getSubtitle(doc))
|
||||
.authors(new HashSet<>(getAuthors(doc)))
|
||||
.authors(new ArrayList<>(getAuthors(doc)))
|
||||
.categories(new HashSet<>(getCategories(doc)))
|
||||
.description(cleanDescriptionHtml(getDescription(doc)))
|
||||
.seriesName(getSeriesName(doc))
|
||||
@@ -359,8 +359,8 @@ public class DoubanBookParser implements BookParser {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Set<String> getAuthors(Document doc) {
|
||||
Set<String> authors = new HashSet<>();
|
||||
private List<String> getAuthors(Document doc) {
|
||||
List<String> authors = new ArrayList<>();
|
||||
try {
|
||||
Element infoElement = doc.selectFirst("#info");
|
||||
if (infoElement != null) {
|
||||
@@ -386,7 +386,7 @@ public class DoubanBookParser implements BookParser {
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to parse authors: {}", e.getMessage());
|
||||
}
|
||||
return authors.isEmpty() ? Set.of() : authors;
|
||||
return authors.isEmpty() ? List.of() : authors;
|
||||
}
|
||||
|
||||
private String getDescription(Document doc) {
|
||||
|
||||
+4
-4
@@ -194,7 +194,7 @@ public class GoodReadsParser implements BookParser, DetailedMetadataProvider {
|
||||
String contributorKey = findKeyByPrefix(keySet, "Contributor:kca");
|
||||
String contributorName = getJsonStringField(apolloStateJson, contributorKey, "name");
|
||||
if (contributorName != null) {
|
||||
builder.authors(Set.of(contributorName));
|
||||
builder.authors(List.of(contributorName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -479,7 +479,7 @@ public class GoodReadsParser implements BookParser, DetailedMetadataProvider {
|
||||
String queryAuthor = request.getAuthor();
|
||||
|
||||
for (Element previewBook : previewBooks) {
|
||||
Set<String> authors = extractAuthorsPreview(previewBook);
|
||||
List<String> authors = extractAuthorsPreview(previewBook);
|
||||
|
||||
if (queryAuthor != null && !queryAuthor.isBlank()) {
|
||||
List<String> queryAuthorTokens = List.of(WHITESPACE_PATTERN.split(queryAuthor.toLowerCase()));
|
||||
@@ -549,8 +549,8 @@ public class GoodReadsParser implements BookParser, DetailedMetadataProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Set<String> extractAuthorsPreview(Element book) {
|
||||
Set<String> authors = new HashSet<>();
|
||||
private List<String> extractAuthorsPreview(Element book) {
|
||||
List<String> authors = new ArrayList<>();
|
||||
try {
|
||||
Elements authorsElement = book.select("a.authorName");
|
||||
for (Element authorElement : authorsElement) {
|
||||
|
||||
@@ -392,15 +392,15 @@ public class GoogleParser implements BookParser {
|
||||
return WHITESPACE_PATTERN.matcher(title.trim()).replaceAll(" ");
|
||||
}
|
||||
|
||||
private Set<String> cleanAuthors(Set<String> authors) {
|
||||
private List<String> cleanAuthors(List<String> authors) {
|
||||
if (authors == null || authors.isEmpty()) {
|
||||
return Set.of();
|
||||
return List.of();
|
||||
}
|
||||
return authors.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(author -> !author.isBlank())
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Set<String> cleanCategories(Set<String> categories) {
|
||||
|
||||
+2
-2
@@ -178,7 +178,7 @@ public class HardcoverParser implements BookParser {
|
||||
metadata.setDescription(doc.getDescription());
|
||||
|
||||
if (doc.getAuthorNames() != null) {
|
||||
metadata.setAuthors(Set.copyOf(doc.getAuthorNames()));
|
||||
metadata.setAuthors(List.copyOf(doc.getAuthorNames()));
|
||||
}
|
||||
|
||||
mapSeriesInfo(doc, metadata);
|
||||
@@ -226,7 +226,7 @@ public class HardcoverParser implements BookParser {
|
||||
.filter(Objects::nonNull)
|
||||
.map(GraphQLResponse.Author::getName)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet()));
|
||||
.toList());
|
||||
}
|
||||
|
||||
if (book.getFeaturedBookSeries() != null && book.getFeaturedBookSeries().getSeries() != null) {
|
||||
|
||||
+1
-1
@@ -399,7 +399,7 @@ public class LubimyCzytacParser implements BookParser {
|
||||
// Author(s) - can be single Person or array of Person objects
|
||||
if (root.has("author")) {
|
||||
try {
|
||||
Set<String> authors = new HashSet<>();
|
||||
List<String> authors = new ArrayList<>();
|
||||
JsonNode authorNode = root.get("author");
|
||||
|
||||
if (authorNode.isArray()) {
|
||||
|
||||
@@ -225,11 +225,11 @@ public class RanobeDbParser implements BookParser {
|
||||
.findFirst()
|
||||
.orElse(-1);
|
||||
|
||||
HashSet<String> authors = book.getEditions().stream()
|
||||
List<String> authors = book.getEditions().stream()
|
||||
.flatMap(edition -> edition.getStaff().stream())
|
||||
.filter(staff -> RanobedbBookResponse.RoleType.AUTHOR.equals(staff.getRoleType()))
|
||||
.map(staff -> staff.getRomaji() != null ? staff.getRomaji() : staff.getName())
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
.toList();
|
||||
|
||||
HashSet<String> genres = book.getSeries() != null ? book.getSeries().getTags().stream()
|
||||
.filter(tag -> RanobedbBookResponse.TagType.GENRE.equals(tag.getTtype()))
|
||||
|
||||
+3
-2
@@ -10,6 +10,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -145,11 +146,11 @@ public class SidecarMetadataMapper {
|
||||
return baseName + ".cover.jpg";
|
||||
}
|
||||
|
||||
private Set<String> extractNames(Set<AuthorEntity> entities) {
|
||||
private List<String> extractNames(List<AuthorEntity> entities) {
|
||||
if (entities == null) return null;
|
||||
return entities.stream()
|
||||
.map(AuthorEntity::getName)
|
||||
.collect(Collectors.toSet());
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Set<String> extractCategoryNames(Set<CategoryEntity> entities) {
|
||||
|
||||
+2
-2
@@ -970,11 +970,11 @@ public class EpubMetadataWriter implements MetadataWriter {
|
||||
}
|
||||
|
||||
if (metadata.getAgeRating() != null) {
|
||||
metadataElement.appendChild(createBookloreMetaElement(doc, "age_rating", String.valueOf(metadata.getAgeRating())));
|
||||
metadataElement.appendChild(createBookloreMetaElement(doc, "age_rating", String.valueOf(metadata.getAgeRating()), epub3));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(metadata.getContentRating())) {
|
||||
metadataElement.appendChild(createBookloreMetaElement(doc, "content_rating", metadata.getContentRating()));
|
||||
metadataElement.appendChild(createBookloreMetaElement(doc, "content_rating", metadata.getContentRating(), epub3));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ public class BookSimilarityService {
|
||||
return round(score, 5);
|
||||
}
|
||||
|
||||
private Set<String> extractNames(Set<?> entities) {
|
||||
private Set<String> extractNames(Collection<?> entities) {
|
||||
if (entities == null) return Collections.emptySet();
|
||||
Set<String> names = new HashSet<>();
|
||||
for (Object obj : entities) {
|
||||
|
||||
@@ -52,13 +52,26 @@ public class MetadataChangeDetector {
|
||||
|
||||
private record CollectionFieldDescriptor(
|
||||
String name,
|
||||
Function<BookMetadata, Set<String>> dtoValueGetter,
|
||||
Function<BookMetadataEntity, Set<?>> entityValueGetter,
|
||||
Function<BookMetadata, ? extends Collection<String>> dtoValueGetter,
|
||||
Function<BookMetadataEntity, ? extends Collection<?>> entityValueGetter,
|
||||
Function<BookMetadata, Boolean> dtoLockGetter,
|
||||
Function<BookMetadataEntity, Boolean> entityLockGetter,
|
||||
Predicate<MetadataClearFlags> clearFlagGetter,
|
||||
boolean includedInFileWrite
|
||||
boolean includedInFileWrite,
|
||||
boolean orderSensitive
|
||||
) {
|
||||
CollectionFieldDescriptor(
|
||||
String name,
|
||||
Function<BookMetadata, ? extends Collection<String>> dtoValueGetter,
|
||||
Function<BookMetadataEntity, ? extends Collection<?>> entityValueGetter,
|
||||
Function<BookMetadata, Boolean> dtoLockGetter,
|
||||
Function<BookMetadataEntity, Boolean> entityLockGetter,
|
||||
Predicate<MetadataClearFlags> clearFlagGetter,
|
||||
boolean includedInFileWrite
|
||||
) {
|
||||
this(name, dtoValueGetter, entityValueGetter, dtoLockGetter, entityLockGetter, clearFlagGetter, includedInFileWrite, false);
|
||||
}
|
||||
|
||||
boolean isUnlocked(BookMetadataEntity entity) {
|
||||
return !isTrue(entityLockGetter.apply(entity));
|
||||
}
|
||||
@@ -67,11 +80,16 @@ public class MetadataChangeDetector {
|
||||
return clearFlagGetter.test(flags);
|
||||
}
|
||||
|
||||
Set<String> getNewValue(BookMetadata dto) {
|
||||
return dtoValueGetter.apply(dto);
|
||||
Object getNewValue(BookMetadata dto) {
|
||||
Collection<String> values = dtoValueGetter.apply(dto);
|
||||
if (values == null) return null;
|
||||
return orderSensitive ? new ArrayList<>(values) : new HashSet<>(values);
|
||||
}
|
||||
|
||||
Set<String> getOldValue(BookMetadataEntity entity) {
|
||||
Object getOldValue(BookMetadataEntity entity) {
|
||||
if (orderSensitive) {
|
||||
return toNameList(entityValueGetter.apply(entity));
|
||||
}
|
||||
return toNameSet(entityValueGetter.apply(entity));
|
||||
}
|
||||
|
||||
@@ -231,7 +249,7 @@ public class MetadataChangeDetector {
|
||||
new CollectionFieldDescriptor("authors",
|
||||
BookMetadata::getAuthors, BookMetadataEntity::getAuthors,
|
||||
BookMetadata::getAuthorsLocked, BookMetadataEntity::getAuthorsLocked,
|
||||
MetadataClearFlags::isAuthors, true),
|
||||
MetadataClearFlags::isAuthors, true, true),
|
||||
new CollectionFieldDescriptor("categories",
|
||||
BookMetadata::getCategories, BookMetadataEntity::getCategories,
|
||||
BookMetadata::getCategoriesLocked, BookMetadataEntity::getCategoriesLocked,
|
||||
@@ -377,7 +395,22 @@ public class MetadataChangeDetector {
|
||||
return !Objects.equals(normNew, normOld);
|
||||
}
|
||||
|
||||
private static Set<String> toNameSet(Set<?> entities) {
|
||||
private static List<String> toNameList(Collection<?> entities) {
|
||||
if (entities == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return entities.stream()
|
||||
.map(e -> switch (e) {
|
||||
case AuthorEntity author -> author.getName();
|
||||
case CategoryEntity category -> category.getName();
|
||||
case MoodEntity mood -> mood.getName();
|
||||
case TagEntity tag -> tag.getName();
|
||||
default -> e.toString();
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
|
||||
private static Set<String> toNameSet(Collection<?> entities) {
|
||||
if (entities == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
ALTER TABLE book_metadata_author_mapping
|
||||
ADD COLUMN IF NOT EXISTS sort_order INT NOT NULL DEFAULT 0;
|
||||
|
||||
-- Assign unique sort_order per book for existing rows
|
||||
SET @prev_book := 0;
|
||||
SET @pos := 0;
|
||||
|
||||
UPDATE book_metadata_author_mapping
|
||||
SET sort_order = (@pos := IF(@prev_book = book_id, @pos + 1, 0)),
|
||||
book_id = (@prev_book := book_id)
|
||||
ORDER BY book_id, author_id;
|
||||
|
||||
-- Change PK from (book_id, author_id) to (book_id, sort_order)
|
||||
ALTER TABLE book_metadata_author_mapping
|
||||
DROP PRIMARY KEY,
|
||||
ADD PRIMARY KEY (book_id, sort_order);
|
||||
|
||||
-- Keep an index on author_id for reverse lookups
|
||||
CREATE INDEX IF NOT EXISTS idx_author_mapping_author_id ON book_metadata_author_mapping (book_id, author_id);
|
||||
Reference in New Issue
Block a user