WIP: Try vue #244
@ -4,8 +4,8 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
|||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import ru.ulstu.activity.api.model.ActivityDto;
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
import ru.ulstu.activity.paper.model.Paper;
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
@ -15,7 +15,6 @@ import javax.validation.constraints.Size;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
@ -39,12 +38,9 @@ public class ConferenceDto extends ActivityDto {
|
|||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date endDate = new Date();
|
private Date endDate = new Date();
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||||
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
private List<ScienceGroupMemberDto> userIds = new ArrayList<>();
|
||||||
private List<Integer> userIds = new ArrayList<>();
|
|
||||||
private List<Integer> paperIds = new ArrayList<>();
|
private List<Integer> paperIds = new ArrayList<>();
|
||||||
private List<Paper> papers = new ArrayList<>();
|
|
||||||
private List<Paper> notSelectedPapers = new ArrayList<>();
|
|
||||||
private List<ConferenceUser> users = new ArrayList<>();
|
private List<ConferenceUser> users = new ArrayList<>();
|
||||||
private boolean disabledTakePart = false;
|
private boolean disabledTakePart = false;
|
||||||
|
|
||||||
@ -56,13 +52,10 @@ public class ConferenceDto extends ActivityDto {
|
|||||||
@JsonProperty("ping") Integer ping,
|
@JsonProperty("ping") Integer ping,
|
||||||
@JsonProperty("beginDate") Date beginDate,
|
@JsonProperty("beginDate") Date beginDate,
|
||||||
@JsonProperty("endDate") Date endDate,
|
@JsonProperty("endDate") Date endDate,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
@JsonProperty("userIds") List<Integer> userIds,
|
@JsonProperty("userIds") List<ScienceGroupMemberDto> userIds,
|
||||||
@JsonProperty("paperIds") List<Integer> paperIds,
|
@JsonProperty("paperIds") List<Integer> paperIds,
|
||||||
@JsonProperty("users") List<ConferenceUser> users,
|
@JsonProperty("users") List<ConferenceUser> users) {
|
||||||
@JsonProperty("papers") List<Paper> papers,
|
|
||||||
@JsonProperty("notSelectedPapers") List<Paper> notSelectedPapers,
|
|
||||||
@JsonProperty("notSelectedPapers") Boolean disabledTakePart) {
|
|
||||||
super(id);
|
super(id);
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
@ -73,9 +66,7 @@ public class ConferenceDto extends ActivityDto {
|
|||||||
this.userIds = userIds;
|
this.userIds = userIds;
|
||||||
this.paperIds = paperIds;
|
this.paperIds = paperIds;
|
||||||
this.users = users;
|
this.users = users;
|
||||||
this.papers = papers;
|
this.title = title;
|
||||||
this.notSelectedPapers = notSelectedPapers;
|
|
||||||
this.disabledTakePart = disabledTakePart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto(Conference conference) {
|
public ConferenceDto(Conference conference) {
|
||||||
@ -86,11 +77,10 @@ public class ConferenceDto extends ActivityDto {
|
|||||||
this.ping = conference.getPing();
|
this.ping = conference.getPing();
|
||||||
this.beginDate = conference.getBeginDate();
|
this.beginDate = conference.getBeginDate();
|
||||||
this.endDate = conference.getEndDate();
|
this.endDate = conference.getEndDate();
|
||||||
this.deadlines = conference.getDeadlines();
|
this.deadlines = convert(conference.getDeadlines(), DeadlineDto::new);
|
||||||
this.userIds = convert(conference.getUsers(), BaseEntity::getId);
|
this.userIds = convert(conference.getUsers(), ScienceGroupMemberDto::new);
|
||||||
this.paperIds = convert(conference.getPapers(), BaseEntity::getId);
|
this.paperIds = convert(conference.getPapers(), BaseEntity::getId);
|
||||||
this.users = conference.getUsers();
|
this.users = conference.getUsers();
|
||||||
this.papers = conference.getPapers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto() {
|
public ConferenceDto() {
|
||||||
@ -153,19 +143,19 @@ public class ConferenceDto extends ActivityDto {
|
|||||||
this.endDate = endDate;
|
this.endDate = endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Deadline> getDeadlines() {
|
public List<DeadlineDto> getDeadlines() {
|
||||||
return deadlines;
|
return deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeadlines(List<Deadline> deadlines) {
|
public void setDeadlines(List<DeadlineDto> deadlines) {
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getUserIds() {
|
public List<ScienceGroupMemberDto> getUserIds() {
|
||||||
return userIds;
|
return userIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserIds(List<Integer> userIds) {
|
public void setUserIds(List<ScienceGroupMemberDto> userIds) {
|
||||||
this.userIds = userIds;
|
this.userIds = userIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,14 +167,6 @@ public class ConferenceDto extends ActivityDto {
|
|||||||
this.paperIds = paperIds;
|
this.paperIds = paperIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> getPapers() {
|
|
||||||
return papers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPapers(List<Paper> papers) {
|
|
||||||
this.papers = papers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ConferenceUser> getUsers() {
|
public List<ConferenceUser> getUsers() {
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
@ -200,54 +182,4 @@ public class ConferenceDto extends ActivityDto {
|
|||||||
public void setDisabledTakePart(boolean disabledTakePart) {
|
public void setDisabledTakePart(boolean disabledTakePart) {
|
||||||
this.disabledTakePart = disabledTakePart;
|
this.disabledTakePart = disabledTakePart;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getRemovedDeadlineIds() {
|
|
||||||
return removedDeadlineIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
|
||||||
this.removedDeadlineIds = removedDeadlineIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Paper> getNotSelectedPapers() {
|
|
||||||
return notSelectedPapers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNotSelectedPapers(List<Paper> notSelectedPapers) {
|
|
||||||
this.notSelectedPapers = notSelectedPapers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDatesString() {
|
|
||||||
return BEGIN_DATE + beginDate.toString().split(" ")[0] + " " + END_DATE + endDate.toString().split(" ")[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (o == null || getClass() != o.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ConferenceDto that = (ConferenceDto) o;
|
|
||||||
return ping == that.ping &&
|
|
||||||
disabledTakePart == that.disabledTakePart &&
|
|
||||||
Objects.equals(id, that.id) &&
|
|
||||||
Objects.equals(title, that.title) &&
|
|
||||||
Objects.equals(description, that.description) &&
|
|
||||||
Objects.equals(url, that.url) &&
|
|
||||||
Objects.equals(deadlines, that.deadlines) &&
|
|
||||||
Objects.equals(removedDeadlineIds, that.removedDeadlineIds) &&
|
|
||||||
Objects.equals(userIds, that.userIds) &&
|
|
||||||
Objects.equals(paperIds, that.paperIds) &&
|
|
||||||
Objects.equals(papers, that.papers) &&
|
|
||||||
Objects.equals(notSelectedPapers, that.notSelectedPapers) &&
|
|
||||||
Objects.equals(users, that.users);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(id, title, description, url, ping, beginDate, endDate, deadlines, removedDeadlineIds,
|
|
||||||
userIds, paperIds, papers, notSelectedPapers, users, disabledTakePart);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,13 @@ package ru.ulstu.activity.conference.service;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.Errors;
|
|
||||||
import ru.ulstu.activity.common.service.ActivityService;
|
import ru.ulstu.activity.common.service.ActivityService;
|
||||||
import ru.ulstu.activity.conference.model.Conference;
|
import ru.ulstu.activity.conference.model.Conference;
|
||||||
import ru.ulstu.activity.conference.model.ConferenceDashboardDto;
|
import ru.ulstu.activity.conference.model.ConferenceDashboardDto;
|
||||||
import ru.ulstu.activity.conference.model.ConferenceDto;
|
import ru.ulstu.activity.conference.model.ConferenceDto;
|
||||||
import ru.ulstu.activity.conference.model.ConferenceFilterDto;
|
import ru.ulstu.activity.conference.model.ConferenceFilterDto;
|
||||||
import ru.ulstu.activity.conference.model.ConferenceListDto;
|
import ru.ulstu.activity.conference.model.ConferenceListDto;
|
||||||
import ru.ulstu.activity.conference.model.ConferenceUser;
|
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
|
||||||
import ru.ulstu.activity.deadline.service.DeadlineService;
|
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.activity.paper.model.Paper;
|
|
||||||
import ru.ulstu.activity.paper.service.PaperService;
|
import ru.ulstu.activity.paper.service.PaperService;
|
||||||
import ru.ulstu.activity.ping.service.PingService;
|
import ru.ulstu.activity.ping.service.PingService;
|
||||||
import ru.ulstu.activity.timeline.service.EventService;
|
import ru.ulstu.activity.timeline.service.EventService;
|
||||||
@ -23,12 +19,9 @@ import ru.ulstu.user.model.User;
|
|||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
@ -63,31 +56,6 @@ public class ConferenceService extends ActivityService<ConferenceListDto, Confer
|
|||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto getExistConferenceById(Integer id) {
|
|
||||||
ConferenceDto conferenceDto = new ConferenceDto(conferenceRepository.getOne(id));
|
|
||||||
conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds()));
|
|
||||||
conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers()));
|
|
||||||
return conferenceDto;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean save(ConferenceDto conferenceDto, Errors errors) throws IOException {
|
|
||||||
conferenceDto.setTitle(conferenceDto.getTitle());
|
|
||||||
filterEmptyDeadlines(conferenceDto);
|
|
||||||
checkEmptyFieldsOfDeadline(conferenceDto, errors);
|
|
||||||
checkEmptyFieldsOfDates(conferenceDto, errors);
|
|
||||||
if (!checkUniqueName(conferenceDto.getTitle(), conferenceDto.getId())) {
|
|
||||||
throw new RuntimeException("Название не уникально");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isEmpty(conferenceDto.getId())) {
|
|
||||||
create(conferenceDto);
|
|
||||||
} else {
|
|
||||||
update(conferenceDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public ConferenceDto update(ConferenceDto conferenceDto) {
|
public ConferenceDto update(ConferenceDto conferenceDto) {
|
||||||
@ -124,58 +92,6 @@ public class ConferenceService extends ActivityService<ConferenceListDto, Confer
|
|||||||
return new ConferenceDto(entity);
|
return new ConferenceDto(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto addDeadline(ConferenceDto conferenceDto) {
|
|
||||||
conferenceDto.getDeadlines().add(new Deadline());
|
|
||||||
return conferenceDto;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ConferenceDto removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
|
|
||||||
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
|
|
||||||
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
|
|
||||||
}
|
|
||||||
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
|
||||||
return conferenceDto;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConferenceDto addPaper(ConferenceDto conferenceDto) {
|
|
||||||
Paper paper = new Paper();
|
|
||||||
paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime());
|
|
||||||
paper.setStatus(Paper.PaperStatus.DRAFT);
|
|
||||||
conferenceDto.getPapers().add(paper);
|
|
||||||
return conferenceDto;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConferenceDto removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException {
|
|
||||||
Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex);
|
|
||||||
if (removedPaper.getId() != null) {
|
|
||||||
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
|
||||||
}
|
|
||||||
return conferenceDto;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConferenceDto takePart(ConferenceDto conferenceDto) throws IOException {
|
|
||||||
conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser()));
|
|
||||||
conferenceDto.setDisabledTakePart(true);
|
|
||||||
return conferenceDto;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Paper> getNotSelectPapers(List<Integer> paperIds) {
|
|
||||||
return paperService.findAllNotSelect(paperIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<User> getAllUsers() {
|
|
||||||
return userService.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ConferenceUser.Participation> getAllParticipations() {
|
|
||||||
return Arrays.asList(ConferenceUser.Participation.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ConferenceUser.Deposit> getAllDeposit() {
|
|
||||||
return Arrays.asList(ConferenceUser.Deposit.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
|
protected Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
|
||||||
conference.setTitle(conferenceDto.getTitle());
|
conference.setTitle(conferenceDto.getTitle());
|
||||||
conference.setDescription(conferenceDto.getDescription());
|
conference.setDescription(conferenceDto.getDescription());
|
||||||
@ -183,7 +99,7 @@ public class ConferenceService extends ActivityService<ConferenceListDto, Confer
|
|||||||
conference.setBeginDate(conferenceDto.getBeginDate());
|
conference.setBeginDate(conferenceDto.getBeginDate());
|
||||||
conference.setEndDate(conferenceDto.getEndDate());
|
conference.setEndDate(conferenceDto.getEndDate());
|
||||||
conference.getPapers().clear();
|
conference.getPapers().clear();
|
||||||
conferenceDto.getPapers().forEach(paper -> conference.getPapers().add(paper.getId() != null ? paperService.findById(paper.getId()) : paperService.create(paper)));
|
conferenceDto.getPaperIds().forEach(paperId -> conference.getPapers().add(paperService.findById(paperId)));
|
||||||
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
||||||
conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers()));
|
conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers()));
|
||||||
if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
|
if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
|
||||||
@ -193,11 +109,6 @@ public class ConferenceService extends ActivityService<ConferenceListDto, Confer
|
|||||||
return conference;
|
return conference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) {
|
|
||||||
return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ConferenceDto> filter(ConferenceFilterDto conferenceFilterDto) {
|
public List<ConferenceDto> filter(ConferenceFilterDto conferenceFilterDto) {
|
||||||
return convert(conferenceRepository.findByUserAndYear(
|
return convert(conferenceRepository.findByUserAndYear(
|
||||||
conferenceFilterDto.getFilterUserId() == null ? null : userService.findById(conferenceFilterDto.getFilterUserId()),
|
conferenceFilterDto.getFilterUserId() == null ? null : userService.findById(conferenceFilterDto.getFilterUserId()),
|
||||||
@ -215,10 +126,6 @@ public class ConferenceService extends ActivityService<ConferenceListDto, Confer
|
|||||||
return new PageableItems<>(activeConferencePage.getTotalElements(), activeConferencePage.getContent());
|
return new PageableItems<>(activeConferencePage.getTotalElements(), activeConferencePage.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAttachedToConference(Integer paperId) {
|
|
||||||
return conferenceRepository.isPaperAttached(paperId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConferenceDto findConferenceById(Integer id) {
|
public ConferenceDto findConferenceById(Integer id) {
|
||||||
return new ConferenceDto(findById(id));
|
return new ConferenceDto(findById(id));
|
||||||
}
|
}
|
||||||
@ -227,46 +134,6 @@ public class ConferenceService extends ActivityService<ConferenceListDto, Confer
|
|||||||
return conferenceRepository.getOne(id);
|
return conferenceRepository.getOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotificationAfterUpdateDeadlines(Conference conference, List<Deadline> oldDeadlines) {
|
|
||||||
if (oldDeadlines.size() != conference.getDeadlines().size()) {
|
|
||||||
conferenceNotificationService.updateDeadlineNotification(conference);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conference.getDeadlines()
|
|
||||||
.stream()
|
|
||||||
.filter(deadline -> !oldDeadlines.contains(deadline))
|
|
||||||
.count() > 0) {
|
|
||||||
conferenceNotificationService.updateDeadlineNotification(conference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Deadline copyDeadline(Deadline oldDeadline) {
|
|
||||||
Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription());
|
|
||||||
newDeadline.setId(oldDeadline.getId());
|
|
||||||
return newDeadline;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkEmptyFieldsOfDeadline(ConferenceDto conferenceDto, Errors errors) {
|
|
||||||
for (Deadline deadline : conferenceDto.getDeadlines()) {
|
|
||||||
if (deadline.getDate() == null || deadline.getDescription().isEmpty()) {
|
|
||||||
errors.rejectValue("deadlines", "errorCode", "Все поля дедлайна должны быть заполнены");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkEmptyFieldsOfDates(ConferenceDto conferenceDto, Errors errors) {
|
|
||||||
if (conferenceDto.getBeginDate() == null || conferenceDto.getEndDate() == null) {
|
|
||||||
errors.rejectValue("beginDate", "errorCode", "Даты должны быть заполнены");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void filterEmptyDeadlines(ConferenceDto conferenceDto) {
|
|
||||||
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
|
|
||||||
.filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Conference getActiveConferenceByUser(User user) {
|
public Conference getActiveConferenceByUser(User user) {
|
||||||
return conferenceRepository.findActiveByUser(user);
|
return conferenceRepository.findActiveByUser(user);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public class Deadline extends BaseEntity {
|
|||||||
this.executors = executors;
|
this.executors = executors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getDone() {
|
public Boolean isDone() {
|
||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
package ru.ulstu.activity.deadline.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class DeadlineDto {
|
||||||
|
private final Integer id;
|
||||||
|
private final Date date;
|
||||||
|
private final String description;
|
||||||
|
private final List<Integer> executorsIds;
|
||||||
|
private final Boolean done;
|
||||||
|
|
||||||
|
public DeadlineDto() {
|
||||||
|
this.id = null;
|
||||||
|
this.date = null;
|
||||||
|
this.description = null;
|
||||||
|
this.executorsIds = new ArrayList<>();
|
||||||
|
this.done = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeadlineDto(Deadline deadline) {
|
||||||
|
this.id = deadline.getId();
|
||||||
|
this.date = deadline.getDate();
|
||||||
|
this.description = deadline.getDescription();
|
||||||
|
this.executorsIds = deadline.getExecutors()
|
||||||
|
.stream()
|
||||||
|
.map(executor -> executor.getId())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
this.done = deadline.isDone();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeadlineDto(Date date, String description) {
|
||||||
|
this.id = null;
|
||||||
|
this.date = date;
|
||||||
|
this.description = description;
|
||||||
|
this.executorsIds = new ArrayList<>();
|
||||||
|
this.done = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getExecutorsIds() {
|
||||||
|
return executorsIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean isDone() {
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,8 @@ package ru.ulstu.activity.deadline.service;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -11,12 +13,15 @@ import java.util.stream.Collectors;
|
|||||||
@Service
|
@Service
|
||||||
public class DeadlineService {
|
public class DeadlineService {
|
||||||
private final DeadlineRepository deadlineRepository;
|
private final DeadlineRepository deadlineRepository;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
public DeadlineService(DeadlineRepository deadlineRepository) {
|
public DeadlineService(DeadlineRepository deadlineRepository,
|
||||||
|
UserService userService) {
|
||||||
this.deadlineRepository = deadlineRepository;
|
this.deadlineRepository = deadlineRepository;
|
||||||
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Deadline> saveOrCreate(List<Deadline> deadlines) {
|
public List<Deadline> saveOrCreate(List<DeadlineDto> deadlines) {
|
||||||
return deadlines
|
return deadlines
|
||||||
.stream()
|
.stream()
|
||||||
.map(deadline -> {
|
.map(deadline -> {
|
||||||
@ -25,16 +30,17 @@ public class DeadlineService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Deadline update(Deadline deadline) {
|
public Deadline update(DeadlineDto deadlineDto) {
|
||||||
Deadline updateDeadline = deadlineRepository.getOne(deadline.getId());
|
Deadline updateDeadline = deadlineRepository.getOne(deadlineDto.getId());
|
||||||
updateDeadline.setDate(deadline.getDate());
|
deadlineRepository.save(copyFromDto(updateDeadline, deadlineDto));
|
||||||
updateDeadline.setDescription(deadline.getDescription());
|
|
||||||
updateDeadline.setExecutors(deadline.getExecutors());
|
|
||||||
updateDeadline.setDone(deadline.getDone());
|
|
||||||
deadlineRepository.save(updateDeadline);
|
|
||||||
return updateDeadline;
|
return updateDeadline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Deadline create(DeadlineDto deadlineDto) {
|
||||||
|
return deadlineRepository.save(copyFromDto(new Deadline(), deadlineDto));
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Deadline create(Deadline deadline) {
|
public Deadline create(Deadline deadline) {
|
||||||
return deadlineRepository.save(deadline);
|
return deadlineRepository.save(deadline);
|
||||||
@ -45,6 +51,14 @@ public class DeadlineService {
|
|||||||
deadlineRepository.deleteById(deadlineId);
|
deadlineRepository.deleteById(deadlineId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Deadline copyFromDto(Deadline deadline, DeadlineDto deadlineDto) {
|
||||||
|
deadline.setDate(deadlineDto.getDate());
|
||||||
|
deadline.setDescription(deadlineDto.getDescription());
|
||||||
|
deadline.setExecutors(userService.findByIds(deadlineDto.getExecutorsIds()));
|
||||||
|
deadline.setDone(deadlineDto.isDone());
|
||||||
|
return deadline;
|
||||||
|
}
|
||||||
|
|
||||||
public Date findByGrantIdAndDate(Integer id, Date date) {
|
public Date findByGrantIdAndDate(Integer id, Date date) {
|
||||||
return deadlineRepository.findByGrantIdAndDate(id, date);
|
return deadlineRepository.findByGrantIdAndDate(id, date);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class GrantController implements ActivityController<GrantListDto, GrantDa
|
|||||||
this.grantService = grantService;
|
this.grantService = grantService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/grab")
|
@GetMapping("grab")
|
||||||
public void grab() throws IOException, ParseException {
|
public void grab() throws IOException, ParseException {
|
||||||
grantService.createFromKias();
|
grantService.createFromKias();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
|||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import ru.ulstu.activity.api.model.ActivityDto;
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
import ru.ulstu.activity.file.model.FileDataDto;
|
import ru.ulstu.activity.file.model.FileDataDto;
|
||||||
import ru.ulstu.activity.paper.model.PaperDto;
|
import ru.ulstu.activity.paper.model.PaperDto;
|
||||||
import ru.ulstu.activity.project.model.ProjectDto;
|
import ru.ulstu.activity.project.model.ProjectDto;
|
||||||
@ -21,27 +21,20 @@ public class GrantDto extends ActivityDto {
|
|||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String title;
|
private String title;
|
||||||
private Grant.GrantStatus status;
|
private Grant.GrantStatus status;
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||||
private String comment;
|
private String comment;
|
||||||
private List<FileDataDto> files = new ArrayList<>();
|
private List<FileDataDto> files = new ArrayList<>();
|
||||||
private ProjectDto project;
|
private List<Integer> projectIds;
|
||||||
private Set<Integer> authorIds;
|
private Set<Integer> authorIds;
|
||||||
private Set<ScienceGroupMemberDto> members;
|
private Set<ScienceGroupMemberDto> members;
|
||||||
private Integer leaderId;
|
private Integer leaderId;
|
||||||
private boolean wasLeader;
|
|
||||||
private boolean hasAge;
|
|
||||||
private boolean hasDegree;
|
|
||||||
private boolean hasBAKPapers;
|
|
||||||
private boolean hasScopusPapers;
|
|
||||||
private List<Integer> paperIds = new ArrayList<>();
|
private List<Integer> paperIds = new ArrayList<>();
|
||||||
private List<PaperDto> papers = new ArrayList<>();
|
|
||||||
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public GrantDto(@JsonProperty("id") Integer id,
|
public GrantDto(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("title") String title,
|
@JsonProperty("title") String title,
|
||||||
@JsonProperty("status") Grant.GrantStatus status,
|
@JsonProperty("status") Grant.GrantStatus status,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
@JsonProperty("comment") String comment,
|
@JsonProperty("comment") String comment,
|
||||||
@JsonProperty("files") List<FileDataDto> files,
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
@JsonProperty("project") ProjectDto project,
|
@JsonProperty("project") ProjectDto project,
|
||||||
@ -59,15 +52,10 @@ public class GrantDto extends ActivityDto {
|
|||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.files = files;
|
this.files = files;
|
||||||
this.project = project;
|
|
||||||
this.authorIds = authorIds;
|
this.authorIds = authorIds;
|
||||||
this.members = members;
|
this.members = members;
|
||||||
this.leaderId = leaderId;
|
this.leaderId = leaderId;
|
||||||
this.wasLeader = wasLeader;
|
|
||||||
this.hasAge = hasAge;
|
|
||||||
this.hasDegree = hasDegree;
|
|
||||||
this.paperIds = paperIds;
|
this.paperIds = paperIds;
|
||||||
this.papers = papers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GrantDto(Integer id) {
|
public GrantDto(Integer id) {
|
||||||
@ -78,24 +66,19 @@ public class GrantDto extends ActivityDto {
|
|||||||
super(grant.getId());
|
super(grant.getId());
|
||||||
this.title = grant.getTitle();
|
this.title = grant.getTitle();
|
||||||
this.status = grant.getStatus();
|
this.status = grant.getStatus();
|
||||||
this.deadlines = grant.getDeadlines();
|
this.deadlines = convert(grant.getDeadlines(), DeadlineDto::new);
|
||||||
this.comment = grant.getComment();
|
this.comment = grant.getComment();
|
||||||
this.files = convert(grant.getFiles(), FileDataDto::new);
|
this.files = convert(grant.getFiles(), FileDataDto::new);
|
||||||
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
|
|
||||||
this.authorIds = convert(grant.getAuthors(), user -> user.getId());
|
this.authorIds = convert(grant.getAuthors(), user -> user.getId());
|
||||||
this.members = convert(grant.getAuthors(), ScienceGroupMemberDto::new);
|
this.members = convert(grant.getAuthors(), ScienceGroupMemberDto::new);
|
||||||
this.leaderId = grant.getLeader().getId();
|
this.leaderId = grant.getLeader().getId();
|
||||||
this.wasLeader = false;
|
|
||||||
this.hasAge = false;
|
|
||||||
this.hasDegree = false;
|
|
||||||
this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
|
this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
|
||||||
this.papers = convert(grant.getPapers(), PaperDto::new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GrantDto(String grantTitle, Date deadLineDate) {
|
public GrantDto(String grantTitle, Date deadlineDate) {
|
||||||
super(null);
|
super(null);
|
||||||
this.title = grantTitle;
|
this.title = grantTitle;
|
||||||
this.deadlines.add(new Deadline(deadLineDate, "Окончание приёма заявок"));
|
this.deadlines.add(new DeadlineDto(deadlineDate, "Окончание приёма заявок"));
|
||||||
this.status = Grant.GrantStatus.LOADED_FROM_KIAS;
|
this.status = Grant.GrantStatus.LOADED_FROM_KIAS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,11 +102,11 @@ public class GrantDto extends ActivityDto {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Deadline> getDeadlines() {
|
public List<DeadlineDto> getDeadlines() {
|
||||||
return deadlines;
|
return deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeadlines(List<Deadline> deadlines) {
|
public void setDeadlines(List<DeadlineDto> deadlines) {
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,14 +126,6 @@ public class GrantDto extends ActivityDto {
|
|||||||
this.files = files;
|
this.files = files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectDto getProject() {
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProject(ProjectDto project) {
|
|
||||||
this.project = project;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getAuthorIds() {
|
public Set<Integer> getAuthorIds() {
|
||||||
return authorIds;
|
return authorIds;
|
||||||
}
|
}
|
||||||
@ -175,30 +150,6 @@ public class GrantDto extends ActivityDto {
|
|||||||
this.leaderId = leaderId;
|
this.leaderId = leaderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWasLeader() {
|
|
||||||
return wasLeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWasLeader(boolean wasLeader) {
|
|
||||||
this.wasLeader = wasLeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHasAge() {
|
|
||||||
return hasAge;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHasAge(boolean hasAge) {
|
|
||||||
this.hasAge = hasAge;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHasDegree() {
|
|
||||||
return hasDegree;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHasDegree(boolean hasDegree) {
|
|
||||||
this.hasDegree = hasDegree;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getPaperIds() {
|
public List<Integer> getPaperIds() {
|
||||||
return paperIds;
|
return paperIds;
|
||||||
}
|
}
|
||||||
@ -207,35 +158,7 @@ public class GrantDto extends ActivityDto {
|
|||||||
this.paperIds = paperIds;
|
this.paperIds = paperIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperDto> getPapers() {
|
public List<Integer> getProjectIds() {
|
||||||
return papers;
|
return projectIds;
|
||||||
}
|
|
||||||
|
|
||||||
public void setPapers(List<PaperDto> papers) {
|
|
||||||
this.papers = papers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getRemovedDeadlineIds() {
|
|
||||||
return removedDeadlineIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
|
||||||
this.removedDeadlineIds = removedDeadlineIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHasBAKPapers() {
|
|
||||||
return hasBAKPapers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHasBAKPapers(boolean hasBAKPapers) {
|
|
||||||
this.hasBAKPapers = hasBAKPapers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHasScopusPapers() {
|
|
||||||
return hasScopusPapers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHasScopusPapers(boolean hasScopusPapers) {
|
|
||||||
this.hasScopusPapers = hasScopusPapers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ru.ulstu.activity.grant.service;
|
package ru.ulstu.activity.grant.service;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
@ -8,7 +7,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import ru.ulstu.activity.common.service.ActivityService;
|
import ru.ulstu.activity.common.service.ActivityService;
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
|
||||||
import ru.ulstu.activity.deadline.service.DeadlineService;
|
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.activity.file.service.FileService;
|
import ru.ulstu.activity.file.service.FileService;
|
||||||
import ru.ulstu.activity.grant.model.Grant;
|
import ru.ulstu.activity.grant.model.Grant;
|
||||||
@ -30,13 +28,10 @@ import ru.ulstu.user.service.UserService;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
|
||||||
import static ru.ulstu.activity.grant.model.Grant.GrantStatus.APPLICATION;
|
import static ru.ulstu.activity.grant.model.Grant.GrantStatus.APPLICATION;
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
@ -114,9 +109,6 @@ public class GrantService extends ActivityService<GrantListDto, Grant, GrantDto>
|
|||||||
grant.setComment(grantDto.getComment());
|
grant.setComment(grantDto.getComment());
|
||||||
grant.setStatus(grantDto.getStatus() == null ? APPLICATION : grantDto.getStatus());
|
grant.setStatus(grantDto.getStatus() == null ? APPLICATION : grantDto.getStatus());
|
||||||
grant.setTitle(grantDto.getTitle());
|
grant.setTitle(grantDto.getTitle());
|
||||||
if (grantDto.getProject() != null && grantDto.getProject().getId() != null) {
|
|
||||||
grant.setProject(projectService.findById(grantDto.getProject().getId()));
|
|
||||||
}
|
|
||||||
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
||||||
if (!grant.getFiles().isEmpty()) {
|
if (!grant.getFiles().isEmpty()) {
|
||||||
grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream()
|
grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream()
|
||||||
@ -151,23 +143,6 @@ public class GrantService extends ActivityService<GrantListDto, Grant, GrantDto>
|
|||||||
return Arrays.asList(Grant.GrantStatus.values());
|
return Arrays.asList(Grant.GrantStatus.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean save(GrantDto grantDto, Errors errors) throws IOException {
|
|
||||||
grantDto.setTitle(grantDto.getTitle());
|
|
||||||
filterEmptyDeadlines(grantDto);
|
|
||||||
checkEmptyDeadlines(grantDto, errors);
|
|
||||||
checkEmptyLeader(grantDto, errors);
|
|
||||||
checkUniqueName(grantDto.getTitle(), grantDto.getId());
|
|
||||||
if (errors.hasErrors()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (isEmpty(grantDto.getId())) {
|
|
||||||
create(grantDto);
|
|
||||||
} else {
|
|
||||||
update(grantDto);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean saveFromKias(GrantDto grantDto) throws IOException {
|
private boolean saveFromKias(GrantDto grantDto) throws IOException {
|
||||||
grantDto.setTitle(grantDto.getTitle());
|
grantDto.setTitle(grantDto.getTitle());
|
||||||
if (checkUniqueName(grantDto.getTitle(), grantDto.getId())) {
|
if (checkUniqueName(grantDto.getTitle(), grantDto.getId())) {
|
||||||
@ -202,33 +177,6 @@ public class GrantService extends ActivityService<GrantListDto, Grant, GrantDto>
|
|||||||
return foundGrantDate != null && foundGrantDate.compareTo(date) == 0;
|
return foundGrantDate != null && foundGrantDate.compareTo(date) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> getGrantAuthors(GrantDto grantDto) {
|
|
||||||
List<User> filteredUsers = userService.filterByAgeAndDegree(grantDto.isHasAge(), grantDto.isHasDegree());
|
|
||||||
if (grantDto.isWasLeader()) {
|
|
||||||
filteredUsers = checkContains(filteredUsers, getCompletedGrantLeaders());
|
|
||||||
}
|
|
||||||
if (grantDto.isHasBAKPapers()) {
|
|
||||||
filteredUsers = checkContains(filteredUsers, getBAKAuthors());
|
|
||||||
}
|
|
||||||
if (grantDto.isHasScopusPapers()) {
|
|
||||||
filteredUsers = checkContains(filteredUsers, getScopusAuthors());
|
|
||||||
}
|
|
||||||
return filteredUsers;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<User> checkContains(List<User> filteredUsers, List<User> checkUsers) {
|
|
||||||
return filteredUsers.stream()
|
|
||||||
.filter(checkUsers::contains)
|
|
||||||
.collect(toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<User> getCompletedGrantLeaders() {
|
|
||||||
return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED)
|
|
||||||
.stream()
|
|
||||||
.map(Grant::getLeader)
|
|
||||||
.collect(toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<PaperDto> getGrantPapers(List<Integer> paperIds) {
|
public List<PaperDto> getGrantPapers(List<Integer> paperIds) {
|
||||||
return paperService.findAllSelect(paperIds);
|
return paperService.findAllSelect(paperIds);
|
||||||
}
|
}
|
||||||
@ -237,24 +185,6 @@ public class GrantService extends ActivityService<GrantListDto, Grant, GrantDto>
|
|||||||
return paperService.findAllNotCompleted();
|
return paperService.findAllNotCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperDto> attachPaper(GrantDto grantDto) {
|
|
||||||
if (!grantDto.getPaperIds().isEmpty()) {
|
|
||||||
grantDto.getPapers().clear();
|
|
||||||
grantDto.setPapers(getGrantPapers(grantDto.getPaperIds()));
|
|
||||||
} else {
|
|
||||||
grantDto.getPapers().clear();
|
|
||||||
}
|
|
||||||
return grantDto.getPapers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GrantDto removeDeadline(GrantDto grantDto, Integer deadlineId) {
|
|
||||||
if (grantDto.getDeadlines().get(deadlineId).getId() != null) {
|
|
||||||
grantDto.getRemovedDeadlineIds().add(grantDto.getDeadlines().get(deadlineId).getId());
|
|
||||||
}
|
|
||||||
grantDto.getDeadlines().remove((int) deadlineId);
|
|
||||||
return grantDto;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<User> getCompletedPapersAuthors(Paper.PaperType type) {
|
private List<User> getCompletedPapersAuthors(Paper.PaperType type) {
|
||||||
List<Paper> papers = paperService.findAllCompletedByType(type);
|
List<Paper> papers = paperService.findAllCompletedByType(type);
|
||||||
return papers.stream()
|
return papers.stream()
|
||||||
@ -263,28 +193,6 @@ public class GrantService extends ActivityService<GrantListDto, Grant, GrantDto>
|
|||||||
.collect(toList());
|
.collect(toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<User> getBAKAuthors() {
|
|
||||||
return getCompletedPapersAuthors(Paper.PaperType.VAK)
|
|
||||||
.stream()
|
|
||||||
.distinct()
|
|
||||||
.collect(toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<User> getScopusAuthors() {
|
|
||||||
List<User> authors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS);
|
|
||||||
return authors
|
|
||||||
.stream()
|
|
||||||
.filter(author -> Collections.frequency(authors, author) > 3)
|
|
||||||
.collect(toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Deadline> filterEmptyDeadlines(GrantDto grantDto) {
|
|
||||||
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
|
||||||
.filter(dto -> dto.getDate() != null || !StringUtils.isEmpty(dto.getDescription()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
return grantDto.getDeadlines();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void createFromKias() throws IOException, ParseException {
|
public void createFromKias() throws IOException, ParseException {
|
||||||
for (GrantDto grantDto : kiasService.getNewGrantsDto()) {
|
for (GrantDto grantDto : kiasService.getNewGrantsDto()) {
|
||||||
|
@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
|||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import ru.ulstu.activity.api.model.ActivityDto;
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
import ru.ulstu.activity.file.model.FileDataDto;
|
import ru.ulstu.activity.file.model.FileDataDto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
@ -25,7 +25,7 @@ public class PaperDto extends ActivityDto {
|
|||||||
private Date createDate;
|
private Date createDate;
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||||
private String comment;
|
private String comment;
|
||||||
private String url;
|
private String url;
|
||||||
private Boolean locked;
|
private Boolean locked;
|
||||||
@ -45,7 +45,7 @@ public class PaperDto extends ActivityDto {
|
|||||||
@JsonProperty("type") Paper.PaperType type,
|
@JsonProperty("type") Paper.PaperType type,
|
||||||
@JsonProperty("createDate") Date createDate,
|
@JsonProperty("createDate") Date createDate,
|
||||||
@JsonProperty("updateDate") Date updateDate,
|
@JsonProperty("updateDate") Date updateDate,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
@JsonProperty("comment") String comment,
|
@JsonProperty("comment") String comment,
|
||||||
@JsonProperty("url") String url,
|
@JsonProperty("url") String url,
|
||||||
@JsonProperty("locked") Boolean locked,
|
@JsonProperty("locked") Boolean locked,
|
||||||
@ -72,7 +72,7 @@ public class PaperDto extends ActivityDto {
|
|||||||
this.type = paper.getType();
|
this.type = paper.getType();
|
||||||
this.createDate = paper.getCreateDate();
|
this.createDate = paper.getCreateDate();
|
||||||
this.updateDate = paper.getUpdateDate();
|
this.updateDate = paper.getUpdateDate();
|
||||||
this.deadlines = paper.getDeadlines();
|
this.deadlines = convert(paper.getDeadlines(), DeadlineDto::new);
|
||||||
this.comment = paper.getComment();
|
this.comment = paper.getComment();
|
||||||
this.url = paper.getUrl();
|
this.url = paper.getUrl();
|
||||||
this.locked = paper.getLocked();
|
this.locked = paper.getLocked();
|
||||||
@ -120,11 +120,11 @@ public class PaperDto extends ActivityDto {
|
|||||||
this.updateDate = updateDate;
|
this.updateDate = updateDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Deadline> getDeadlines() {
|
public List<DeadlineDto> getDeadlines() {
|
||||||
return deadlines;
|
return deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeadlines(List<Deadline> deadlines) {
|
public void setDeadlines(List<DeadlineDto> deadlines) {
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,9 @@ package ru.ulstu.activity.project.model;
|
|||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import ru.ulstu.activity.api.model.ActivityDto;
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
import ru.ulstu.activity.file.model.FileDataDto;
|
import ru.ulstu.activity.file.model.FileDataDto;
|
||||||
import ru.ulstu.activity.grant.model.GrantDto;
|
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.model.UserDto;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -22,28 +20,22 @@ public class ProjectDto extends ActivityDto {
|
|||||||
private String title;
|
private String title;
|
||||||
private Project.ProjectStatus status;
|
private Project.ProjectStatus status;
|
||||||
private String description;
|
private String description;
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||||
private String repository;
|
private String repository;
|
||||||
private List<FileDataDto> files = new ArrayList<>();
|
private List<FileDataDto> files = new ArrayList<>();
|
||||||
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
|
||||||
private Set<Integer> executorIds;
|
private Set<Integer> executorIds;
|
||||||
private List<UserDto> executors;
|
|
||||||
private List<Integer> grantIds;
|
private List<Integer> grantIds;
|
||||||
private List<GrantDto> grants;
|
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public ProjectDto(@JsonProperty("id") Integer id,
|
public ProjectDto(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("title") String title,
|
@JsonProperty("title") String title,
|
||||||
@JsonProperty("status") Project.ProjectStatus status,
|
@JsonProperty("status") Project.ProjectStatus status,
|
||||||
@JsonProperty("description") String description,
|
@JsonProperty("description") String description,
|
||||||
@JsonProperty("grant") GrantDto grant,
|
|
||||||
@JsonProperty("repository") String repository,
|
@JsonProperty("repository") String repository,
|
||||||
@JsonProperty("files") List<FileDataDto> files,
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
@JsonProperty("executorIds") Set<Integer> executorIds,
|
@JsonProperty("executorIds") Set<Integer> executorIds,
|
||||||
@JsonProperty("executors") List<UserDto> executors,
|
@JsonProperty("grantIds") List<Integer> grantIds) {
|
||||||
@JsonProperty("grantIds") List<Integer> grantIds,
|
|
||||||
@JsonProperty("grants") List<GrantDto> grants) {
|
|
||||||
super(id);
|
super(id);
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
@ -52,9 +44,7 @@ public class ProjectDto extends ActivityDto {
|
|||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
this.files = files;
|
this.files = files;
|
||||||
this.executorIds = executorIds;
|
this.executorIds = executorIds;
|
||||||
this.executors = executors;
|
|
||||||
this.grantIds = grantIds;
|
this.grantIds = grantIds;
|
||||||
this.grants = grants;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -66,11 +56,9 @@ public class ProjectDto extends ActivityDto {
|
|||||||
this.description = project.getDescription();
|
this.description = project.getDescription();
|
||||||
this.files = convert(project.getFiles(), FileDataDto::new);
|
this.files = convert(project.getFiles(), FileDataDto::new);
|
||||||
this.repository = project.getRepository();
|
this.repository = project.getRepository();
|
||||||
this.deadlines = project.getDeadlines();
|
this.deadlines = convert(project.getDeadlines(), DeadlineDto::new);
|
||||||
this.executorIds = convert(users, user -> user.getId());
|
this.executorIds = convert(users, user -> user.getId());
|
||||||
this.executors = convert(project.getExecutors(), UserDto::new);
|
|
||||||
this.grantIds = convert(project.getGrants(), grant -> grant.getId());
|
this.grantIds = convert(project.getGrants(), grant -> grant.getId());
|
||||||
this.grants = convert(project.getGrants(), GrantDto::new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
@ -105,11 +93,11 @@ public class ProjectDto extends ActivityDto {
|
|||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Deadline> getDeadlines() {
|
public List<DeadlineDto> getDeadlines() {
|
||||||
return deadlines;
|
return deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeadlines(List<Deadline> deadlines) {
|
public void setDeadlines(List<DeadlineDto> deadlines) {
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,14 +109,6 @@ public class ProjectDto extends ActivityDto {
|
|||||||
this.files = files;
|
this.files = files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getRemovedDeadlineIds() {
|
|
||||||
return removedDeadlineIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
|
||||||
this.removedDeadlineIds = removedDeadlineIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getExecutorIds() {
|
public Set<Integer> getExecutorIds() {
|
||||||
return executorIds;
|
return executorIds;
|
||||||
}
|
}
|
||||||
@ -137,14 +117,6 @@ public class ProjectDto extends ActivityDto {
|
|||||||
this.executorIds = executorIds;
|
this.executorIds = executorIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserDto> getExecutors() {
|
|
||||||
return executors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExecutors(List<UserDto> executors) {
|
|
||||||
this.executors = executors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getGrantIds() {
|
public List<Integer> getGrantIds() {
|
||||||
return grantIds;
|
return grantIds;
|
||||||
}
|
}
|
||||||
@ -152,12 +124,4 @@ public class ProjectDto extends ActivityDto {
|
|||||||
public void setGrantIds(List<Integer> grantIds) {
|
public void setGrantIds(List<Integer> grantIds) {
|
||||||
this.grantIds = grantIds;
|
this.grantIds = grantIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GrantDto> getGrants() {
|
|
||||||
return grants;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrants(List<GrantDto> grants) {
|
|
||||||
this.grants = grants;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -97,14 +97,6 @@ public class ProjectService extends ActivityService<ProjectListDto, Project, Pro
|
|||||||
return new ProjectDto(entity);
|
return new ProjectDto(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectDto removeDeadline(ProjectDto projectDto, Integer deadlineId) {
|
|
||||||
if (deadlineId != null) {
|
|
||||||
projectDto.getRemovedDeadlineIds().add(deadlineId);
|
|
||||||
}
|
|
||||||
projectDto.getDeadlines().remove((int) deadlineId);
|
|
||||||
return projectDto;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Project findById(Integer id) {
|
public Project findById(Integer id) {
|
||||||
return projectRepository.getOne(id);
|
return projectRepository.getOne(id);
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,16 @@ package ru.ulstu.activity.students.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import ru.ulstu.activity.api.model.ActivityDto;
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
import ru.ulstu.activity.tags.model.Tag;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class TaskDto extends ActivityDto {
|
public class TaskDto extends ActivityDto {
|
||||||
|
|
||||||
@ -22,11 +21,10 @@ public class TaskDto extends ActivityDto {
|
|||||||
private String title;
|
private String title;
|
||||||
private String description;
|
private String description;
|
||||||
private Task.TaskStatus status;
|
private Task.TaskStatus status;
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||||
private Date createDate;
|
private Date createDate;
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
private Set<Integer> tagIds;
|
private Set<Integer> tagIds;
|
||||||
private List<Tag> tags = new ArrayList<>();
|
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public TaskDto(@JsonProperty("id") Integer id,
|
public TaskDto(@JsonProperty("id") Integer id,
|
||||||
@ -35,9 +33,8 @@ public class TaskDto extends ActivityDto {
|
|||||||
@JsonProperty("createDate") Date createDate,
|
@JsonProperty("createDate") Date createDate,
|
||||||
@JsonProperty("updateDate") Date updateDate,
|
@JsonProperty("updateDate") Date updateDate,
|
||||||
@JsonProperty("status") Task.TaskStatus status,
|
@JsonProperty("status") Task.TaskStatus status,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
@JsonProperty("tagIds") Set<Integer> tagIds,
|
@JsonProperty("tagIds") Set<Integer> tagIds) {
|
||||||
@JsonProperty("tags") List<Tag> tags) {
|
|
||||||
super(id);
|
super(id);
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
@ -45,18 +42,16 @@ public class TaskDto extends ActivityDto {
|
|||||||
this.createDate = createDate;
|
this.createDate = createDate;
|
||||||
this.updateDate = updateDate;
|
this.updateDate = updateDate;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.tags = tags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskDto(Task task) {
|
public TaskDto(Task task) {
|
||||||
super(task.getId());
|
super(task.getId());
|
||||||
this.title = task.getTitle();
|
this.title = task.getTitle();
|
||||||
this.status = task.getStatus();
|
this.status = task.getStatus();
|
||||||
this.deadlines = task.getDeadlines();
|
this.deadlines = convert(task.getDeadlines(), DeadlineDto::new);
|
||||||
this.createDate = task.getCreateDate();
|
this.createDate = task.getCreateDate();
|
||||||
this.updateDate = task.getUpdateDate();
|
this.updateDate = task.getUpdateDate();
|
||||||
this.description = task.getDescription();
|
this.description = task.getDescription();
|
||||||
this.tags = task.getTags();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
@ -83,14 +78,6 @@ public class TaskDto extends ActivityDto {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Deadline> getDeadlines() {
|
|
||||||
return deadlines;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeadlines(List<Deadline> deadlines) {
|
|
||||||
this.deadlines = deadlines;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreateDate() {
|
public Date getCreateDate() {
|
||||||
return createDate;
|
return createDate;
|
||||||
}
|
}
|
||||||
@ -115,18 +102,7 @@ public class TaskDto extends ActivityDto {
|
|||||||
this.tagIds = tagIds;
|
this.tagIds = tagIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Tag> getTags() {
|
public List<DeadlineDto> getDeadlines() {
|
||||||
return tags;
|
return deadlines;
|
||||||
}
|
|
||||||
|
|
||||||
public void setTags(List<Tag> tags) {
|
|
||||||
this.tags = tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTagsString() {
|
|
||||||
return StringUtils.abbreviate(tags
|
|
||||||
.stream()
|
|
||||||
.map(tag -> tag.getTagName())
|
|
||||||
.collect(Collectors.joining(", ")), MAX_TAGS_LENGTH);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import ru.ulstu.core.model.response.PageableItems;
|
|||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
|
|
||||||
import javax.persistence.EntityNotFoundException;
|
import javax.persistence.EntityNotFoundException;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@ -101,18 +100,7 @@ public class TaskService extends ActivityService<TaskListDto, Task, TaskDto> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
protected Task copyFromDto(Task task, TaskDto taskDto) {
|
||||||
public TaskDto create(TaskDto taskDto) {
|
|
||||||
Task newTask = null;
|
|
||||||
try {
|
|
||||||
newTask = copyFromDto(new Task(), taskDto);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return new TaskDto(create(newTask));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Task copyFromDto(Task task, TaskDto taskDto) throws IOException {
|
|
||||||
task.setTitle(taskDto.getTitle());
|
task.setTitle(taskDto.getTitle());
|
||||||
task.setDescription(taskDto.getDescription());
|
task.setDescription(taskDto.getDescription());
|
||||||
task.setStatus(taskDto.getStatus() == null ? IN_WORK : taskDto.getStatus());
|
task.setStatus(taskDto.getStatus() == null ? IN_WORK : taskDto.getStatus());
|
||||||
@ -120,16 +108,10 @@ public class TaskService extends ActivityService<TaskListDto, Task, TaskDto> {
|
|||||||
task.setCreateDate(task.getCreateDate() == null ? new Date() : task.getCreateDate());
|
task.setCreateDate(task.getCreateDate() == null ? new Date() : task.getCreateDate());
|
||||||
task.setUpdateDate(new Date());
|
task.setUpdateDate(new Date());
|
||||||
task.getTags().clear();
|
task.getTags().clear();
|
||||||
task.setTags(tagService.saveOrCreate(taskDto.getTags()));
|
//task.setTags(tagService.saveOrCreate(taskDto.getTags()));
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public TaskDto update(TaskDto taskDto) {
|
|
||||||
Task task = taskRepository.getOne(taskDto.getId());
|
|
||||||
return new TaskDto(update(task));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean delete(Integer taskId) {
|
public boolean delete(Integer taskId) {
|
||||||
if (taskRepository.existsById(taskId)) {
|
if (taskRepository.existsById(taskId)) {
|
||||||
|
@ -1,281 +0,0 @@
|
|||||||
package conference;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.InjectMocks;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import ru.ulstu.activity.conference.model.Conference;
|
|
||||||
import ru.ulstu.activity.conference.model.ConferenceDto;
|
|
||||||
import ru.ulstu.activity.conference.model.ConferenceFilterDto;
|
|
||||||
import ru.ulstu.activity.conference.model.ConferenceUser;
|
|
||||||
import ru.ulstu.activity.conference.repository.ConferenceRepository;
|
|
||||||
import ru.ulstu.activity.conference.service.ConferenceNotificationService;
|
|
||||||
import ru.ulstu.activity.conference.service.ConferenceService;
|
|
||||||
import ru.ulstu.activity.conference.service.ConferenceUserService;
|
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
|
||||||
import ru.ulstu.activity.deadline.service.DeadlineService;
|
|
||||||
import ru.ulstu.activity.paper.model.Paper;
|
|
||||||
import ru.ulstu.activity.paper.service.PaperService;
|
|
||||||
import ru.ulstu.activity.ping.service.PingService;
|
|
||||||
import ru.ulstu.activity.timeline.service.EventService;
|
|
||||||
import ru.ulstu.user.model.User;
|
|
||||||
import ru.ulstu.user.service.UserService;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
public class ConferenceServiceTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
ConferenceRepository conferenceRepository;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
DeadlineService deadlineService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
ConferenceUserService conferenceUserService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
PaperService paperService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
UserService userService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
EventService eventService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
ConferenceNotificationService conferenceNotificationService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
PingService pingService;
|
|
||||||
|
|
||||||
@InjectMocks
|
|
||||||
ConferenceService conferenceService;
|
|
||||||
|
|
||||||
private final static Integer ID = 1;
|
|
||||||
private final static Integer INDEX = 0;
|
|
||||||
private final static String NAME = "Name";
|
|
||||||
private final static String DESCRIPTION = "Desc";
|
|
||||||
private final static boolean TRUE = true;
|
|
||||||
private final static Integer YEAR = 2019;
|
|
||||||
private final static Sort SORT = new Sort(Sort.Direction.DESC, "beginDate");
|
|
||||||
|
|
||||||
private List<Conference> conferences;
|
|
||||||
private List<Deadline> deadlines;
|
|
||||||
private List<Paper> papers;
|
|
||||||
private List<ConferenceUser> conferenceUsers;
|
|
||||||
|
|
||||||
private Conference conferenceWithId;
|
|
||||||
|
|
||||||
private Paper paperWithId;
|
|
||||||
private Paper paperWithoutId;
|
|
||||||
|
|
||||||
private ConferenceDto conferenceDto;
|
|
||||||
private User user;
|
|
||||||
private Deadline deadline;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
conferences = new ArrayList<>();
|
|
||||||
conferenceWithId = new Conference();
|
|
||||||
|
|
||||||
conferenceWithId.setId(ID);
|
|
||||||
conferenceWithId.setTitle(NAME);
|
|
||||||
conferenceWithId.setDescription(DESCRIPTION);
|
|
||||||
|
|
||||||
paperWithId = new Paper();
|
|
||||||
paperWithId.setId(1);
|
|
||||||
paperWithId.setTitle(NAME);
|
|
||||||
|
|
||||||
paperWithoutId = new Paper();
|
|
||||||
paperWithoutId.setTitle(NAME);
|
|
||||||
|
|
||||||
papers = new ArrayList<>();
|
|
||||||
papers.add(paperWithId);
|
|
||||||
papers.add(paperWithoutId);
|
|
||||||
|
|
||||||
deadlines = new ArrayList<>();
|
|
||||||
deadline = new Deadline(new Date(), DESCRIPTION);
|
|
||||||
deadline.setId(ID);
|
|
||||||
deadlines.add(deadline);
|
|
||||||
|
|
||||||
ConferenceUser conferenceUser = new ConferenceUser();
|
|
||||||
conferenceUser.setDeposit(ConferenceUser.Deposit.ARTICLE);
|
|
||||||
conferenceUser.setParticipation(ConferenceUser.Participation.INTRAMURAL);
|
|
||||||
user = new User();
|
|
||||||
user.setFirstName(NAME);
|
|
||||||
conferenceUser.setUser(user);
|
|
||||||
|
|
||||||
conferenceUsers = new ArrayList<>();
|
|
||||||
conferenceUsers.add(conferenceUser);
|
|
||||||
|
|
||||||
conferences.add(conferenceWithId);
|
|
||||||
conferenceDto = new ConferenceDto(conferenceWithId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getExistConferenceById() {
|
|
||||||
when(conferenceRepository.getOne(ID)).thenReturn(conferenceWithId);
|
|
||||||
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
|
|
||||||
when(userService.getCurrentUser()).thenReturn(user);
|
|
||||||
|
|
||||||
ConferenceDto newConferenceDto = new ConferenceDto(conferenceWithId);
|
|
||||||
newConferenceDto.setNotSelectedPapers(papers);
|
|
||||||
newConferenceDto.setDisabledTakePart(!TRUE);
|
|
||||||
ConferenceDto result = conferenceService.getExistConferenceById(ID);
|
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getId(), result.getId());
|
|
||||||
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
|
||||||
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNewConference() {
|
|
||||||
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
|
|
||||||
|
|
||||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
|
||||||
newConferenceDto.setNotSelectedPapers(papers);
|
|
||||||
ConferenceDto result = new ConferenceDto();
|
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getId(), result.getId());
|
|
||||||
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
|
||||||
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void findAll() {
|
|
||||||
when(conferenceRepository.findAll(SORT)).thenReturn(conferences);
|
|
||||||
|
|
||||||
assertEquals(Collections.singletonList(conferenceWithId), conferenceService.findAll(0, 100).getItems());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void create() throws IOException {
|
|
||||||
when(paperService.findById(ID)).thenReturn(paperWithId);
|
|
||||||
when(paperService.create(new Paper())).thenReturn(paperWithoutId);
|
|
||||||
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
|
|
||||||
when(conferenceUserService.saveOrCreate(new ArrayList<>())).thenReturn(conferenceUsers);
|
|
||||||
when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId);
|
|
||||||
|
|
||||||
conferenceDto.setPapers(papers);
|
|
||||||
conferenceDto.setDeadlines(deadlines);
|
|
||||||
conferenceDto.setUsers(conferenceUsers);
|
|
||||||
conferenceDto.getPaperIds().add(ID);
|
|
||||||
|
|
||||||
Conference newConference = new Conference();
|
|
||||||
newConference.setId(ID);
|
|
||||||
newConference.setTitle(NAME);
|
|
||||||
newConference.setDescription(DESCRIPTION);
|
|
||||||
newConference.setPapers(papers);
|
|
||||||
newConference.getPapers().add(paperWithId);
|
|
||||||
newConference.setDeadlines(deadlines);
|
|
||||||
newConference.setUsers(conferenceUsers);
|
|
||||||
|
|
||||||
assertEquals(newConference, conferenceService.create(conferenceDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete() {
|
|
||||||
when(conferenceRepository.existsById(ID)).thenReturn(true);
|
|
||||||
when(conferenceRepository.getOne(ID)).thenReturn(conferenceWithId);
|
|
||||||
assertTrue(conferenceService.delete(ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addDeadline() {
|
|
||||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
|
||||||
newConferenceDto.getDeadlines().add(new Deadline());
|
|
||||||
conferenceDto.getDeadlines().clear();
|
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getDeadlines().get(0), conferenceService.addDeadline(conferenceDto).getDeadlines().get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void removeDeadline() throws IOException {
|
|
||||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
|
||||||
newConferenceDto.getRemovedDeadlineIds().add(ID);
|
|
||||||
conferenceDto.getDeadlines().add(deadline);
|
|
||||||
ConferenceDto result = conferenceService.removeDeadline(conferenceDto, INDEX);
|
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getDeadlines(), result.getDeadlines());
|
|
||||||
assertEquals(newConferenceDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addPaper() {
|
|
||||||
when(userService.getCurrentUser()).thenReturn(user);
|
|
||||||
|
|
||||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
|
||||||
newConferenceDto.getPapers().add(paperWithoutId);
|
|
||||||
conferenceDto.getPapers().clear();
|
|
||||||
ConferenceDto result = conferenceService.addPaper(conferenceDto);
|
|
||||||
result.getPapers().get(INDEX).setTitle(NAME); // приходится вручную назначать название, т.е. название зависит от даты
|
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getPapers(), result.getPapers());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void removePaper() throws IOException {
|
|
||||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
|
||||||
newConferenceDto.getNotSelectedPapers().add(paperWithId);
|
|
||||||
newConferenceDto.getPapers().add(paperWithoutId);
|
|
||||||
conferenceDto.getPapers().add(paperWithId);
|
|
||||||
conferenceDto.getPapers().add(paperWithoutId);
|
|
||||||
ConferenceDto result = conferenceService.removePaper(conferenceDto, INDEX);
|
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getPapers(), result.getPapers());
|
|
||||||
assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void takePart() throws IOException {
|
|
||||||
when(userService.getCurrentUser()).thenReturn(user);
|
|
||||||
|
|
||||||
ConferenceDto newConferenceDto = new ConferenceDto();
|
|
||||||
newConferenceDto.setUsers(conferenceUsers);
|
|
||||||
newConferenceDto.setDisabledTakePart(TRUE);
|
|
||||||
conferenceDto.getPapers().clear();
|
|
||||||
ConferenceDto result = conferenceService.takePart(conferenceDto);
|
|
||||||
|
|
||||||
assertEquals(newConferenceDto.getUsers(), result.getUsers());
|
|
||||||
assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAllUsers() {
|
|
||||||
List<User> users = Collections.singletonList(user);
|
|
||||||
when(userService.findAll()).thenReturn(users);
|
|
||||||
assertEquals(users, conferenceService.getAllUsers());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void filter() {
|
|
||||||
when(userService.findById(ID)).thenReturn(user);
|
|
||||||
when(conferenceRepository.findByUserAndYear(user, YEAR)).thenReturn(conferences);
|
|
||||||
|
|
||||||
ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto();
|
|
||||||
conferenceFilterDto.setFilterUserId(ID);
|
|
||||||
conferenceFilterDto.setYear(YEAR);
|
|
||||||
|
|
||||||
assertEquals(Collections.singletonList(conferenceDto), conferenceService.filter(conferenceFilterDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAttachedToConference() {
|
|
||||||
when(conferenceRepository.isPaperAttached(ID)).thenReturn(TRUE);
|
|
||||||
|
|
||||||
assertTrue(conferenceService.isAttachedToConference(ID));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,149 +0,0 @@
|
|||||||
package project;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.InjectMocks;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
|
||||||
import ru.ulstu.activity.deadline.service.DeadlineService;
|
|
||||||
import ru.ulstu.activity.file.model.FileData;
|
|
||||||
import ru.ulstu.activity.file.service.FileService;
|
|
||||||
import ru.ulstu.activity.grant.model.GrantDto;
|
|
||||||
import ru.ulstu.activity.grant.service.GrantService;
|
|
||||||
import ru.ulstu.activity.project.model.Project;
|
|
||||||
import ru.ulstu.activity.project.model.ProjectDto;
|
|
||||||
import ru.ulstu.activity.project.repository.ProjectRepository;
|
|
||||||
import ru.ulstu.activity.project.service.ProjectService;
|
|
||||||
import ru.ulstu.activity.timeline.service.EventService;
|
|
||||||
import ru.ulstu.user.model.User;
|
|
||||||
import ru.ulstu.user.service.UserService;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertTrue;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
public class ProjectServiceTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
ProjectRepository projectRepository;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
DeadlineService deadlineService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
EventService eventService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
FileService fileService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
UserService userService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
GrantService grantService;
|
|
||||||
|
|
||||||
@InjectMocks
|
|
||||||
ProjectService projectService;
|
|
||||||
|
|
||||||
private final static String TITLE = "title";
|
|
||||||
private final static String DESCR = "descr";
|
|
||||||
private final static Integer ID = 1;
|
|
||||||
private final static Integer INDEX = 0;
|
|
||||||
private final static String NAME = "name";
|
|
||||||
|
|
||||||
private List<Project> projects;
|
|
||||||
private Project project;
|
|
||||||
private ProjectDto projectDto;
|
|
||||||
private Deadline deadline;
|
|
||||||
private List<Deadline> deadlines;
|
|
||||||
private FileData file;
|
|
||||||
private List<FileData> files;
|
|
||||||
private User user;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
projects = new ArrayList<>();
|
|
||||||
project = new Project();
|
|
||||||
|
|
||||||
projects.add(project);
|
|
||||||
projectDto = new ProjectDto(project);
|
|
||||||
|
|
||||||
deadlines = new ArrayList<>();
|
|
||||||
deadline = new Deadline(new Date(), DESCR);
|
|
||||||
deadline.setId(ID);
|
|
||||||
deadlines.add(deadline);
|
|
||||||
|
|
||||||
user = new User();
|
|
||||||
user.setFirstName(NAME);
|
|
||||||
|
|
||||||
List<GrantDto> grants = new ArrayList<>();
|
|
||||||
GrantDto grant = new GrantDto(ID);
|
|
||||||
grants.add(grant);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void findAll() {
|
|
||||||
when(projectRepository.findAll()).thenReturn(projects);
|
|
||||||
assertEquals(projects, projectService.findAll(0, 100).getItems());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void create() throws IOException {
|
|
||||||
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
|
|
||||||
when(projectRepository.save(new Project())).thenReturn(project);
|
|
||||||
eventService.createFromObject(new Project(), Collections.emptyList(), false, "проекта");
|
|
||||||
|
|
||||||
projectDto.setTitle(TITLE);
|
|
||||||
projectDto.setDeadlines(deadlines);
|
|
||||||
|
|
||||||
project.setId(ID);
|
|
||||||
project.setTitle(TITLE);
|
|
||||||
project.setDescription(DESCR);
|
|
||||||
project.setDeadlines(deadlines);
|
|
||||||
project.setFiles(files);
|
|
||||||
|
|
||||||
assertEquals(project.getId(), (projectService.create(projectDto)).getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete() throws IOException {
|
|
||||||
when(projectRepository.existsById(ID)).thenReturn(true);
|
|
||||||
when(projectRepository.getOne(ID)).thenReturn(project);
|
|
||||||
|
|
||||||
assertTrue(projectService.delete(ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getProjectExecutors() {
|
|
||||||
List<User> executors = Collections.singletonList(user);
|
|
||||||
when(userService.findAll()).thenReturn(executors);
|
|
||||||
|
|
||||||
assertEquals(executors, projectService.getProjectExecutors(projectDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void findById() {
|
|
||||||
when(projectRepository.getOne(ID)).thenReturn(project);
|
|
||||||
assertEquals(project, projectService.findById(ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void removeDeadline() {
|
|
||||||
ProjectDto newProjectDto = new ProjectDto(null);
|
|
||||||
newProjectDto.getRemovedDeadlineIds().add(INDEX);
|
|
||||||
projectDto.getDeadlines().add(deadline);
|
|
||||||
ProjectDto result = projectService.removeDeadline(projectDto, INDEX);
|
|
||||||
|
|
||||||
assertEquals(newProjectDto.getDeadlines(), result.getDeadlines());
|
|
||||||
assertEquals(newProjectDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,216 +0,0 @@
|
|||||||
package students;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.InjectMocks;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import ru.ulstu.activity.deadline.model.Deadline;
|
|
||||||
import ru.ulstu.activity.deadline.service.DeadlineService;
|
|
||||||
import ru.ulstu.activity.students.model.Scheduler;
|
|
||||||
import ru.ulstu.activity.students.model.Task;
|
|
||||||
import ru.ulstu.activity.students.model.TaskDto;
|
|
||||||
import ru.ulstu.activity.students.model.TaskFilterDto;
|
|
||||||
import ru.ulstu.activity.students.repository.SchedulerRepository;
|
|
||||||
import ru.ulstu.activity.students.repository.TaskRepository;
|
|
||||||
import ru.ulstu.activity.students.service.TaskService;
|
|
||||||
import ru.ulstu.activity.tags.model.Tag;
|
|
||||||
import ru.ulstu.activity.tags.service.TagService;
|
|
||||||
import ru.ulstu.activity.timeline.service.EventService;
|
|
||||||
import ru.ulstu.core.util.DateUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
public class TaskServiceTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
TaskRepository taskRepository;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
SchedulerRepository schedulerRepository;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private TagService tagService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
DeadlineService deadlineService;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
EventService eventService;
|
|
||||||
|
|
||||||
@InjectMocks
|
|
||||||
TaskService taskService;
|
|
||||||
|
|
||||||
private final static Sort SORT = new Sort(Sort.Direction.DESC, "createDate");
|
|
||||||
private final static Integer ID = 1;
|
|
||||||
private final static Task.TaskStatus STATUS = Task.TaskStatus.IN_WORK;
|
|
||||||
private final static String TITLE = "title";
|
|
||||||
private final static String DESCR = "descr";
|
|
||||||
private final static String TAG = "tag";
|
|
||||||
private final static Date YEAR = DateUtils.clearTime(DateUtils.addYears(new Date(), 0));
|
|
||||||
|
|
||||||
private List<Task> tasks;
|
|
||||||
private List<Tag> tags;
|
|
||||||
private Task task;
|
|
||||||
private Task taskForSchedule;
|
|
||||||
private TaskDto taskDto;
|
|
||||||
private Tag tag;
|
|
||||||
private Deadline deadline;
|
|
||||||
private List<Deadline> deadlines;
|
|
||||||
private Scheduler scheduler;
|
|
||||||
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
|
|
||||||
tasks = new ArrayList<>();
|
|
||||||
task = new Task();
|
|
||||||
|
|
||||||
task.setId(ID);
|
|
||||||
task.setTitle(TITLE);
|
|
||||||
task.setDescription(DESCR);
|
|
||||||
|
|
||||||
|
|
||||||
tag = new Tag();
|
|
||||||
tag.setId(ID);
|
|
||||||
tag.setTagName(TAG);
|
|
||||||
|
|
||||||
deadlines = new ArrayList<>();
|
|
||||||
deadline = new Deadline(new Date(), DESCR);
|
|
||||||
deadline.setId(ID);
|
|
||||||
deadlines.add(deadline);
|
|
||||||
|
|
||||||
task.setDeadlines(deadlines);
|
|
||||||
|
|
||||||
tags = new ArrayList<>();
|
|
||||||
tags.add(tag);
|
|
||||||
|
|
||||||
tasks.add(task);
|
|
||||||
taskDto = new TaskDto(task);
|
|
||||||
|
|
||||||
taskForSchedule = new Task();
|
|
||||||
taskForSchedule.setTitle(TITLE);
|
|
||||||
taskForSchedule.setDescription(DESCR);
|
|
||||||
|
|
||||||
scheduler = new Scheduler();
|
|
||||||
scheduler.setDate(new Date());
|
|
||||||
scheduler.setTask(taskForSchedule);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void findAll() {
|
|
||||||
when(taskRepository.findAll(SORT)).thenReturn(tasks);
|
|
||||||
assertEquals(Collections.singletonList(task), taskService.findAll());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void filter() {
|
|
||||||
when(tagService.findById(ID)).thenReturn(tag);
|
|
||||||
when(taskRepository.filterNew(STATUS, tag)).thenReturn(tasks);
|
|
||||||
|
|
||||||
TaskFilterDto taskFilterDto = new TaskFilterDto();
|
|
||||||
taskFilterDto.setTag(ID);
|
|
||||||
taskFilterDto.setOrder("new");
|
|
||||||
taskFilterDto.setStatus(STATUS);
|
|
||||||
|
|
||||||
assertEquals(Collections.singletonList(taskDto), taskService.filter(taskFilterDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void create() throws IOException {
|
|
||||||
when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags);
|
|
||||||
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
|
|
||||||
when(taskRepository.save(new Task())).thenReturn(task);
|
|
||||||
eventService.createFromObject(new Task(), Collections.emptyList(), true, "задачи");
|
|
||||||
|
|
||||||
taskDto.setTags(tags);
|
|
||||||
taskDto.setDeadlines(deadlines);
|
|
||||||
|
|
||||||
Task newTask = new Task();
|
|
||||||
task.setId(ID);
|
|
||||||
task.setTitle(TITLE);
|
|
||||||
task.setDescription(DESCR);
|
|
||||||
task.setTags(tags);
|
|
||||||
task.setDeadlines(deadlines);
|
|
||||||
|
|
||||||
assertEquals(task.getId(), taskService.create(taskDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete() throws IOException {
|
|
||||||
when(taskRepository.existsById(ID)).thenReturn(true);
|
|
||||||
when(taskRepository.getOne(ID)).thenReturn(task);
|
|
||||||
when(schedulerRepository.findOneByTask(task)).thenReturn(null);
|
|
||||||
|
|
||||||
assertTrue(taskService.delete(ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void generateYearTasks() {
|
|
||||||
when(tagService.getTags()).thenReturn(tags);
|
|
||||||
tasks.get(0).setTags(tags);
|
|
||||||
when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks);
|
|
||||||
tasks.get(0).setCreateDate(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)));
|
|
||||||
when(taskRepository.findByTag(tag)).thenReturn(tasks);
|
|
||||||
|
|
||||||
Task newTask = new Task();
|
|
||||||
newTask.setTitle(tasks.get(0).getTitle());
|
|
||||||
newTask.setTags(tasks.get(0).getTags());
|
|
||||||
newTask.setCreateDate(new Date());
|
|
||||||
newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS);
|
|
||||||
|
|
||||||
Deadline newDeadline = new Deadline();
|
|
||||||
newDeadline.setId(ID);
|
|
||||||
newDeadline.setDescription(deadline.getDescription());
|
|
||||||
newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1));
|
|
||||||
when(deadlineService.create(newDeadline)).thenReturn(newDeadline);
|
|
||||||
newTask.setDeadlines(Arrays.asList(newDeadline));
|
|
||||||
|
|
||||||
when(taskRepository.save(newTask)).thenReturn(task);
|
|
||||||
|
|
||||||
assertEquals(Arrays.asList(task), taskService.generateYearTasks());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void checkRepeatingTags() {
|
|
||||||
when(tagService.getTags()).thenReturn(tags);
|
|
||||||
tasks.get(0).setTags(tags);
|
|
||||||
when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks);
|
|
||||||
|
|
||||||
assertEquals(new HashSet<Tag>(Arrays.asList(tag)), taskService.checkRepeatingTags(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createPeriodTask() {
|
|
||||||
Task newTask = new Task();
|
|
||||||
newTask.setTitle(scheduler.getTask().getTitle());
|
|
||||||
newTask.setTags(scheduler.getTask().getTags());
|
|
||||||
newTask.setCreateDate(new Date());
|
|
||||||
|
|
||||||
Deadline newDeadline = new Deadline();
|
|
||||||
newDeadline.setId(ID);
|
|
||||||
newDeadline.setDescription(deadline.getDescription());
|
|
||||||
newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1));
|
|
||||||
when(deadlineService.create(newDeadline)).thenReturn(newDeadline);
|
|
||||||
newTask.setDeadlines(Arrays.asList(newDeadline));
|
|
||||||
|
|
||||||
when(taskRepository.save(newTask)).thenReturn(taskForSchedule);
|
|
||||||
|
|
||||||
assertEquals(taskForSchedule, taskService.createPeriodTask(scheduler));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user