From aefd56d1ffb001d693a6d6b3ff734f89674997e1 Mon Sep 17 00:00:00 2001 From: Thomas Peetz Date: Sun, 1 Jun 2025 22:23:25 +0200 Subject: [PATCH] Remove entity ModuleData and setup data refs #18 --- .../thpeetz/kontor/admin/AdminConstants.java | 1 - .../thpeetz/kontor/admin/data/ModuleData.java | 25 - .../repository/ModuleDataRepository.java | 16 - .../kontor/admin/services/ModuleService.java | 76 -- .../kontor/admin/views/ModuleDataForm.java | 100 -- .../kontor/admin/views/ModuleDataView.java | 140 --- .../bookshelf/SetupModuleBookshelf.java | 36 - .../kontor/comics/SetupModuleComics.java | 1113 ----------------- .../kontor/media/SetupModuleMedia.java | 10 - .../thpeetz/kontor/tysc/SetupModuleTysc.java | 428 ------- 10 files changed, 1945 deletions(-) delete mode 100644 kontor-spring/src/main/java/de/thpeetz/kontor/admin/data/ModuleData.java delete mode 100644 kontor-spring/src/main/java/de/thpeetz/kontor/admin/repository/ModuleDataRepository.java delete mode 100644 kontor-spring/src/main/java/de/thpeetz/kontor/admin/services/ModuleService.java delete mode 100644 kontor-spring/src/main/java/de/thpeetz/kontor/admin/views/ModuleDataForm.java delete mode 100644 kontor-spring/src/main/java/de/thpeetz/kontor/admin/views/ModuleDataView.java diff --git a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/AdminConstants.java b/kontor-spring/src/main/java/de/thpeetz/kontor/admin/AdminConstants.java index 9490d74..97cee54 100644 --- a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/AdminConstants.java +++ b/kontor-spring/src/main/java/de/thpeetz/kontor/admin/AdminConstants.java @@ -48,7 +48,6 @@ public class AdminConstants { data.addItem(new SideNavItem(ComicConstants.COMICWORK, ComicWorkView.class)); data.addItem(new SideNavItem(MediaConstants.MEDIAACTORFILE, MediaActorFileView.class)); data.addItem(new SideNavItem(AUTHORIZATION, AssignmentView.class)); - data.addItem(new SideNavItem("Data Import", ModuleDataView.class)); administration.addItem(data); return administration; } diff --git a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/data/ModuleData.java b/kontor-spring/src/main/java/de/thpeetz/kontor/admin/data/ModuleData.java deleted file mode 100644 index b884425..0000000 --- a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/data/ModuleData.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.thpeetz.kontor.admin.data; - -import de.thpeetz.kontor.common.data.AbstractEntity; -import jakarta.persistence.Entity; -import jakarta.persistence.Index; -import jakarta.persistence.Table; -import jakarta.persistence.UniqueConstraint; -import jakarta.validation.constraints.NotEmpty; -import lombok.Getter; -import lombok.Setter; - -@Entity -@Getter -@Setter -@Table( - indexes = @Index(columnList = "moduleName"), - uniqueConstraints = @UniqueConstraint(columnNames = {"moduleName"}) -) -public class ModuleData extends AbstractEntity { - - @NotEmpty - private String moduleName; - - private Boolean importData; -} diff --git a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/repository/ModuleDataRepository.java b/kontor-spring/src/main/java/de/thpeetz/kontor/admin/repository/ModuleDataRepository.java deleted file mode 100644 index ace45ef..0000000 --- a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/repository/ModuleDataRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.thpeetz.kontor.admin.repository; - -import de.thpeetz.kontor.admin.data.ModuleData; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.List; - -public interface ModuleDataRepository extends JpaRepository { - - @Query("select m from ModuleData m where lower(m.moduleName) like lower(concat('%', :searchTerm, '%')) ") - List search(@Param("searchTerm") String searchTerm); - - ModuleData findByModuleName(String moduleName); -} diff --git a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/services/ModuleService.java b/kontor-spring/src/main/java/de/thpeetz/kontor/admin/services/ModuleService.java deleted file mode 100644 index 8c5f929..0000000 --- a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/services/ModuleService.java +++ /dev/null @@ -1,76 +0,0 @@ -package de.thpeetz.kontor.admin.services; - -import de.thpeetz.kontor.admin.data.ModuleData; -import de.thpeetz.kontor.admin.repository.ModuleDataRepository; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Slf4j -@Service -public class ModuleService { - - private final ModuleDataRepository moduleDataRepository; - - public ModuleService(ModuleDataRepository moduleDataRepository) { - this.moduleDataRepository = moduleDataRepository; - } - - public List findAll(String stringFilter) { - if (stringFilter == null || stringFilter.isEmpty()) { - return moduleDataRepository.findAll(); - } else { - return moduleDataRepository.search(stringFilter); - } - } - - public ModuleData findByName(String moduleName) { - if (moduleName == null || moduleName.isEmpty()) { - return null; - } else { - return moduleDataRepository.findByModuleName(moduleName); - } - } - - public boolean importData(String moduleName) { - ModuleData module = moduleDataRepository.findByModuleName(moduleName); - if (module != null) { - return module.getImportData(); - } else { - log.info("Module {} not found, should import data", moduleName); - return true; - } - } - - public void setDataImported(String moduleName) { - ModuleData module = moduleDataRepository.findByModuleName(moduleName); - if (module == null) { - log.info("Module {} not found, will create it", moduleName); - module = new ModuleData(); - module.setModuleName(moduleName); - module.setImportData(false); - moduleDataRepository.save(module); - } else { - log.info("Module {} found, change import data", module); - module.setImportData(false); - moduleDataRepository.save(module); - } - } - - public void saveModuleData(ModuleData moduleData) { - if (moduleData == null) { - log.warn("ModuleData is null, can't save it."); - } else { - moduleDataRepository.save(moduleData); - } - } - - public void deleteModuleData(ModuleData moduleData) { - if (moduleData == null) { - log.warn("ModuleData is null, can't delete it."); - } else { - moduleDataRepository.delete(moduleData); - } - } -} diff --git a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/views/ModuleDataForm.java b/kontor-spring/src/main/java/de/thpeetz/kontor/admin/views/ModuleDataForm.java deleted file mode 100644 index b2c5f8c..0000000 --- a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/views/ModuleDataForm.java +++ /dev/null @@ -1,100 +0,0 @@ -package de.thpeetz.kontor.admin.views; - -import com.vaadin.flow.component.ComponentEvent; -import com.vaadin.flow.component.ComponentEventListener; -import com.vaadin.flow.component.Key; -import com.vaadin.flow.component.button.Button; -import com.vaadin.flow.component.button.ButtonVariant; -import com.vaadin.flow.component.checkbox.Checkbox; -import com.vaadin.flow.component.formlayout.FormLayout; -import com.vaadin.flow.component.orderedlayout.HorizontalLayout; -import com.vaadin.flow.component.textfield.TextField; -import com.vaadin.flow.data.binder.BeanValidationBinder; -import com.vaadin.flow.data.binder.Binder; -import de.thpeetz.kontor.admin.data.ModuleData; - -public class ModuleDataForm extends FormLayout { - TextField moduleName = new TextField("Module Name"); - Checkbox importData = new Checkbox("Import Data"); - - Button save = new com.vaadin.flow.component.button.Button("Save"); - Button delete = new com.vaadin.flow.component.button.Button("Delete"); - Button close = new Button("Cancel"); - - Binder binder = new BeanValidationBinder<>(ModuleData.class); - - public ModuleDataForm() { - addClassName("moduleData-form"); - binder.bindInstanceFields(this); - add(moduleName, importData, createButtonsLayout()); - } - - private HorizontalLayout createButtonsLayout() { - save.addThemeVariants(ButtonVariant.LUMO_PRIMARY); - delete.addThemeVariants(ButtonVariant.LUMO_ERROR); - close.addThemeVariants(ButtonVariant.LUMO_TERTIARY); - - save.addClickShortcut(Key.ENTER); - close.addClickShortcut(Key.ESCAPE); - - save.addClickListener(event -> validateAndSave()); - delete.addClickListener(event -> fireEvent(new ModuleDataForm.DeleteEvent(this, binder.getBean()))); - close.addClickListener(event -> fireEvent(new ModuleDataForm.CloseEvent(this))); - - binder.addStatusChangeListener(e -> save.setEnabled(binder.isValid())); - return new HorizontalLayout(save, delete, close); - } - - private void validateAndSave() { - if (binder.isValid()) { - fireEvent(new ModuleDataForm.SaveEvent(this, binder.getBean())); - } - } - - public void setModuleData(ModuleData moduleData) { - binder.setBean(moduleData); - } - - public abstract static class ModuleDataFormEvent extends ComponentEvent { - private ModuleData moduleData; - - protected ModuleDataFormEvent(ModuleDataForm source, ModuleData moduleData) { - super(source, false); - this.moduleData = moduleData; - } - - public ModuleData getModuleData() { - return moduleData; - } - } - - public static class SaveEvent extends ModuleDataForm.ModuleDataFormEvent { - SaveEvent(ModuleDataForm source, ModuleData moduleData) { - super(source, moduleData); - } - } - - public static class DeleteEvent extends ModuleDataForm.ModuleDataFormEvent { - DeleteEvent(ModuleDataForm source, ModuleData moduleData) { - super(source, moduleData); - } - } - - public static class CloseEvent extends ModuleDataForm.ModuleDataFormEvent { - CloseEvent(ModuleDataForm source) { - super(source, null); - } - } - - public void addDeleteListener(ComponentEventListener listener) { - addListener(ModuleDataForm.DeleteEvent.class, listener); - } - - public void addSaveListener(ComponentEventListener listener) { - addListener(ModuleDataForm.SaveEvent.class, listener); - } - - public void addCloseListener(ComponentEventListener listener) { - addListener(ModuleDataForm.CloseEvent.class, listener); - } -} diff --git a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/views/ModuleDataView.java b/kontor-spring/src/main/java/de/thpeetz/kontor/admin/views/ModuleDataView.java deleted file mode 100644 index 89f93f1..0000000 --- a/kontor-spring/src/main/java/de/thpeetz/kontor/admin/views/ModuleDataView.java +++ /dev/null @@ -1,140 +0,0 @@ -package de.thpeetz.kontor.admin.views; - -import com.vaadin.flow.component.Component; -import com.vaadin.flow.component.button.Button; -import com.vaadin.flow.component.button.ButtonVariant; -import com.vaadin.flow.component.contextmenu.ContextMenu; -import com.vaadin.flow.component.contextmenu.MenuItem; -import com.vaadin.flow.component.grid.Grid; -import com.vaadin.flow.component.icon.Icon; -import com.vaadin.flow.component.icon.VaadinIcon; -import com.vaadin.flow.component.orderedlayout.HorizontalLayout; -import com.vaadin.flow.component.orderedlayout.VerticalLayout; -import com.vaadin.flow.component.textfield.TextField; -import com.vaadin.flow.data.value.ValueChangeMode; -import com.vaadin.flow.router.PageTitle; -import com.vaadin.flow.router.Route; -import com.vaadin.flow.spring.annotation.SpringComponent; -import de.thpeetz.kontor.admin.data.ModuleData; -import de.thpeetz.kontor.admin.services.ModuleService; -import de.thpeetz.kontor.common.views.MainLayout; -import de.thpeetz.kontor.common.views.ColumnToggleContextMenu; -import de.thpeetz.kontor.common.views.StatusIcon; -import jakarta.annotation.security.RolesAllowed; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.annotation.Scope; - -@Slf4j -@SpringComponent -@Scope("prototype") -@RolesAllowed("ROLE_ADMIN") -@Route(value = "admin/module", layout = MainLayout.class) -@PageTitle("Module Data | Admin | Kontor") -public class ModuleDataView extends VerticalLayout { - - Grid grid = new Grid<>(ModuleData.class, false); - Grid.Column idColumn = grid.addColumn(ModuleData::getId) - .setHeader("ID").setResizable(true).setSortable(true); - Grid.Column nameColumn = grid.addColumn(ModuleData::getModuleName) - .setHeader("Name").setResizable(true).setSortable(true); - Grid.Column importColumn = grid.addComponentColumn(moduleData -> StatusIcon.create(moduleData.getImportData())) - .setHeader("Import Data").setWidth("6rem").setSortable(true); - - TextField filterText = new TextField(); - @Getter - ModuleDataForm form; - ModuleService service; - - public ModuleDataView(ModuleService service) { - this.service = service; - addClassName("moduleData-view"); - setSizeFull(); - configureGrid(); - configureForm(); - - add(getToolbar(), getContent()); - updateList(); - } - - private void configureGrid() { - grid.addClassName("moduleData-grid"); - grid.setSizeFull(); - grid.getColumns().forEach(col -> col.setAutoWidth(true)); - grid.asSingleSelect().addValueChangeListener(event -> editModuleData(event.getValue())); - } - - private void configureForm() { - form = new ModuleDataForm(); - form.setWidth("25em"); - form.setVisible(false); - form.addSaveListener(this::saveModuleData); - form.addDeleteListener(this::deleteModuleData); - form.addCloseListener(e -> closeEditor()); - } - - private void saveModuleData(ModuleDataForm.SaveEvent event) { - ModuleData moduleData = event.getModuleData(); - service.saveModuleData(moduleData); - updateList(); - closeEditor(); - } - - private void deleteModuleData(ModuleDataForm.DeleteEvent event) { - service.deleteModuleData(event.getModuleData()); - updateList(); - closeEditor(); - } - - private Component getContent() { - HorizontalLayout content = new HorizontalLayout(grid, form); - content.setFlexGrow(2, grid); - content.setFlexGrow(1, form); - content.addClassName("content"); - content.setSizeFull(); - return content; - } - - private HorizontalLayout getToolbar() { - filterText.setPlaceholder("Filter by module name..."); - filterText.setClearButtonVisible(true); - filterText.setValueChangeMode(ValueChangeMode.LAZY); - filterText.addValueChangeListener(e -> updateList()); - Button addModuleDataButton = new Button("Add module", click -> addModuleData()); - - Button menuButton = new Button("Show/Hide Columns"); - menuButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY); - ColumnToggleContextMenu columnToggleContextMenu = new ColumnToggleContextMenu<>(menuButton); - columnToggleContextMenu.addColumnToggleItem(idColumn); - columnToggleContextMenu.addColumnToggleItem(nameColumn); - columnToggleContextMenu.addColumnToggleItem(importColumn); - HorizontalLayout toolbar = new HorizontalLayout(filterText, addModuleDataButton, menuButton); - toolbar.addClassName("toolbar"); - return toolbar; - } - - public void editModuleData(ModuleData moduleData) { - if (moduleData == null) { - closeEditor(); - } else { - form.setModuleData(moduleData); - form.setVisible(true); - addClassName("editing"); - } - } - - public void closeEditor() { - form.setModuleData(null); - form.setVisible(false); - removeClassName("editing"); - } - - private void addModuleData() { - grid.asSingleSelect().clear(); - editModuleData(new ModuleData()); - } - - private void updateList() { - grid.setItems(service.findAll(filterText.getValue())); - } -} diff --git a/kontor-spring/src/main/java/de/thpeetz/kontor/bookshelf/SetupModuleBookshelf.java b/kontor-spring/src/main/java/de/thpeetz/kontor/bookshelf/SetupModuleBookshelf.java index abb0e9a..f505654 100644 --- a/kontor-spring/src/main/java/de/thpeetz/kontor/bookshelf/SetupModuleBookshelf.java +++ b/kontor-spring/src/main/java/de/thpeetz/kontor/bookshelf/SetupModuleBookshelf.java @@ -5,7 +5,6 @@ import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.stereotype.Component; -import de.thpeetz.kontor.admin.services.ModuleService; import de.thpeetz.kontor.bookshelf.data.ArticleAuthorRepository; import de.thpeetz.kontor.bookshelf.data.Author; import de.thpeetz.kontor.bookshelf.data.AuthorRepository; @@ -36,47 +35,12 @@ public class SetupModuleBookshelf implements ApplicationListener volumes = volumeRepository.findAll(); - volumes.forEach(volume -> volumeRepository.delete(volume)); - moduleService.setDataImported(ComicConstants.COMICS); - } - - private Artist createArtistIfNotFound(String artistName) { - log.info("createArtistIfNotFound {}", artistName); - Artist artist = artistRepository.findByName(artistName); - if (artist == null) { - log.info("Artist {} not found, will create it", artistName); - artist = new Artist(); - artist.setName(artistName); - artistRepository.save(artist); - } - return artist; - } - - private Publisher createPublisherIfNotFound(String publisherName) { - log.info("createPublisherIfNotFound {}", publisherName); - Publisher publisher = publisherRepository.findByName(publisherName); - if (publisher == null) { - log.info("Publisher {} not found, will create it", publisherName); - publisher = new Publisher(); - publisher.setName(publisherName); - publisherRepository.save(publisher); - } - return publisher; - } - - private Worktype createWorktypeIfNotFound(String workTypeName) { - log.info("createWorktypeIfNotFound {}", workTypeName); - Worktype worktype = worktypeRepository.findByName(workTypeName); - if (worktype == null) { - log.info("Worktype {} not found, will create it", workTypeName); - worktype = new Worktype(); - worktype.setName(workTypeName); - worktypeRepository.save(worktype); - } - return worktype; - } - - private Comic createComicIfNotFound(Publisher publisher, String title, boolean currentOrder, boolean completed) { - log.info("createComicIfNotFound {} {} {} {}", publisher, title, currentOrder, completed); - Comic comic = comicRepository.findByTitleAndPublisher(title, publisher); - if (comic == null) { - log.info("Comic {} from {} not found, will create it", title, publisher.getName()); - comic = new Comic(); - comic.setTitle(title); - comic.setPublisher(publisher); - comic.setCurrentOrder(currentOrder); - comic.setCompleted(completed); - comicRepository.save(comic); - } - return comic; - } - - private ComicWork createComicWorkIfNotFound(Comic comic, Artist artist, Worktype worktype) { - log.info("createComicWorkIfNotFound {} {} {}", comic, artist, worktype); - ComicWork comicWork = comicWorkRepository.findbyComicAndArtistAndWorktype(comic, artist, worktype); - if (comicWork == null) { - log.info("ComicWork {} from {} for {} not found, will create it", worktype, artist, comic); - comicWork = new ComicWork(); - comicWork.setComic(comic); - comicWork.setArtist(artist); - comicWork.setWorkType(worktype); - comicWorkRepository.save(comicWork); - } - return comicWork; - } - - private void createStoryArcIfNotFound(String name, Comic comic) { - log.info("createStoryArcIfNotFound {} {}", comic, name); - StoryArc storyArc = storyArcRepository.findByNameAndComic(name, comic); - if (storyArc == null) { - log.info("StoryArc {} for {} not found, will create it", name, comic); - storyArc = new StoryArc(); - storyArc.setName(name); - storyArc.setComic(comic); - storyArcRepository.save(storyArc); - } - } - - private void createTradePaperbackIfNotFound(String name, Comic comic, int start, int end) { - log.info("createTradePaperbackIfNotFound {} {} {}-{}", comic, name, start, end); - TradePaperback tradePaperback = tradePaperbackRepository.findByFields(name, comic, start, end); - if (tradePaperback == null) { - log.info("TradePaperback {} for {} with issues {}-{} not found, will create it", name, comic, start, end); - tradePaperback = new TradePaperback(); - tradePaperback.setName(name); - tradePaperback.setComic(comic); - tradePaperback.setIssueStart(start); - tradePaperback.setIssueEnd(end); - tradePaperbackRepository.save(tradePaperback); - } - } - - private void createIssueIfNotFound(String issueNumber, Comic comic, boolean isRead, boolean inStock) { - log.info("createIssueIfNotFound {} {} {} {}", comic, issueNumber, isRead, inStock); - Issue issue = issueRepository.findByComicAndIssueNumber(comic, issueNumber); - if (issue == null) { - log.info("Issue {} for {} not found, will create it", issueNumber, comic); - issue = new Issue(); - issue.setIssueNumber(issueNumber); - issue.setComic(comic); - issue.setIsRead(isRead); - issue.setInStock(inStock); - issueRepository.save(issue); - } } } diff --git a/kontor-spring/src/main/java/de/thpeetz/kontor/media/SetupModuleMedia.java b/kontor-spring/src/main/java/de/thpeetz/kontor/media/SetupModuleMedia.java index 7c5671c..f6bb939 100644 --- a/kontor-spring/src/main/java/de/thpeetz/kontor/media/SetupModuleMedia.java +++ b/kontor-spring/src/main/java/de/thpeetz/kontor/media/SetupModuleMedia.java @@ -6,7 +6,6 @@ import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.stereotype.Component; import de.thpeetz.kontor.admin.services.AdminService; -import de.thpeetz.kontor.admin.services.ModuleService; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -18,9 +17,6 @@ public class SetupModuleMedia implements ApplicationListener