Widen length of metadata fields and add checks in the code
This commit is contained in:
committed by
Aditya Chandel
parent
b7becc50d9
commit
1d91770656
+14
-7
@@ -122,14 +122,14 @@ public class EpubProcessor implements FileProcessor {
|
|||||||
BookMetadataEntity bookMetadata = bookEntity.getMetadata();
|
BookMetadataEntity bookMetadata = bookEntity.getMetadata();
|
||||||
Metadata epubMetadata = book.getMetadata();
|
Metadata epubMetadata = book.getMetadata();
|
||||||
if (epubMetadata != null) {
|
if (epubMetadata != null) {
|
||||||
bookMetadata.setTitle(epubMetadata.getFirstTitle());
|
bookMetadata.setTitle(truncate(epubMetadata.getFirstTitle(), 1000));
|
||||||
|
|
||||||
if (epubMetadata.getDescriptions() != null && !epubMetadata.getDescriptions().isEmpty()) {
|
if (epubMetadata.getDescriptions() != null && !epubMetadata.getDescriptions().isEmpty()) {
|
||||||
bookMetadata.setDescription(epubMetadata.getDescriptions().getFirst());
|
bookMetadata.setDescription(truncate(epubMetadata.getDescriptions().getFirst(), 2000));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (epubMetadata.getPublishers() != null && !epubMetadata.getPublishers().isEmpty()) {
|
if (epubMetadata.getPublishers() != null && !epubMetadata.getPublishers().isEmpty()) {
|
||||||
bookMetadata.setPublisher(epubMetadata.getPublishers().getFirst());
|
bookMetadata.setPublisher(truncate(epubMetadata.getPublishers().getFirst(), 2000));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> identifiers = epubMetadata.getIdentifiers().stream()
|
List<String> identifiers = epubMetadata.getIdentifiers().stream()
|
||||||
@@ -138,11 +138,13 @@ public class EpubProcessor implements FileProcessor {
|
|||||||
if (!identifiers.isEmpty()) {
|
if (!identifiers.isEmpty()) {
|
||||||
String isbn13 = identifiers.stream().filter(id -> id.length() == 13).findFirst().orElse(null);
|
String isbn13 = identifiers.stream().filter(id -> id.length() == 13).findFirst().orElse(null);
|
||||||
String isbn10 = identifiers.stream().filter(id -> id.length() == 10).findFirst().orElse(null);
|
String isbn10 = identifiers.stream().filter(id -> id.length() == 10).findFirst().orElse(null);
|
||||||
bookMetadata.setIsbn13(isbn13);
|
bookMetadata.setIsbn13(truncate(isbn13, 64));
|
||||||
bookMetadata.setIsbn10(isbn10);
|
bookMetadata.setIsbn10(truncate(isbn10, 64));
|
||||||
}
|
}
|
||||||
|
|
||||||
bookMetadata.setLanguage(epubMetadata.getLanguage() == null || epubMetadata.getLanguage().equalsIgnoreCase("UND") ? "en" : epubMetadata.getLanguage());
|
bookMetadata.setLanguage(truncate(
|
||||||
|
epubMetadata.getLanguage() == null || epubMetadata.getLanguage().equalsIgnoreCase("UND") ? "en" : epubMetadata.getLanguage(), 1000
|
||||||
|
));
|
||||||
|
|
||||||
if (epubMetadata.getDates() != null && !epubMetadata.getDates().isEmpty()) {
|
if (epubMetadata.getDates() != null && !epubMetadata.getDates().isEmpty()) {
|
||||||
epubMetadata.getDates().stream()
|
epubMetadata.getDates().stream()
|
||||||
@@ -163,7 +165,7 @@ public class EpubProcessor implements FileProcessor {
|
|||||||
|
|
||||||
String seriesName = epubMetadata.getMetaAttribute("calibre:series");
|
String seriesName = epubMetadata.getMetaAttribute("calibre:series");
|
||||||
if (seriesName != null && !seriesName.isEmpty()) {
|
if (seriesName != null && !seriesName.isEmpty()) {
|
||||||
bookMetadata.setSeriesName(seriesName);
|
bookMetadata.setSeriesName(truncate(seriesName, 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
String seriesIndex = epubMetadata.getMetaAttribute("calibre:series_index");
|
String seriesIndex = epubMetadata.getMetaAttribute("calibre:series_index");
|
||||||
@@ -206,4 +208,9 @@ public class EpubProcessor implements FileProcessor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String truncate(String input, int maxLength) {
|
||||||
|
if (input == null) return null;
|
||||||
|
return input.length() <= maxLength ? input : input.substring(0, maxLength);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+6
-1
@@ -86,7 +86,7 @@ public class PdfProcessor implements FileProcessor {
|
|||||||
log.warn("No document information found");
|
log.warn("No document information found");
|
||||||
} else {
|
} else {
|
||||||
if (pdf.getDocumentInformation().getTitle() != null) {
|
if (pdf.getDocumentInformation().getTitle() != null) {
|
||||||
bookEntity.getMetadata().setTitle(pdf.getDocumentInformation().getTitle());
|
bookEntity.getMetadata().setTitle(truncate(pdf.getDocumentInformation().getTitle(), 1000));
|
||||||
}
|
}
|
||||||
if (pdf.getDocumentInformation().getAuthor() != null) {
|
if (pdf.getDocumentInformation().getAuthor() != null) {
|
||||||
Set<String> authors = getAuthors(pdf);
|
Set<String> authors = getAuthors(pdf);
|
||||||
@@ -115,4 +115,9 @@ public class PdfProcessor implements FileProcessor {
|
|||||||
BufferedImage coverImage = new PDFRenderer(document).renderImageWithDPI(0, 300, ImageType.RGB);
|
BufferedImage coverImage = new PDFRenderer(document).renderImageWithDPI(0, 300, ImageType.RGB);
|
||||||
return fileProcessingUtils.saveCoverImage(coverImage, bookId);
|
return fileProcessingUtils.saveCoverImage(coverImage, bookId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String truncate(String input, int maxLength) {
|
||||||
|
if (input == null) return null;
|
||||||
|
return input.length() <= maxLength ? input : input.substring(0, maxLength);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
ALTER TABLE book_metadata MODIFY COLUMN title VARCHAR(1000);
|
||||||
|
ALTER TABLE book_metadata MODIFY COLUMN subtitle VARCHAR(1000);
|
||||||
|
ALTER TABLE book_metadata MODIFY COLUMN publisher VARCHAR(1000);
|
||||||
|
ALTER TABLE book_metadata MODIFY COLUMN isbn_10 VARCHAR(64);
|
||||||
|
ALTER TABLE book_metadata MODIFY COLUMN isbn_13 VARCHAR(64);
|
||||||
|
ALTER TABLE book_metadata MODIFY COLUMN thumbnail VARCHAR(2000);
|
||||||
|
ALTER TABLE book_metadata MODIFY COLUMN series_name VARCHAR(1000);
|
||||||
|
ALTER TABLE book_metadata MODIFY COLUMN cover VARCHAR(2000);
|
||||||
Reference in New Issue
Block a user