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()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user