Asin metadata support (#346)
--------- Co-authored-by: Aditya Chandel <8075870+adityachandelgit@users.noreply.github.com>
This commit is contained in:
committed by
aditya.chandel
co-authored by
Aditya Chandel
parent
3921d42014
commit
a7b665e0ba
@@ -26,6 +26,7 @@ public class BookMetadata {
|
||||
private Integer seriesTotal;
|
||||
private String isbn13;
|
||||
private String isbn10;
|
||||
private String asin;
|
||||
private Integer pageCount;
|
||||
private String language;
|
||||
private Double rating;
|
||||
@@ -54,6 +55,7 @@ public class BookMetadata {
|
||||
private Boolean seriesTotalLocked;
|
||||
private Boolean isbn13Locked;
|
||||
private Boolean isbn10Locked;
|
||||
private Boolean asinLocked;
|
||||
private Boolean pageCountLocked;
|
||||
private Boolean languageLocked;
|
||||
private Boolean ratingLocked;
|
||||
|
||||
+1
@@ -14,4 +14,5 @@ public class FetchMetadataRequest {
|
||||
private String isbn;
|
||||
private String title;
|
||||
private String author;
|
||||
private String asin;
|
||||
}
|
||||
|
||||
+9
@@ -51,6 +51,9 @@ public class BookMetadataEntity {
|
||||
@Column(name = "isbn_10", length = 10)
|
||||
private String isbn10;
|
||||
|
||||
@Column(name = "asin", length = 10)
|
||||
private String asin;
|
||||
|
||||
@Column(name = "page_count")
|
||||
private Integer pageCount;
|
||||
|
||||
@@ -104,6 +107,9 @@ public class BookMetadataEntity {
|
||||
@Column(name = "isbn_10_locked")
|
||||
private Boolean isbn10Locked = Boolean.FALSE;
|
||||
|
||||
@Column(name = "asin_locked")
|
||||
private Boolean asinLocked = Boolean.FALSE;
|
||||
|
||||
@Column(name = "page_count_locked")
|
||||
private Boolean pageCountLocked = Boolean.FALSE;
|
||||
|
||||
@@ -181,6 +187,7 @@ public class BookMetadataEntity {
|
||||
this.descriptionLocked = lock;
|
||||
this.isbn13Locked = lock;
|
||||
this.isbn10Locked = lock;
|
||||
this.asinLocked = lock;
|
||||
this.pageCountLocked = lock;
|
||||
this.thumbnailLocked = lock;
|
||||
this.languageLocked = lock;
|
||||
@@ -206,6 +213,7 @@ public class BookMetadataEntity {
|
||||
|| Boolean.TRUE.equals(this.descriptionLocked)
|
||||
|| Boolean.TRUE.equals(this.isbn13Locked)
|
||||
|| Boolean.TRUE.equals(this.isbn10Locked)
|
||||
|| Boolean.TRUE.equals(this.asinLocked)
|
||||
|| Boolean.TRUE.equals(this.pageCountLocked)
|
||||
|| Boolean.TRUE.equals(this.thumbnailLocked)
|
||||
|| Boolean.TRUE.equals(this.languageLocked)
|
||||
@@ -231,6 +239,7 @@ public class BookMetadataEntity {
|
||||
&& Boolean.TRUE.equals(this.descriptionLocked)
|
||||
&& Boolean.TRUE.equals(this.isbn13Locked)
|
||||
&& Boolean.TRUE.equals(this.isbn10Locked)
|
||||
&& Boolean.TRUE.equals(this.asinLocked)
|
||||
&& Boolean.TRUE.equals(this.pageCountLocked)
|
||||
&& Boolean.TRUE.equals(this.thumbnailLocked)
|
||||
&& Boolean.TRUE.equals(this.languageLocked)
|
||||
|
||||
@@ -200,6 +200,7 @@ public class BookMetadataService {
|
||||
metadataCombined.setPublishedDate(metadata.getPublishedDate() != null ? metadata.getPublishedDate() : metadataCombined.getPublishedDate());
|
||||
metadataCombined.setIsbn10(metadata.getIsbn10() != null ? metadata.getIsbn10() : metadataCombined.getIsbn10());
|
||||
metadataCombined.setIsbn13(metadata.getIsbn13() != null ? metadata.getIsbn13() : metadataCombined.getIsbn13());
|
||||
metadataCombined.setAsin(metadata.getAsin() != null ? metadata.getAsin() : metadataCombined.getAsin());
|
||||
metadataCombined.setPageCount(metadata.getPageCount() != null ? metadata.getPageCount() : metadataCombined.getPageCount());
|
||||
metadataCombined.setLanguage(metadata.getLanguage() != null ? metadata.getLanguage() : metadataCombined.getLanguage());
|
||||
metadataCombined.setRating(metadata.getRating() != null ? metadata.getRating() : metadataCombined.getRating());
|
||||
@@ -334,6 +335,7 @@ public class BookMetadataService {
|
||||
private FetchMetadataRequest buildFetchMetadataRequestFromBook(Book book) {
|
||||
return FetchMetadataRequest.builder()
|
||||
.isbn(book.getMetadata().getIsbn10())
|
||||
.asin(book.getMetadata().getAsin())
|
||||
.author(String.join(", ", book.getMetadata().getAuthors()))
|
||||
.title(book.getMetadata().getTitle())
|
||||
.bookId(book.getId())
|
||||
@@ -375,6 +377,9 @@ public class BookMetadataService {
|
||||
case "isbn13":
|
||||
existingMetadata.setIsbn13Locked(isLocked);
|
||||
break;
|
||||
case "asin":
|
||||
existingMetadata.setAsinLocked(isLocked);
|
||||
break;
|
||||
case "description":
|
||||
existingMetadata.setDescriptionLocked(isLocked);
|
||||
break;
|
||||
|
||||
+6
-1
@@ -71,7 +71,9 @@ public class BookMetadataUpdater {
|
||||
if ((metadata.getIsbn13Locked() == null || !metadata.getIsbn13Locked()) && newMetadata.getIsbn13() != null) {
|
||||
metadata.setIsbn13(newMetadata.getIsbn13().isBlank() ? null : newMetadata.getIsbn13());
|
||||
}
|
||||
|
||||
if ((metadata.getAsinLocked() == null || !metadata.getAsinLocked()) && newMetadata.getAsin() != null) {
|
||||
metadata.setAsin(newMetadata.getAsin().isBlank() ? null : newMetadata.getAsin());
|
||||
}
|
||||
if ((metadata.getDescriptionLocked() == null || !metadata.getDescriptionLocked()) && newMetadata.getDescription() != null) {
|
||||
metadata.setDescription(newMetadata.getDescription().isBlank() ? null : newMetadata.getDescription());
|
||||
}
|
||||
@@ -216,6 +218,9 @@ public class BookMetadataUpdater {
|
||||
if (newMetadata.getIsbn10Locked() != null) {
|
||||
metadata.setIsbn10Locked(newMetadata.getIsbn10Locked());
|
||||
}
|
||||
if (newMetadata.getAsinLocked() != null) {
|
||||
metadata.setAsinLocked(newMetadata.getAsinLocked());
|
||||
}
|
||||
if (newMetadata.getPageCountLocked() != null) {
|
||||
metadata.setPageCountLocked(newMetadata.getPageCountLocked());
|
||||
}
|
||||
|
||||
+27
-2
@@ -11,6 +11,7 @@ import java.time.LocalDate;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -153,12 +154,36 @@ public class EpubProcessor implements FileProcessor {
|
||||
|
||||
List<String> identifiers = epubMetadata.getIdentifiers().stream()
|
||||
.map(Identifier::getValue)
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.map(id -> id.contains(":") ? id.substring(id.indexOf(":") + 1) : id) // strip prefix
|
||||
.map(id -> id.replace("-", "")) // remove dashes
|
||||
.toList();
|
||||
|
||||
|
||||
if (!identifiers.isEmpty()) {
|
||||
String isbn13 = identifiers.stream().filter(id -> id.length() == 13).findFirst().orElse(null);
|
||||
String isbn10 = identifiers.stream().filter(id -> id.length() == 10).findFirst().orElse(null);
|
||||
// Checking for ISBN 13 (strict 13-digit numeric)
|
||||
String isbn13 = identifiers.stream()
|
||||
.filter(id -> id.length() == 13 && id.matches("\\d{13}"))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
// Checking for ISBN 10 (strict 10-digit format or ends in X)
|
||||
String isbn10 = identifiers.stream()
|
||||
.filter(id -> id.length() == 10 && id.matches("\\d{9}[\\dXx]"))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
// Checking for ASIN (alphanumeric 10 chars, must not be ISBN-10)
|
||||
String asin = identifiers.stream()
|
||||
.filter(id -> id.length() == 10 && id.matches("^[A-Z0-9]{10}$"))
|
||||
.filter(id -> !id.equalsIgnoreCase(isbn10))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
bookMetadata.setIsbn13(truncate(isbn13, 64));
|
||||
bookMetadata.setIsbn10(truncate(isbn10, 64));
|
||||
bookMetadata.setAsin(truncate(asin, 20));
|
||||
}
|
||||
|
||||
bookMetadata.setLanguage(truncate(
|
||||
|
||||
+1
@@ -126,6 +126,7 @@ public class AmazonBookParser implements BookParser {
|
||||
.seriesTotal(getSeriesTotal(doc))
|
||||
.isbn13(getIsbn13(doc))
|
||||
.isbn10(getIsbn10(doc))
|
||||
.asin(amazonBookId)
|
||||
.publisher(getPublisher(doc))
|
||||
.publishedDate(getPublicationDate(doc))
|
||||
.language(getLanguage(doc))
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE book_metadata ADD COLUMN asin VARCHAR(20);
|
||||
ALTER TABLE book_metadata ADD COLUMN asin_locked BOOLEAN DEFAULT FALSE;
|
||||
Reference in New Issue
Block a user