|
|
@ -1,5 +1,6 @@
|
|
|
|
package ru.ulstu.grant.service;
|
|
|
|
package ru.ulstu.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.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@ -17,7 +18,6 @@ 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;
|
|
|
|
import ru.ulstu.ping.service.PingService;
|
|
|
|
import ru.ulstu.ping.service.PingService;
|
|
|
|
import ru.ulstu.project.model.Project;
|
|
|
|
|
|
|
|
import ru.ulstu.project.model.ProjectDto;
|
|
|
|
import ru.ulstu.project.model.ProjectDto;
|
|
|
|
import ru.ulstu.project.service.ProjectService;
|
|
|
|
import ru.ulstu.project.service.ProjectService;
|
|
|
|
import ru.ulstu.timeline.service.EventService;
|
|
|
|
import ru.ulstu.timeline.service.EventService;
|
|
|
@ -77,6 +77,11 @@ public class GrantService extends BaseService {
|
|
|
|
this.pingService = pingService;
|
|
|
|
this.pingService = pingService;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public GrantDto getExistGrantById(Integer id) {
|
|
|
|
|
|
|
|
GrantDto grantDto = new GrantDto(findById(id));
|
|
|
|
|
|
|
|
return grantDto;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Grant> findAll() {
|
|
|
|
public List<Grant> findAll() {
|
|
|
|
return grantRepository.findAll();
|
|
|
|
return grantRepository.findAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -85,17 +90,13 @@ public class GrantService extends BaseService {
|
|
|
|
return convert(findAll(), GrantDto::new);
|
|
|
|
return convert(findAll(), GrantDto::new);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public GrantDto findOneDto(Integer id) {
|
|
|
|
|
|
|
|
return new GrantDto(grantRepository.findOne(id));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public Integer create(GrantDto grantDto) throws IOException {
|
|
|
|
public Grant create(GrantDto grantDto) throws IOException {
|
|
|
|
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
|
|
|
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
|
|
|
newGrant = grantRepository.save(newGrant);
|
|
|
|
newGrant = grantRepository.save(newGrant);
|
|
|
|
eventService.createFromObject(newGrant, Collections.emptyList(), false, "гранта");
|
|
|
|
eventService.createFromObject(newGrant, Collections.emptyList(), false, "гранта");
|
|
|
|
grantNotificationService.sendCreateNotification(newGrant);
|
|
|
|
grantNotificationService.sendCreateNotification(newGrant);
|
|
|
|
return newGrant.getId();
|
|
|
|
return newGrant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Grant copyFromDto(Grant grant, GrantDto grantDto) throws IOException {
|
|
|
|
private Grant copyFromDto(Grant grant, GrantDto grantDto) throws IOException {
|
|
|
@ -106,9 +107,11 @@ public class GrantService extends BaseService {
|
|
|
|
grant.setProject(projectService.findById(grantDto.getProject().getId()));
|
|
|
|
grant.setProject(projectService.findById(grantDto.getProject().getId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
|
|
|
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
|
|
|
|
|
|
|
if (!grant.getFiles().isEmpty()) {
|
|
|
|
grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream()
|
|
|
|
grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream()
|
|
|
|
.filter(f -> !f.isDeleted())
|
|
|
|
.filter(f -> !f.isDeleted())
|
|
|
|
.collect(toList())));
|
|
|
|
.collect(toList())));
|
|
|
|
|
|
|
|
}
|
|
|
|
grant.getAuthors().clear();
|
|
|
|
grant.getAuthors().clear();
|
|
|
|
if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) {
|
|
|
|
if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) {
|
|
|
|
grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds)));
|
|
|
|
grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds)));
|
|
|
@ -123,6 +126,7 @@ public class GrantService extends BaseService {
|
|
|
|
return grant;
|
|
|
|
return grant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void createProject(GrantDto grantDto) throws IOException {
|
|
|
|
public void createProject(GrantDto grantDto) throws IOException {
|
|
|
|
grantDto.setProject(
|
|
|
|
grantDto.setProject(
|
|
|
|
new ProjectDto(projectService.save(new ProjectDto(grantDto.getTitle()))));
|
|
|
|
new ProjectDto(projectService.save(new ProjectDto(grantDto.getTitle()))));
|
|
|
@ -130,7 +134,7 @@ public class GrantService extends BaseService {
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public Integer update(GrantDto grantDto) throws IOException {
|
|
|
|
public Integer update(GrantDto grantDto) throws IOException {
|
|
|
|
Grant grant = grantRepository.findOne(grantDto.getId());
|
|
|
|
Grant grant = findById(grantDto.getId());
|
|
|
|
Set<User> oldAuthors = new HashSet<>(grant.getAuthors());
|
|
|
|
Set<User> oldAuthors = new HashSet<>(grant.getAuthors());
|
|
|
|
User oldLeader = grant.getLeader();
|
|
|
|
User oldLeader = grant.getLeader();
|
|
|
|
for (FileDataDto file : grantDto.getFiles().stream()
|
|
|
|
for (FileDataDto file : grantDto.getFiles().stream()
|
|
|
@ -159,34 +163,19 @@ public class GrantService extends BaseService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public void delete(Integer grantId) throws IOException {
|
|
|
|
public boolean delete(Integer grantId) throws IOException {
|
|
|
|
Grant grant = grantRepository.findOne(grantId);
|
|
|
|
Grant grant = findById(grantId);
|
|
|
|
|
|
|
|
if (grant != null) {
|
|
|
|
grantRepository.delete(grant);
|
|
|
|
grantRepository.delete(grant);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Grant.GrantStatus> getGrantStatuses() {
|
|
|
|
public List<Grant.GrantStatus> getGrantStatuses() {
|
|
|
|
return Arrays.asList(Grant.GrantStatus.values());
|
|
|
|
return Arrays.asList(Grant.GrantStatus.values());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
|
|
|
public Grant create(String title, Project projectId, Date deadlineDate, User user, Paper paper) {
|
|
|
|
|
|
|
|
Grant grant = new Grant();
|
|
|
|
|
|
|
|
grant.setTitle(title);
|
|
|
|
|
|
|
|
grant.setComment("Комментарий к гранту 1");
|
|
|
|
|
|
|
|
grant.setProject(projectId);
|
|
|
|
|
|
|
|
grant.setStatus(APPLICATION);
|
|
|
|
|
|
|
|
grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн"));
|
|
|
|
|
|
|
|
grant.getAuthors().add(user);
|
|
|
|
|
|
|
|
grant.setLeader(user);
|
|
|
|
|
|
|
|
grant.getPapers().add(paper);
|
|
|
|
|
|
|
|
grant = grantRepository.save(grant);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eventService.createFromObject(grant, Collections.emptyList(), false, "гранта");
|
|
|
|
|
|
|
|
grantNotificationService.sendCreateNotification(grant);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return grant;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean save(GrantDto grantDto, Errors errors) throws IOException {
|
|
|
|
public boolean save(GrantDto grantDto, Errors errors) throws IOException {
|
|
|
|
grantDto.setName(grantDto.getTitle());
|
|
|
|
grantDto.setName(grantDto.getTitle());
|
|
|
|
filterEmptyDeadlines(grantDto);
|
|
|
|
filterEmptyDeadlines(grantDto);
|
|
|
@ -274,20 +263,22 @@ public class GrantService extends BaseService {
|
|
|
|
return paperService.findAllNotCompleted();
|
|
|
|
return paperService.findAllNotCompleted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void attachPaper(GrantDto grantDto) {
|
|
|
|
public List<PaperDto> attachPaper(GrantDto grantDto) {
|
|
|
|
if (!grantDto.getPaperIds().isEmpty()) {
|
|
|
|
if (!grantDto.getPaperIds().isEmpty()) {
|
|
|
|
grantDto.getPapers().clear();
|
|
|
|
grantDto.getPapers().clear();
|
|
|
|
grantDto.setPapers(getGrantPapers(grantDto.getPaperIds()));
|
|
|
|
grantDto.setPapers(getGrantPapers(grantDto.getPaperIds()));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
grantDto.getPapers().clear();
|
|
|
|
grantDto.getPapers().clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return grantDto.getPapers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void removeDeadline(GrantDto grantDto, Integer deadlineId) {
|
|
|
|
public GrantDto removeDeadline(GrantDto grantDto, Integer deadlineId) {
|
|
|
|
if (grantDto.getDeadlines().get(deadlineId).getId() != null) {
|
|
|
|
if (grantDto.getDeadlines().get(deadlineId).getId() != null) {
|
|
|
|
grantDto.getRemovedDeadlineIds().add(grantDto.getDeadlines().get(deadlineId).getId());
|
|
|
|
grantDto.getRemovedDeadlineIds().add(grantDto.getDeadlines().get(deadlineId).getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
grantDto.getDeadlines().remove((int) deadlineId);
|
|
|
|
grantDto.getDeadlines().remove((int) deadlineId);
|
|
|
|
|
|
|
|
return grantDto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<User> getCompletedPapersAuthors(Paper.PaperType type) {
|
|
|
|
private List<User> getCompletedPapersAuthors(Paper.PaperType type) {
|
|
|
@ -313,10 +304,11 @@ public class GrantService extends BaseService {
|
|
|
|
.collect(toList());
|
|
|
|
.collect(toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void filterEmptyDeadlines(GrantDto grantDto) {
|
|
|
|
public List<Deadline> filterEmptyDeadlines(GrantDto grantDto) {
|
|
|
|
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
|
|
|
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
|
|
|
.filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription()))
|
|
|
|
.filter(dto -> dto.getDate() != null || !StringUtils.isEmpty(dto.getDescription()))
|
|
|
|
.collect(Collectors.toList()));
|
|
|
|
.collect(Collectors.toList()));
|
|
|
|
|
|
|
|
return grantDto.getDeadlines();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
@ -346,8 +338,4 @@ public class GrantService extends BaseService {
|
|
|
|
public void ping(int grantId) throws IOException {
|
|
|
|
public void ping(int grantId) throws IOException {
|
|
|
|
pingService.addPing(findById(grantId));
|
|
|
|
pingService.addPing(findById(grantId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Grant findGrantById(Integer grantId) {
|
|
|
|
|
|
|
|
return grantRepository.findOne(grantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|