|
|
@ -3,6 +3,7 @@ package ru.ulstu.grant.service;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
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.deadline.model.Deadline;
|
|
|
|
import ru.ulstu.deadline.model.Deadline;
|
|
|
|
import ru.ulstu.deadline.service.DeadlineService;
|
|
|
|
import ru.ulstu.deadline.service.DeadlineService;
|
|
|
|
import ru.ulstu.file.model.FileDataDto;
|
|
|
|
import ru.ulstu.file.model.FileDataDto;
|
|
|
@ -10,6 +11,7 @@ import ru.ulstu.file.service.FileService;
|
|
|
|
import ru.ulstu.grant.model.Grant;
|
|
|
|
import ru.ulstu.grant.model.Grant;
|
|
|
|
import ru.ulstu.grant.model.GrantDto;
|
|
|
|
import ru.ulstu.grant.model.GrantDto;
|
|
|
|
import ru.ulstu.grant.repository.GrantRepository;
|
|
|
|
import ru.ulstu.grant.repository.GrantRepository;
|
|
|
|
|
|
|
|
import ru.ulstu.name.BaseService;
|
|
|
|
import ru.ulstu.paper.model.Paper;
|
|
|
|
import ru.ulstu.paper.model.Paper;
|
|
|
|
import ru.ulstu.paper.model.PaperDto;
|
|
|
|
import ru.ulstu.paper.model.PaperDto;
|
|
|
|
import ru.ulstu.paper.service.PaperService;
|
|
|
|
import ru.ulstu.paper.service.PaperService;
|
|
|
@ -27,6 +29,7 @@ import java.util.Date;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
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 org.springframework.util.ObjectUtils.isEmpty;
|
|
|
@ -34,7 +37,7 @@ import static ru.ulstu.core.util.StreamApiUtils.convert;
|
|
|
|
import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
|
|
|
|
import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class GrantService {
|
|
|
|
public class GrantService extends BaseService {
|
|
|
|
private final static int MAX_DISPLAY_SIZE = 50;
|
|
|
|
private final static int MAX_DISPLAY_SIZE = 50;
|
|
|
|
|
|
|
|
|
|
|
|
private final GrantRepository grantRepository;
|
|
|
|
private final GrantRepository grantRepository;
|
|
|
@ -55,6 +58,7 @@ public class GrantService {
|
|
|
|
EventService eventService,
|
|
|
|
EventService eventService,
|
|
|
|
GrantNotificationService grantNotificationService) {
|
|
|
|
GrantNotificationService grantNotificationService) {
|
|
|
|
this.grantRepository = grantRepository;
|
|
|
|
this.grantRepository = grantRepository;
|
|
|
|
|
|
|
|
this.baseRepository = grantRepository;
|
|
|
|
this.fileService = fileService;
|
|
|
|
this.fileService = fileService;
|
|
|
|
this.deadlineService = deadlineService;
|
|
|
|
this.deadlineService = deadlineService;
|
|
|
|
this.projectService = projectService;
|
|
|
|
this.projectService = projectService;
|
|
|
@ -176,12 +180,35 @@ public class GrantService {
|
|
|
|
return grant;
|
|
|
|
return grant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void save(GrantDto grantDto) throws IOException {
|
|
|
|
public boolean save(GrantDto grantDto, Errors errors) throws IOException {
|
|
|
|
|
|
|
|
grantDto.setName(grantDto.getTitle());
|
|
|
|
|
|
|
|
filterEmptyDeadlines(grantDto);
|
|
|
|
|
|
|
|
checkEmptyDeadlines(grantDto, errors);
|
|
|
|
|
|
|
|
checkEmptyLeader(grantDto, errors);
|
|
|
|
|
|
|
|
checkUniqueName(grantDto, errors, grantDto.getId(), "title", "Грант с таким именем уже существует");
|
|
|
|
|
|
|
|
if (errors.hasErrors()) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isEmpty(grantDto.getId())) {
|
|
|
|
if (isEmpty(grantDto.getId())) {
|
|
|
|
create(grantDto);
|
|
|
|
create(grantDto);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
update(grantDto);
|
|
|
|
update(grantDto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void checkEmptyLeader(GrantDto grantDto, Errors errors) {
|
|
|
|
|
|
|
|
if (grantDto.getLeaderId().equals(-1)) {
|
|
|
|
|
|
|
|
errors.rejectValue("leaderId", "errorCode", "Укажите руководителя");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void checkEmptyDeadlines(GrantDto grantDto, Errors errors) {
|
|
|
|
|
|
|
|
if (grantDto.getDeadlines().isEmpty()) {
|
|
|
|
|
|
|
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пусто");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<User> getGrantAuthors(GrantDto grantDto) {
|
|
|
|
public List<User> getGrantAuthors(GrantDto grantDto) {
|
|
|
@ -261,4 +288,10 @@ public class GrantService {
|
|
|
|
.filter(author -> Collections.frequency(authors, author) > 3)
|
|
|
|
.filter(author -> Collections.frequency(authors, author) > 3)
|
|
|
|
.collect(toList());
|
|
|
|
.collect(toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void filterEmptyDeadlines(GrantDto grantDto) {
|
|
|
|
|
|
|
|
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
|
|
|
|
|
|
|
.filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription()))
|
|
|
|
|
|
|
|
.collect(Collectors.toList()));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|