More refactorings, more file re-arrangings
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.stomp.Topic;
|
||||
import com.adityachandel.booklore.model.websocket.Topic;
|
||||
import com.adityachandel.booklore.service.NotificationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.adityachandel.booklore.model;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.enums.ParsingStatus;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class FileProcessResult {
|
||||
private LibraryFile libraryFile;
|
||||
private ParsingStatus parsingStatus;
|
||||
private Book book;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.adityachandel.booklore.model;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.enums.ParsingStatus;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class ParseLibraryEvent {
|
||||
private long libraryId;
|
||||
private String file;
|
||||
private Book book;
|
||||
private ParsingStatus parsingStatus;
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.adityachandel.booklore.model.dto.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class GoogleBooksMetadata {
|
||||
private String googleBookId;
|
||||
private String title;
|
||||
private String subtitle;
|
||||
private String publisher;
|
||||
private String publishedDate;
|
||||
private String description;
|
||||
private String isbn13;
|
||||
private String isbn10;
|
||||
private Integer pageCount;
|
||||
private String thumbnail;
|
||||
private String language;
|
||||
private List<String> authors;
|
||||
private List<String> categories;
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.adityachandel.booklore.model.stomp;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class BookNotification {
|
||||
|
||||
private Action action;
|
||||
private Book addedBook;
|
||||
private Set<Long> removedBookIds;
|
||||
|
||||
public enum Action {
|
||||
BOOK_ADDED, BOOKS_REMOVED
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.adityachandel.booklore.model.stomp;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum Topic {
|
||||
BOOK("/topic/book"),
|
||||
LOG("/topic/log"),
|
||||
METADATA_UPDATE("/topic/metadata-update");
|
||||
|
||||
private final String path;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.adityachandel.booklore.model.websocket;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BookAddNotification {
|
||||
private Book addedBook;
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.adityachandel.booklore.model.websocket;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
public class BooksRemoveNotification {
|
||||
private Set<Long> removedBookIds;
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.model.stomp;
|
||||
package com.adityachandel.booklore.model.websocket;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.adityachandel.booklore.model.websocket;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum Topic {
|
||||
BOOK_ADD("/topic/book-add"),
|
||||
BOOKS_REMOVE("/topic/books-remove"),
|
||||
BOOK_METADATA_UPDATE("/topic/book-metadata-update"),
|
||||
|
||||
LOG("/topic/log");
|
||||
|
||||
private final String path;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
+4
-9
@@ -6,8 +6,7 @@ import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.model.stomp.BookNotification;
|
||||
import com.adityachandel.booklore.model.stomp.Topic;
|
||||
import com.adityachandel.booklore.model.websocket.Topic;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -23,9 +22,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.adityachandel.booklore.model.stomp.BookNotification.Action.BOOKS_REMOVED;
|
||||
import static com.adityachandel.booklore.model.stomp.BookNotification.Action.BOOK_ADDED;
|
||||
import static com.adityachandel.booklore.model.stomp.LogNotification.createLogNotification;
|
||||
import static com.adityachandel.booklore.model.websocket.LogNotification.createLogNotification;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@@ -61,8 +58,7 @@ public class LibraryProcessingService {
|
||||
if (!removedBookEntities.isEmpty()) {
|
||||
Set<Long> bookIds = removedBookEntities.stream().map(BookEntity::getId).collect(Collectors.toSet());
|
||||
bookRepository.deleteByIdIn(bookIds);
|
||||
BookNotification notification = BookNotification.builder().action(BOOKS_REMOVED).removedBookIds(bookIds).build();
|
||||
notificationService.sendMessage(Topic.BOOK, notification);
|
||||
notificationService.sendMessage(Topic.BOOKS_REMOVE, bookIds);
|
||||
log.info("Books removed: {}", bookIds);
|
||||
}
|
||||
}
|
||||
@@ -73,8 +69,7 @@ public class LibraryProcessingService {
|
||||
log.info("Processing file: {}", libraryFile.getFilePath());
|
||||
Book book = processLibraryFile(libraryFile);
|
||||
if (book != null) {
|
||||
BookNotification notification = BookNotification.builder().action(BOOK_ADDED).addedBook(book).build();
|
||||
notificationService.sendMessage(Topic.BOOK, notification);
|
||||
notificationService.sendMessage(Topic.BOOK_ADD, book);
|
||||
notificationService.sendMessage(Topic.LOG, createLogNotification("Book added: " + book.getFileName()));
|
||||
log.info("Processed file: {}", libraryFile.getFilePath());
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.model.stomp.Topic;
|
||||
import com.adityachandel.booklore.model.websocket.Topic;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
+3
-3
@@ -9,7 +9,7 @@ import com.adityachandel.booklore.model.dto.request.MetadataRefreshRequest;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||
import com.adityachandel.booklore.model.stomp.Topic;
|
||||
import com.adityachandel.booklore.model.websocket.Topic;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import com.adityachandel.booklore.service.NotificationService;
|
||||
@@ -28,7 +28,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.adityachandel.booklore.model.stomp.LogNotification.createLogNotification;
|
||||
import static com.adityachandel.booklore.model.websocket.LogNotification.createLogNotification;
|
||||
import static com.adityachandel.booklore.service.metadata.model.MetadataProvider.*;
|
||||
|
||||
@Slf4j
|
||||
@@ -105,7 +105,7 @@ public class BookMetadataService {
|
||||
bookEntity.setMetadata(bookMetadata);
|
||||
bookRepository.save(bookEntity);
|
||||
Book book = bookMapper.toBook(bookEntity);
|
||||
notificationService.sendMessage(Topic.METADATA_UPDATE, book);
|
||||
notificationService.sendMessage(Topic.BOOK_METADATA_UPDATE, book);
|
||||
notificationService.sendMessage(Topic.LOG, createLogNotification("Book metadata updated: " + book.getMetadata().getTitle()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import {Component, OnInit} from '@angular/core';
|
||||
import {RxStompService} from './shared/websocket/rx-stomp.service';
|
||||
import {Message} from '@stomp/stompjs';
|
||||
import {BookService} from './book/service/book.service';
|
||||
import {Action, parseBookNotification} from './shared/websocket/model/book-notification.model';
|
||||
import {EventService} from './shared/websocket/event.service';
|
||||
import {parseLogNotification} from './shared/websocket/model/log-notification.model';
|
||||
|
||||
@@ -18,16 +17,15 @@ export class AppComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.rxStompService.watch('/topic/book').subscribe((message: Message) => {
|
||||
const notification = parseBookNotification(message.body);
|
||||
if (notification.action === Action.BOOK_ADDED) {
|
||||
this.bookService.handleNewlyCreatedBook(notification.addedBook!);
|
||||
} else if (notification.action === Action.BOOKS_REMOVED) {
|
||||
this.bookService.handleRemovedBookIds(notification.removedBookIds!);
|
||||
}
|
||||
this.rxStompService.watch('/topic/book-add').subscribe((message: Message) => {
|
||||
this.bookService.handleNewlyCreatedBook(JSON.parse(message.body));
|
||||
});
|
||||
|
||||
this.rxStompService.watch('/topic/metadata-update').subscribe((message: Message) => {
|
||||
this.rxStompService.watch('/topic/books-removed').subscribe((message: Message) => {
|
||||
this.bookService.handleRemovedBookIds(JSON.parse(message.body));
|
||||
});
|
||||
|
||||
this.rxStompService.watch('/topic/book-metadata-update').subscribe((message: Message) => {
|
||||
this.bookService.handleBookUpdate(JSON.parse(message.body));
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {AppComponent} from './app.component';
|
||||
import {AppLayoutModule} from './layout/component/layout-main/app.layout.module';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {DirectoryPickerComponent} from './utilities/directory-picker/directory-picker.component';
|
||||
import {DirectoryPickerComponent} from './utilities/component/directory-picker/directory-picker.component';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {Button} from 'primeng/button';
|
||||
@@ -35,7 +35,7 @@ import {SpeedDialModule} from 'primeng/speeddial';
|
||||
import {RouteReuseStrategy} from '@angular/router';
|
||||
import {CustomReuseStrategy} from './custom-reuse-strategy';
|
||||
import {MenuModule} from 'primeng/menu';
|
||||
import {IconPickerComponent} from './utilities/icon-picker/icon-picker.component';
|
||||
import {IconPickerComponent} from './utilities/component/icon-picker/icon-picker.component';
|
||||
import {ProgressSpinnerModule} from 'primeng/progressspinner';
|
||||
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
|
||||
import {providePrimeNG} from 'primeng/config';
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {DirectoryPickerComponent} from '../../../utilities/directory-picker/directory-picker.component';
|
||||
import {DirectoryPickerComponent} from '../../../utilities/component/directory-picker/directory-picker.component';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Router} from '@angular/router';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {IconPickerComponent} from '../../../utilities/icon-picker/icon-picker.component';
|
||||
import {IconPickerComponent} from '../../../utilities/component/icon-picker/icon-picker.component';
|
||||
import {take} from 'rxjs';
|
||||
|
||||
@Component({
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Observable } from 'rxjs';
|
||||
import { BookService } from '../../service/book.service';
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
import { Shelf } from '../../model/shelf.model';
|
||||
import { IconPickerComponent } from '../../../utilities/icon-picker/icon-picker.component';
|
||||
import { IconPickerComponent } from '../../../utilities/component/icon-picker/icon-picker.component';
|
||||
import { ShelfState } from '../../model/state/shelf-state.model';
|
||||
|
||||
@Component({
|
||||
|
||||
@@ -5,8 +5,6 @@ import {LibraryService} from './library.service';
|
||||
import {ShelfService} from './shelf.service';
|
||||
import {Library} from '../model/library.model';
|
||||
import {Shelf} from '../model/shelf.model';
|
||||
import {MetadataService} from '../../metadata/metadata.service';
|
||||
import {MetadataProvider} from '../../metadata/model/provider.model';
|
||||
import {DialogService} from 'primeng/dynamicdialog';
|
||||
import {MetadataFetchOptionsComponent} from '../../metadata/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component';
|
||||
import {MetadataRefreshType} from '../../metadata/model/request/metadata-refresh-type.enum';
|
||||
@@ -20,7 +18,6 @@ export class LibraryShelfMenuService {
|
||||
private messageService: MessageService,
|
||||
private libraryService: LibraryService,
|
||||
private shelfService: ShelfService,
|
||||
private metadataService: MetadataService,
|
||||
private router: Router,
|
||||
private dialogService: DialogService
|
||||
) {
|
||||
@@ -99,42 +96,6 @@ export class LibraryShelfMenuService {
|
||||
metadataRefreshType: MetadataRefreshType.LIBRARY
|
||||
}
|
||||
})
|
||||
/*this.confirmationService.confirm({
|
||||
message: `Are you sure you want to refresh the metadata for all books in the library: "${entity?.name}"?`,
|
||||
header: 'Confirm Library Metadata Refresh',
|
||||
rejectButtonProps: {
|
||||
label: 'Cancel',
|
||||
},
|
||||
accept: () => {
|
||||
this.metadataService.autoRefreshLibraryBooksMetadata(entity?.id!, MetadataProvider.AMAZON, false).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
life: 1500,
|
||||
summary: 'Library Metadata Refresh Scheduled',
|
||||
detail: 'The metadata refresh for all books in the library has been successfully scheduled.',
|
||||
});
|
||||
},
|
||||
error: (e) => {
|
||||
if (e.status === 409) {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Task Already Running',
|
||||
life: 5000,
|
||||
detail: 'A metadata refresh task is already in progress. Please wait for it to complete before starting another one.',
|
||||
});
|
||||
} else {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Library Metadata Refresh Failed',
|
||||
life: 5000,
|
||||
detail: 'An unexpected error occurred while scheduling the metadata refresh. Please try again later or contact support if the issue persists.',
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});*/
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -8,7 +8,7 @@ import {TooltipModule} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {BookSearcherComponent} from '../../../book/components/book-searcher/book-searcher.component';
|
||||
import {FileUploadComponent} from '../../../utilities/file-upload/file-upload.component';
|
||||
import {FileUploadComponent} from '../../../utilities/component/file-upload/file-upload.component';
|
||||
import {NgClass, NgIf} from '@angular/common';
|
||||
import {EventService} from '../../../shared/websocket/event.service';
|
||||
import {LogNotification} from '../../../shared/websocket/model/log-notification.model';
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { Book } from '../../../book/model/book.model';
|
||||
|
||||
export interface BookNotification {
|
||||
action: Action;
|
||||
addedBook?: Book;
|
||||
removedBookIds?: Set<number>;
|
||||
}
|
||||
|
||||
export enum Action {
|
||||
BOOK_ADDED = 'BOOK_ADDED',
|
||||
BOOKS_REMOVED = 'BOOKS_REMOVED',
|
||||
}
|
||||
|
||||
export function parseBookNotification(messageBody: string): BookNotification {
|
||||
const raw = JSON.parse(messageBody);
|
||||
return {
|
||||
action: raw.action,
|
||||
addedBook: raw.addedBook,
|
||||
removedBookIds: raw.removedBookIds ? new Set<number>(raw.removedBookIds) : undefined,
|
||||
};
|
||||
}
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {Library} from '../../book/model/library.model';
|
||||
import {Library} from '../../../book/model/library.model';
|
||||
import {FileUploadService} from './file-upload.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {AsyncPipe, NgIf} from '@angular/common';
|
||||
import {DropdownModule} from 'primeng/dropdown';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {ToastService} from '../../core/service/toast.service';
|
||||
import {ToastService} from '../../../core/service/toast.service';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {LibraryService} from '../../book/service/library.service';
|
||||
import {LibraryService} from '../../../book/service/library.service';
|
||||
import {Observable} from 'rxjs';
|
||||
import {LibraryState} from '../../book/model/state/library-state.model';
|
||||
import {LibraryState} from '../../../book/model/state/library-state.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-file-upload-v2',
|
||||
Reference in New Issue
Block a user