#66 added handling of adding articles not added to the picker.
This commit is contained in:
parent
fbf9a7943b
commit
dca644eba1
@ -13,10 +13,13 @@ import ru.ulstu.conference.model.ConferenceDto;
|
|||||||
import ru.ulstu.conference.model.ConferenceFilterDto;
|
import ru.ulstu.conference.model.ConferenceFilterDto;
|
||||||
import ru.ulstu.conference.service.ConferenceService;
|
import ru.ulstu.conference.service.ConferenceService;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.paper.model.Paper;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.springframework.util.StringUtils.isEmpty;
|
import static org.springframework.util.StringUtils.isEmpty;
|
||||||
@ -44,9 +47,12 @@ public class ConferenceController {
|
|||||||
@GetMapping("/conference")
|
@GetMapping("/conference")
|
||||||
public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
||||||
if (id != null && id > 0) {
|
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 {
|
} else {
|
||||||
modelMap.put("conferenceDto", new ConferenceDto());
|
modelMap.put("conferenceDto", new ConferenceDto());
|
||||||
|
modelMap.put("allPapers", getAllPapers(new ArrayList<Integer>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +93,10 @@ public class ConferenceController {
|
|||||||
return CONFERENCE_PAGE;
|
return CONFERENCE_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Paper> getAllPapers(List<Integer> paperIds) {
|
||||||
|
return conferenceService.getConferencePapers(paperIds);
|
||||||
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
|
private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
|
||||||
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
|
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||||
|
@ -7,6 +7,8 @@ import ru.ulstu.conference.model.Conference;
|
|||||||
import ru.ulstu.conference.model.ConferenceDto;
|
import ru.ulstu.conference.model.ConferenceDto;
|
||||||
import ru.ulstu.conference.repository.ConferenceRepository;
|
import ru.ulstu.conference.repository.ConferenceRepository;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
import ru.ulstu.paper.service.PaperService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -20,11 +22,14 @@ public class ConferenceService {
|
|||||||
|
|
||||||
private final ConferenceRepository conferenceRepository;
|
private final ConferenceRepository conferenceRepository;
|
||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
|
private final PaperService paperService;
|
||||||
|
|
||||||
public ConferenceService(ConferenceRepository conferenceRepository,
|
public ConferenceService(ConferenceRepository conferenceRepository,
|
||||||
DeadlineService deadlineService) {
|
DeadlineService deadlineService,
|
||||||
|
PaperService paperService) {
|
||||||
this.conferenceRepository = conferenceRepository;
|
this.conferenceRepository = conferenceRepository;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
|
this.paperService = paperService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Conference> findAll() {
|
public List<Conference> findAll() {
|
||||||
@ -78,6 +83,10 @@ public class ConferenceService {
|
|||||||
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
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 {
|
private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
|
||||||
conference.setTitle(conferenceDto.getTitle());
|
conference.setTitle(conferenceDto.getTitle());
|
||||||
conference.setDescription(conferenceDto.getDescription());
|
conference.setDescription(conferenceDto.getDescription());
|
||||||
@ -86,6 +95,10 @@ public class ConferenceService {
|
|||||||
conference.setBeginDate(conferenceDto.getBeginDate());
|
conference.setBeginDate(conferenceDto.getBeginDate());
|
||||||
conference.setEndDate(conferenceDto.getEndDate());
|
conference.setEndDate(conferenceDto.getEndDate());
|
||||||
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
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;
|
return conference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)")
|
@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> filter(@Param("author") User author, @Param("year") Integer year);
|
||||||
|
|
||||||
|
List<Paper> findByIdNotIn(List<Integer> paperIds);
|
||||||
}
|
}
|
||||||
|
@ -215,6 +215,19 @@ public class PaperService {
|
|||||||
return new PaperDto(paperRepository.findOne(paperId));
|
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() {
|
public List<User> getPaperAuthors() {
|
||||||
return userService.findAll();
|
return userService.findAll();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user