Enhance Quick Metadata Refresh Functionality

This commit is contained in:
aditya.chandel
2025-05-28 17:46:30 -07:00
committed by Aditya Chandel
parent da6decb349
commit 40294019f5
13 changed files with 125 additions and 60 deletions
@@ -203,9 +203,12 @@ public class BookMetadataService {
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());
metadataCombined.setRatingCount(metadata.getRatingCount() != null ? metadata.getRatingCount() : metadataCombined.getRatingCount());
metadataCombined.setReviewCount(metadata.getReviewCount() != null ? metadata.getReviewCount() : metadataCombined.getReviewCount());
metadataCombined.setGoodreadsRating(metadata.getGoodreadsRating() != null ? metadata.getGoodreadsRating() : metadataCombined.getGoodreadsRating());
metadataCombined.setGoodreadsReviewCount(metadata.getGoodreadsReviewCount() != null ? metadata.getGoodreadsReviewCount() : metadataCombined.getGoodreadsReviewCount());
metadataCombined.setAmazonRating(metadata.getAmazonRating() != null ? metadata.getAmazonRating() : metadataCombined.getAmazonRating());
metadataCombined.setAmazonReviewCount(metadata.getAmazonReviewCount() != null ? metadata.getAmazonReviewCount() : metadataCombined.getAmazonReviewCount());
metadataCombined.setHardcoverRating(metadata.getHardcoverRating() != null ? metadata.getHardcoverRating() : metadataCombined.getHardcoverRating());
metadataCombined.setHardcoverReviewCount(metadata.getHardcoverReviewCount() != null ? metadata.getHardcoverReviewCount() : metadataCombined.getHardcoverReviewCount());
metadataCombined.setAwards(metadata.getAwards() != null ? metadata.getAwards() : metadataCombined.getAwards());
metadataCombined.setSeriesName(metadata.getSeriesName() != null ? metadata.getSeriesName() : metadataCombined.getSeriesName());
metadataCombined.setSeriesNumber(metadata.getSeriesNumber() != null ? metadata.getSeriesNumber() : metadataCombined.getSeriesNumber());
@@ -389,11 +392,23 @@ public class BookMetadataService {
case "language":
existingMetadata.setLanguageLocked(isLocked);
break;
case "rating":
existingMetadata.setRatingLocked(isLocked);
case "amazonRating":
existingMetadata.setAmazonRatingLocked(isLocked);
break;
case "reviewCount":
existingMetadata.setReviewCountLocked(isLocked);
case "amazonReviewCount":
existingMetadata.setAmazonReviewCountLocked(isLocked);
break;
case "goodreadsRating":
existingMetadata.setGoodreadsRatingLocked(isLocked);
break;
case "goodreadsReviewCount":
existingMetadata.setGoodreadsReviewCountLocked(isLocked);
break;
case "hardcoverRating":
existingMetadata.setHardcoverRatingLocked(isLocked);
break;
case "hardcoverReviewCount":
existingMetadata.setHardcoverReviewCountLocked(isLocked);
break;
default:
throw new IllegalArgumentException("Invalid field name: " + field);
@@ -460,6 +475,6 @@ public class BookMetadataService {
.peek(book -> book.getMetadata().applyLockToAllFields(lock))
.toList();
bookRepository.saveAll(books);
return books.stream().map(b ->bookMetadataMapper.toBookMetadata(b.getMetadata(), false)).collect(Collectors.toList());
return books.stream().map(b -> bookMetadataMapper.toBookMetadata(b.getMetadata(), false)).collect(Collectors.toList());
}
}
@@ -47,27 +47,21 @@ public class BookMetadataUpdater {
if ((metadata.getTitleLocked() == null || !metadata.getTitleLocked()) && newMetadata.getTitle() != null) {
metadata.setTitle(newMetadata.getTitle().isEmpty() ? null : newMetadata.getTitle());
}
if ((metadata.getSubtitleLocked() == null || !metadata.getSubtitleLocked()) && newMetadata.getSubtitle() != null) {
metadata.setSubtitle(newMetadata.getSubtitle().isBlank() ? null : newMetadata.getSubtitle());
}
if ((metadata.getPublisherLocked() == null || !metadata.getPublisherLocked()) && newMetadata.getPublisher() != null) {
metadata.setPublisher(newMetadata.getPublisher().isBlank() ? null : newMetadata.getPublisher());
}
if ((metadata.getPublishedDateLocked() == null || !metadata.getPublishedDateLocked()) && newMetadata.getPublishedDate() != null) {
metadata.setPublishedDate(newMetadata.getPublishedDate());
}
if ((metadata.getLanguageLocked() == null || !metadata.getLanguageLocked()) && newMetadata.getLanguage() != null) {
metadata.setLanguage(newMetadata.getLanguage().isBlank() ? null : newMetadata.getLanguage());
}
if ((metadata.getIsbn10Locked() == null || !metadata.getIsbn10Locked()) && newMetadata.getIsbn10() != null) {
metadata.setIsbn10(newMetadata.getIsbn10().isBlank() ? null : newMetadata.getIsbn10());
}
if ((metadata.getIsbn13Locked() == null || !metadata.getIsbn13Locked()) && newMetadata.getIsbn13() != null) {
metadata.setIsbn13(newMetadata.getIsbn13().isBlank() ? null : newMetadata.getIsbn13());
}
@@ -77,47 +71,36 @@ public class BookMetadataUpdater {
if ((metadata.getDescriptionLocked() == null || !metadata.getDescriptionLocked()) && newMetadata.getDescription() != null) {
metadata.setDescription(newMetadata.getDescription().isBlank() ? null : newMetadata.getDescription());
}
if ((metadata.getPageCountLocked() == null || !metadata.getPageCountLocked()) && newMetadata.getPageCount() != null) {
metadata.setPageCount(newMetadata.getPageCount());
}
if ((metadata.getAmazonRatingLocked() == null || !metadata.getAmazonRatingLocked()) && newMetadata.getAmazonRating() != null) {
metadata.setAmazonRating(newMetadata.getAmazonRating());
}
if ((metadata.getAmazonReviewCountLocked() == null || !metadata.getAmazonReviewCountLocked()) && newMetadata.getAmazonReviewCount() != null) {
metadata.setAmazonReviewCount(newMetadata.getAmazonReviewCount());
}
if ((metadata.getGoodreadsRatingLocked() == null || !metadata.getGoodreadsRatingLocked()) && newMetadata.getGoodreadsRating() != null) {
metadata.setGoodreadsRating(newMetadata.getGoodreadsRating());
}
if ((metadata.getGoodreadsReviewCountLocked() == null || !metadata.getGoodreadsReviewCountLocked()) && newMetadata.getGoodreadsReviewCount() != null) {
metadata.setGoodreadsReviewCount(newMetadata.getGoodreadsReviewCount());
}
if ((metadata.getHardcoverRatingLocked() == null || !metadata.getHardcoverRatingLocked()) && newMetadata.getHardcoverRating() != null) {
metadata.setHardcoverRating(newMetadata.getHardcoverRating());
}
if ((metadata.getHardcoverReviewCountLocked() == null || !metadata.getHardcoverReviewCountLocked()) && newMetadata.getHardcoverReviewCount() != null) {
metadata.setHardcoverReviewCount(newMetadata.getHardcoverReviewCount());
}
if ((metadata.getSeriesNameLocked() == null || !metadata.getSeriesNameLocked()) && newMetadata.getSeriesName() != null) {
metadata.setSeriesName(newMetadata.getSeriesName());
}
if ((metadata.getSeriesNumberLocked() == null || !metadata.getSeriesNumberLocked()) && newMetadata.getSeriesNumber() != null) {
metadata.setSeriesNumber(newMetadata.getSeriesNumber());
}
if ((metadata.getSeriesTotalLocked() == null || !metadata.getSeriesTotalLocked()) && newMetadata.getSeriesTotal() != null) {
metadata.setSeriesTotal(newMetadata.getSeriesTotal());
}
if (newMetadata.getAwards() != null && !newMetadata.getAwards().isEmpty()) {
HashSet<BookAwardEntity> newAwards = new HashSet<>();
newMetadata.getAwards()
@@ -293,7 +293,7 @@ public class AmazonBookParser implements BookParser {
if (seriesNameElement != null) {
return seriesNameElement.text();
} else {
log.warn("Failed to parse seriesName: Element not found.");
log.debug("Failed to parse seriesName: Element not found.");
}
} catch (Exception e) {
log.warn("Failed to parse seriesName: {}", e.getMessage());
@@ -311,7 +311,7 @@ public class AmazonBookParser implements BookParser {
return Float.parseFloat(parts[1]);
}
} else {
log.warn("Failed to parse seriesNumber: Element not found.");
log.debug("Failed to parse seriesNumber: Element not found.");
}
} catch (Exception e) {
log.warn("Failed to parse seriesNumber: {}", e.getMessage());
@@ -329,7 +329,7 @@ public class AmazonBookParser implements BookParser {
return Integer.parseInt(parts[3]);
}
} else {
log.warn("Failed to parse seriesTotal: Element not found.");
log.debug("Failed to parse seriesTotal: Element not found.");
}
} catch (Exception e) {
log.warn("Failed to parse seriesTotal: {}", e.getMessage());
@@ -343,7 +343,7 @@ public class AmazonBookParser implements BookParser {
if (languageElement != null) {
return languageElement.text();
}
log.warn("Failed to parse language: Element not found.");
log.debug("Failed to parse language: Element not found.");
} catch (Exception e) {
log.warn("Failed to parse language: {}", e.getMessage());
}
@@ -24,6 +24,8 @@ public class HardcoverParser implements BookParser {
@Override
public List<BookMetadata> fetchMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) {
log.info("Hardcover: Fetching metadata for book {}", fetchMetadataRequest.getTitle());
List<GraphQLResponse.Hit> hits = hardcoverBookSearchService.searchBooks(fetchMetadataRequest.getTitle());
return hits.stream().map(hit -> {
@@ -78,6 +80,6 @@ public class HardcoverParser implements BookParser {
@Override
public BookMetadata fetchTopMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) {
List<BookMetadata> bookMetadata = fetchMetadata(book, fetchMetadataRequest);
return bookMetadata.getFirst();
return bookMetadata.isEmpty() ? null : bookMetadata.getFirst();
}
}
@@ -7,6 +7,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestClientException;
import java.util.Collections;
import java.util.List;
@@ -51,14 +52,25 @@ public class HardcoverBookSearchService {
body.setQuery(graphqlQuery);
body.setOperationName("SearchBooks");
GraphQLResponse response = restClient.post()
.uri("")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + apiToken)
.body(body)
.retrieve()
.body(GraphQLResponse.class);
try {
GraphQLResponse response = restClient.post()
.uri("")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + apiToken)
.body(body)
.retrieve()
.body(GraphQLResponse.class);
return response.getData().getSearch().getResults().getHits();
if (response == null || response.getData() == null || response.getData().getSearch() == null || response.getData().getSearch().getResults() == null) {
log.warn("Empty or malformed response from Hardcover API");
return Collections.emptyList();
}
return response.getData().getSearch().getResults().getHits();
} catch (RestClientException e) {
log.error("Failed to fetch data from Hardcover API, Error: {}", e.getMessage());
return Collections.emptyList();
}
}
}
}
@@ -457,9 +457,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
bookIds: this.selectedBooks
},
});
this.dynamicDialogRef.onClose.subscribe(() => {
this.selectedBooks.clear();
});
}
updateMetadata() {
@@ -133,8 +133,10 @@
<p-button label="Assign Shelf" icon="pi pi-folder" severity="info" outlined (onClick)="assignShelf(metadata.bookId)"></p-button>
<p-button *ngIf="userData.permissions.canDownload || userData.permissions.admin" label="Download" icon="pi pi-download" severity="info" outlined
(onClick)="download(metadata.bookId)"></p-button>
<p-splitbutton *ngIf="userData.permissions.canEmailBook || userData.permissions.admin" label="Quick Send" icon="pi pi-send" [model]="items"
<p-splitbutton *ngIf="userData.permissions.canEmailBook || userData.permissions.admin" label="Quick Send" icon="pi pi-send" [model]="emailMenuItems"
(onClick)="quickSend(metadata.bookId)" outlined severity="info"/>
<p-splitbutton *ngIf="userData.permissions.canEditMetadata || userData.permissions.admin" label="Quick Refresh" icon="pi pi-bolt" [model]="refreshMenuItems"
(onClick)="quickRefresh(metadata.bookId)" outlined severity="info"/>
</div>
</div>
</div>
@@ -24,6 +24,9 @@ import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {Editor} from 'primeng/editor';
import {ProgressBar} from 'primeng/progressbar';
import {ToggleButton} from 'primeng/togglebutton';
import {MetadataFetchOptionsComponent} from '../../metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
@Component({
selector: 'app-metadata-viewer',
@@ -50,13 +53,14 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
private destroyRef = inject(DestroyRef);
metadata$: Observable<BookMetadata | null> = this.metadataCenterService.currentMetadata$;
items: MenuItem[] | undefined;
emailMenuItems: MenuItem[] | undefined;
refreshMenuItems: MenuItem[] | undefined;
bookInSeries: Book[] = [];
isExpanded = false;
showFilePath = false;
ngOnInit(): void {
this.items = [
this.emailMenuItems = [
{
label: 'Custom Send',
command: () => {
@@ -80,6 +84,24 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
}
];
this.refreshMenuItems = [
{
label: 'Granular Refresh',
icon: 'pi pi-database',
command: () => {
this.dialogService.open(MetadataFetchOptionsComponent, {
header: 'Metadata Refresh Options',
modal: true,
closable: true,
data: {
bookIds: [this.book!.id],
metadataRefreshType: MetadataRefreshType.BOOKS,
},
});
},
}
];
this.metadata$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((metadata) => {
@@ -134,6 +156,15 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
this.bookService.downloadFile(bookId);
}
quickRefresh(bookId: number) {
const metadataRefreshRequest: MetadataRefreshRequest = {
quick: true,
refreshType: MetadataRefreshType.BOOKS,
bookIds: [bookId],
};
this.bookService.autoRefreshMetadata(metadataRefreshRequest).subscribe();
}
quickSend(bookId: number) {
this.emailService.emailBookQuick(bookId).subscribe({
next: () => {
@@ -191,7 +222,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
getProgressPercent(): number | undefined {
if (this.book?.bookType === 'PDF') {
return this.book.pdfProgress?.percentage;
} else if(this.book?.bookType === 'CBX') {
} else if (this.book?.bookType === 'CBX') {
return this.book?.cbxProgress?.percentage;
} else {
return this.book?.epubProgress?.percentage;
@@ -201,9 +232,9 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
copyFilePath() {
if (this.book?.filePath) {
navigator.clipboard.writeText(this.book.filePath).then(() => {
this.messageService.add({ severity: 'success', summary: 'Copied', detail: 'File path copied to clipboard.' });
this.messageService.add({severity: 'success', summary: 'Copied', detail: 'File path copied to clipboard.'});
}, () => {
this.messageService.add({ severity: 'error', summary: 'Error', detail: 'Failed to copy file path.' });
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to copy file path.'});
});
}
}
@@ -219,12 +250,18 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
if (!fileType) return 'bg-gray-500 text-white';
switch (fileType.toLowerCase()) {
case 'pdf': return 'bg-red-700 text-white';
case 'epub': return 'bg-yellow-600 text-gray-900';
case 'cbz': return 'bg-green-700 text-white';
case 'cbr': return 'bg-purple-700 text-white';
case 'cb7': return 'bg-blue-700 text-white';
default: return 'bg-gray-600 text-white';
case 'pdf':
return 'bg-red-700 text-white';
case 'epub':
return 'bg-yellow-600 text-gray-900';
case 'cbz':
return 'bg-green-700 text-white';
case 'cbr':
return 'bg-purple-700 text-white';
case 'cb7':
return 'bg-blue-700 text-white';
default:
return 'bg-gray-600 text-white';
}
}
@@ -72,7 +72,7 @@
</div>
<div class="flex flex-row gap-6">
<p-button severity="warn" outlined="true" label="Reset" (onClick)="reset()"></p-button>
<p-button label="Save" outlined="true" (onClick)="submit()"></p-button>
<p-button [label]="submitButtonLabel" outlined="true" (onClick)="submit()"></p-button>
</div>
</div>
@@ -36,6 +36,7 @@ export class MetadataAdvancedFetchOptionsComponent implements OnChanges {
private messageService = inject(MessageService);
@Input() currentMetadataOptions!: MetadataRefreshOptions;
@Input() submitButtonLabel!: string;
ngOnChanges(changes: SimpleChanges): void {
@@ -1,5 +1,7 @@
<div class="flex flex-col space-y-6">
<app-metadata-advanced-fetch-options (metadataOptionsSubmitted)="onMetadataSubmit($event)"></app-metadata-advanced-fetch-options>
<app-metadata-advanced-fetch-options
(metadataOptionsSubmitted)="onMetadataSubmit($event)"
[currentMetadataOptions]="currentMetadataOptions"
[submitButtonLabel]="'Start Refresh'">
</app-metadata-advanced-fetch-options>
</div>
@@ -1,10 +1,12 @@
import {Component, inject} from '@angular/core';
import {Component, inject, Input} from '@angular/core';
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
import {MetadataAdvancedFetchOptionsComponent} from '../metadata-advanced-fetch-options/metadata-advanced-fetch-options.component';
import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model';
import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum';
import {MetadataRefreshOptions} from '../../model/request/metadata-refresh-options.model';
import {BookService} from '../../../service/book.service';
import {AppSettingsService} from '../../../../core/service/app-settings.service';
import {filter, take} from 'rxjs/operators';
@Component({
selector: 'app-metadata-fetch-options',
@@ -19,15 +21,23 @@ export class MetadataFetchOptionsComponent {
libraryId!: number;
bookIds!: number[];
metadataRefreshType!: MetadataRefreshType;
currentMetadataOptions!: MetadataRefreshOptions;
private dynamicDialogConfig = inject(DynamicDialogConfig);
private dynamicDialogRef = inject(DynamicDialogRef);
private bookService = inject(BookService);
private appSettingsService = inject(AppSettingsService);
constructor() {
this.libraryId = this.dynamicDialogConfig.data.libraryId;
this.bookIds = this.dynamicDialogConfig.data.bookIds;
this.metadataRefreshType = this.dynamicDialogConfig.data.metadataRefreshType;
this.appSettingsService.appSettings$.pipe(
filter(settings => settings != null),
take(1)
).subscribe(settings => {
this.currentMetadataOptions = settings?.metadataRefreshOptions;
});
}
onMetadataSubmit(metadataRefreshOptions: MetadataRefreshOptions) {
@@ -170,7 +170,11 @@
style="cursor: pointer;">
</i>
</p>
<app-metadata-advanced-fetch-options (metadataOptionsSubmitted)="onMetadataSubmit($event)" [currentMetadataOptions]="currentMetadataOptions"></app-metadata-advanced-fetch-options>
<app-metadata-advanced-fetch-options
(metadataOptionsSubmitted)="onMetadataSubmit($event)"
[currentMetadataOptions]="currentMetadataOptions"
[submitButtonLabel]="'Save'">
</app-metadata-advanced-fetch-options>
</div>
</div>