#66 added handling of adding articles not added to the picker.

This commit is contained in:
Nightblade73 2019-04-16 10:42:40 +04:00
parent fbf9a7943b
commit dca644eba1
4 changed files with 40 additions and 2 deletions

View File

@ -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<Integer>()));
}
}
@ -87,6 +93,10 @@ public class ConferenceController {
return CONFERENCE_PAGE;
}
public List<Paper> getAllPapers(List<Integer> paperIds) {
return conferenceService.getConferencePapers(paperIds);
}
private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))

View File

@ -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<Conference> findAll() {
@ -78,6 +83,10 @@ public class ConferenceService {
conferenceDto.getDeadlines().remove((int) deadlineIndex);
}
public List<Paper> getConferencePapers(List<Integer> 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;
}

View File

@ -12,4 +12,6 @@ public interface PaperRepository extends JpaRepository<Paper, Integer> {
@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<Paper> filter(@Param("author") User author, @Param("year") Integer year);
List<Paper> findByIdNotIn(List<Integer> paperIds);
}

View File

@ -215,6 +215,19 @@ public class PaperService {
return new PaperDto(paperRepository.findOne(paperId));
}
public Paper findEntityById(Integer paperId) {
return paperRepository.findOne(paperId);
}
public List<Paper> findAllNotSelect(List<Integer> paperIds) {
if (!paperIds.isEmpty()) {
return sortPapers(paperRepository.findByIdNotIn(paperIds));
} else {
return sortPapers(paperRepository.findAll());
}
}
public List<User> getPaperAuthors() {
return userService.findAll();
}