Add option for merging categories
This commit is contained in:
+1
@@ -16,6 +16,7 @@ public class MetadataRefreshOptions {
|
||||
@NotNull(message = "Default Provider cannot be null")
|
||||
private MetadataProvider defaultProvider;
|
||||
private boolean refreshCovers;
|
||||
private boolean mergeCategories;
|
||||
private FieldOptions fieldOptions;
|
||||
|
||||
@Getter
|
||||
|
||||
+6
-6
@@ -103,7 +103,7 @@ public class BookMetadataService {
|
||||
Thread.sleep(ThreadLocalRandom.current().nextLong(500, 1500));
|
||||
}
|
||||
FetchedBookMetadata fetchedBookMetadata = getRawOrCombinedMetadata(request, metadataMap);
|
||||
updateBookMetadata(bookEntity, fetchedBookMetadata, shouldRefreshCovers(request));
|
||||
updateBookMetadata(bookEntity, fetchedBookMetadata, request.getRefreshOptions().isRefreshCovers());
|
||||
} catch (Exception e) {
|
||||
log.error("Error while updating book metadata, book: {}", bookEntity.getFileName(), e);
|
||||
}
|
||||
@@ -163,15 +163,15 @@ public class BookMetadataService {
|
||||
nonDefaultProviders.forEach(provider -> setUnspecificMetadata(metadataMap, combinedMetadata, provider));
|
||||
setUnspecificMetadata(metadataMap, combinedMetadata, defaultProvider);
|
||||
|
||||
if(request.getRefreshOptions().isMergeCategories()) {
|
||||
combinedMetadata.getCategories().clear();
|
||||
metadataMap.forEach((k, v) -> combinedMetadata.getCategories().addAll(v.getCategories()));
|
||||
}
|
||||
|
||||
return combinedMetadata;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
protected boolean shouldRefreshCovers(MetadataRefreshRequest request) {
|
||||
return request.getRefreshOptions().isRefreshCovers();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
protected FetchedBookMetadata setSpecificMetadata(MetadataRefreshRequest request, Map<MetadataProvider, FetchedBookMetadata> metadataMap) {
|
||||
FetchedBookMetadata metadataCombined = FetchedBookMetadata.builder().build();
|
||||
|
||||
@@ -15,7 +15,7 @@ spring:
|
||||
name: booklore-api
|
||||
datasource:
|
||||
driver-class-name: org.h2.Driver
|
||||
url: jdbc:h2:~/my-library-temp/config/local/db/booklore
|
||||
url: 'jdbc:h2:~/my-library-temp/config/local/db/booklore;AUTO_SERVER=TRUE'
|
||||
username: sa
|
||||
password: password
|
||||
jpa:
|
||||
|
||||
@@ -19,40 +19,40 @@ VALUES
|
||||
('reader_setting', 'pdf', 'individual'),
|
||||
('reader_setting', 'epub', 'individual');
|
||||
|
||||
-- Insert JSON data into app_settings
|
||||
INSERT INTO app_settings (category, name, val)
|
||||
VALUES
|
||||
(
|
||||
'quick_book_match',
|
||||
'all_books',
|
||||
'{
|
||||
"defaultProvider": "Amazon",
|
||||
"refreshCovers": false,
|
||||
"defaultProvider": "Google",
|
||||
"refreshCovers": true,
|
||||
"mergeCategories": true,
|
||||
"fieldOptions": {
|
||||
"title": {
|
||||
"default": "Amazon",
|
||||
"p2": null,
|
||||
"p1": null
|
||||
"p2": "GoodReads",
|
||||
"p1": "Amazon",
|
||||
"default": "Google"
|
||||
},
|
||||
"description": {
|
||||
"default": "Amazon",
|
||||
"p2": null,
|
||||
"p1": null
|
||||
"p2": "GoodReads",
|
||||
"p1": "Amazon",
|
||||
"default": "Google"
|
||||
},
|
||||
"authors": {
|
||||
"default": "Amazon",
|
||||
"p2": null,
|
||||
"p1": null
|
||||
"p2": "GoodReads",
|
||||
"p1": "Amazon",
|
||||
"default": "Google"
|
||||
},
|
||||
"categories": {
|
||||
"default": "Amazon",
|
||||
"p2": null,
|
||||
"p1": null
|
||||
"p2": "Amazon",
|
||||
"p1": "GoodReads",
|
||||
"default": "Google"
|
||||
},
|
||||
"cover": {
|
||||
"default": "Amazon",
|
||||
"p2": null,
|
||||
"p1": null
|
||||
"p2": "GoodReads",
|
||||
"p1": "Amazon",
|
||||
"default": "Google"
|
||||
}
|
||||
}
|
||||
}'
|
||||
|
||||
Reference in New Issue
Block a user