From 1460e261271eb334e58d974d54de4f3a4cc82fad Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 17 Feb 2020 10:22:26 +0400 Subject: [PATCH] remove papers --- .../ru/ulstu/deadline/service/DeadlineService.java | 4 ++++ .../java/ru/ulstu/paper/controller/PapersView.java | 1 + src/main/java/ru/ulstu/paper/model/Paper.java | 2 +- .../java/ru/ulstu/paper/service/PaperService.java | 10 +++++++--- .../resources/META-INF/resources/paper/papers.xhtml | 13 ++++++++++--- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java index 1611388..1fbd69f 100644 --- a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java +++ b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java @@ -67,4 +67,8 @@ public class DeadlineService { public Deadline createWithOffset(Date date, long value, ChronoUnit chronoUnit) { return create(DateUtils.localDateToDate(DateUtils.convertToLocalDate(date).plus(value, chronoUnit))); } + + public void delete(List deadlines) { + deadlineRepository.deleteInBatch(deadlines); + } } diff --git a/src/main/java/ru/ulstu/paper/controller/PapersView.java b/src/main/java/ru/ulstu/paper/controller/PapersView.java index 49c2c81..9720367 100644 --- a/src/main/java/ru/ulstu/paper/controller/PapersView.java +++ b/src/main/java/ru/ulstu/paper/controller/PapersView.java @@ -38,6 +38,7 @@ public class PapersView { public void deleteSelected() { paperService.delete(selectedPapers); + papers = paperService.findAll(); } public List getPaperStatuses() { diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 457cf82..c76acb8 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -99,7 +99,7 @@ public class Paper extends BaseEntity implements UserActivity, EventSource { @Temporal(TemporalType.TIMESTAMP) private Date updateDate = new Date(); - @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true) @JoinColumn(name = "paper_id", unique = true) @Fetch(FetchMode.SUBSELECT) @OrderBy("date") diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 2d83b51..072ed19 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -233,8 +233,7 @@ public class PaperService { @Transactional public void delete(Integer paperId) { - Paper paper = paperRepository.getOne(paperId); - paperRepository.delete(paper); + delete(paperRepository.getOne(paperId)); } public List getPaperStatuses() { @@ -439,6 +438,11 @@ public class PaperService { } public void delete(List papers) { - paperRepository.deleteInBatch(papers); + papers.forEach(paper -> delete(paper)); + } + + public void delete(Paper paper) { + deadlineService.delete(paper.getDeadlines()); + paperRepository.delete(paper); } } diff --git a/src/main/resources/META-INF/resources/paper/papers.xhtml b/src/main/resources/META-INF/resources/paper/papers.xhtml index 66e1049..845eabd 100644 --- a/src/main/resources/META-INF/resources/paper/papers.xhtml +++ b/src/main/resources/META-INF/resources/paper/papers.xhtml @@ -11,7 +11,8 @@ } + widgetVar="papersTable" emptyMessage="Не найдено подходящих статей" + selection="#{papersView.selectedPapers}" rowKey="#{paper.id}"> @@ -19,6 +20,11 @@ placeholder="Строка поиска..."/> + + + + + #{paper.title} @@ -41,9 +47,10 @@
- + update="messages @form"/>