From dca644eba1cca8079f5cfe7bcaa8c94c668d3c4b Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 16 Apr 2019 10:42:40 +0400 Subject: [PATCH] #66 added handling of adding articles not added to the picker. --- .../controller/ConferenceController.java | 12 +++++++++++- .../conference/service/ConferenceService.java | 15 ++++++++++++++- .../ulstu/paper/repository/PaperRepository.java | 2 ++ .../java/ru/ulstu/paper/service/PaperService.java | 13 +++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 1011c51..c4a2433 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -13,10 +13,13 @@ import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.paper.model.Paper; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; @@ -44,9 +47,12 @@ public class ConferenceController { @GetMapping("/conference") public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { - modelMap.put("conferenceDto", conferenceService.findOneDto(id)); + ConferenceDto conferenceDto = conferenceService.findOneDto(id); + modelMap.put("conferenceDto", conferenceDto); + modelMap.put("allPapers", getAllPapers(conferenceDto.getPaperIds())); } else { modelMap.put("conferenceDto", new ConferenceDto()); + modelMap.put("allPapers", getAllPapers(new ArrayList())); } } @@ -87,6 +93,10 @@ public class ConferenceController { return CONFERENCE_PAGE; } + public List getAllPapers(List paperIds) { + return conferenceService.getConferencePapers(paperIds); + } + private void filterEmptyDeadlines(ConferenceDto conferenceDto) { conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 84ae923..e95addb 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -7,6 +7,8 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.service.PaperService; import java.io.IOException; import java.util.List; @@ -20,11 +22,14 @@ public class ConferenceService { private final ConferenceRepository conferenceRepository; private final DeadlineService deadlineService; + private final PaperService paperService; public ConferenceService(ConferenceRepository conferenceRepository, - DeadlineService deadlineService) { + DeadlineService deadlineService, + PaperService paperService) { this.conferenceRepository = conferenceRepository; this.deadlineService = deadlineService; + this.paperService = paperService; } public List findAll() { @@ -78,6 +83,10 @@ public class ConferenceService { conferenceDto.getDeadlines().remove((int) deadlineIndex); } + public List getConferencePapers(List paperIds) { + return paperService.findAllNotSelect(paperIds); + } + private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); @@ -86,6 +95,10 @@ public class ConferenceService { conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); + if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) { + conferenceDto.getPaperIds().forEach(paperId -> + conference.getPapers().add(paperService.findEntityById(paperId))); + } return conference; } diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index 3951f53..343e9e2 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -12,4 +12,6 @@ public interface PaperRepository extends JpaRepository { @Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND (YEAR(p.createDate) = :year OR :year IS NULL)") List filter(@Param("author") User author, @Param("year") Integer year); + + List findByIdNotIn(List paperIds); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index a93c9c6..6c27c6e 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -215,6 +215,19 @@ public class PaperService { return new PaperDto(paperRepository.findOne(paperId)); } + public Paper findEntityById(Integer paperId) { + return paperRepository.findOne(paperId); + } + + public List findAllNotSelect(List paperIds) { + if (!paperIds.isEmpty()) { + return sortPapers(paperRepository.findByIdNotIn(paperIds)); + } else { + return sortPapers(paperRepository.findAll()); + } + + } + public List getPaperAuthors() { return userService.findAll(); }