Add ability to have decimals in "Book Number" metadata field
This commit is contained in:
committed by
Aditya Chandel
parent
af1cccbaab
commit
7d5533c891
@@ -22,7 +22,7 @@ public class BookMetadata {
|
|||||||
private LocalDate publishedDate;
|
private LocalDate publishedDate;
|
||||||
private String description;
|
private String description;
|
||||||
private String seriesName;
|
private String seriesName;
|
||||||
private Integer seriesNumber;
|
private Float seriesNumber;
|
||||||
private Integer seriesTotal;
|
private Integer seriesTotal;
|
||||||
private String isbn13;
|
private String isbn13;
|
||||||
private String isbn10;
|
private String isbn10;
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ public class BookMetadataEntity {
|
|||||||
private String seriesName;
|
private String seriesName;
|
||||||
|
|
||||||
@Column(name = "series_number")
|
@Column(name = "series_number")
|
||||||
private Integer seriesNumber;
|
private Float seriesNumber;
|
||||||
|
|
||||||
@Column(name = "series_total")
|
@Column(name = "series_total")
|
||||||
private Integer seriesTotal;
|
private Integer seriesTotal;
|
||||||
|
|||||||
+1
-1
@@ -172,7 +172,7 @@ public class EpubProcessor implements FileProcessor {
|
|||||||
if (seriesIndex != null && !seriesIndex.isEmpty()) {
|
if (seriesIndex != null && !seriesIndex.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
double indexValue = Double.parseDouble(seriesIndex);
|
double indexValue = Double.parseDouble(seriesIndex);
|
||||||
bookMetadata.setSeriesNumber((int) indexValue);
|
bookMetadata.setSeriesNumber((float) indexValue);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
log.warn("Unable to parse series number: {}", seriesIndex);
|
log.warn("Unable to parse series number: {}", seriesIndex);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -306,14 +306,14 @@ public class AmazonBookParser implements BookParser {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer getSeriesNumber(Document doc) {
|
private Float getSeriesNumber(Document doc) {
|
||||||
try {
|
try {
|
||||||
Element bookDetailsLabel = doc.selectFirst("#rpi-attribute-book_details-series .rpi-attribute-label span");
|
Element bookDetailsLabel = doc.selectFirst("#rpi-attribute-book_details-series .rpi-attribute-label span");
|
||||||
if (bookDetailsLabel != null) {
|
if (bookDetailsLabel != null) {
|
||||||
String bookAndTotal = bookDetailsLabel.text();
|
String bookAndTotal = bookDetailsLabel.text();
|
||||||
if (bookAndTotal.matches("Book \\d+ of \\d+")) {
|
if (bookAndTotal.matches("Book \\d+(\\.\\d+)? of \\d+")) {
|
||||||
String[] parts = bookAndTotal.split(" ");
|
String[] parts = bookAndTotal.split(" ");
|
||||||
return Integer.parseInt(parts[1]);
|
return Float.parseFloat(parts[1]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("Error fetching series number: Element not found.");
|
log.debug("Error fetching series number: Element not found.");
|
||||||
|
|||||||
+10
-1
@@ -140,7 +140,7 @@ public class GoodReadsParser implements BookParser {
|
|||||||
if (bookSeriesJson != null && bookSeriesJson.length() > 0) {
|
if (bookSeriesJson != null && bookSeriesJson.length() > 0) {
|
||||||
JSONObject firstElement = bookSeriesJson.optJSONObject(0);
|
JSONObject firstElement = bookSeriesJson.optJSONObject(0);
|
||||||
if (firstElement != null) {
|
if (firstElement != null) {
|
||||||
builder.seriesNumber(parseInteger(firstElement.optString("userPosition")));
|
builder.seriesNumber(parseFloat(firstElement.optString("userPosition")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,6 +176,15 @@ public class GoodReadsParser implements BookParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Float parseFloat(String value) {
|
||||||
|
try {
|
||||||
|
return value != null ? Float.parseFloat(value) : null;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
log.error("Error parsing double: {}, Error: {}", value, e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Integer parseInteger(String value) {
|
private Integer parseInteger(String value) {
|
||||||
try {
|
try {
|
||||||
return value != null ? Integer.parseInt(value) : null;
|
return value != null ? Integer.parseInt(value) : null;
|
||||||
|
|||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE book_metadata
|
||||||
|
MODIFY COLUMN series_number FLOAT;
|
||||||
Reference in New Issue
Block a user