|
|
@ -9,6 +9,8 @@ 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.paper.model.Paper;
|
|
|
|
|
|
|
|
import ru.ulstu.paper.service.PaperService;
|
|
|
|
import ru.ulstu.project.model.Project;
|
|
|
|
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;
|
|
|
@ -34,17 +36,20 @@ public class GrantService {
|
|
|
|
private final DeadlineService deadlineService;
|
|
|
|
private final DeadlineService deadlineService;
|
|
|
|
private final FileService fileService;
|
|
|
|
private final FileService fileService;
|
|
|
|
private final UserService userService;
|
|
|
|
private final UserService userService;
|
|
|
|
|
|
|
|
private final PaperService paperService;
|
|
|
|
|
|
|
|
|
|
|
|
public GrantService(GrantRepository grantRepository,
|
|
|
|
public GrantService(GrantRepository grantRepository,
|
|
|
|
FileService fileService,
|
|
|
|
FileService fileService,
|
|
|
|
DeadlineService deadlineService,
|
|
|
|
DeadlineService deadlineService,
|
|
|
|
ProjectService projectService,
|
|
|
|
ProjectService projectService,
|
|
|
|
UserService userService) {
|
|
|
|
UserService userService,
|
|
|
|
|
|
|
|
PaperService paperService) {
|
|
|
|
this.grantRepository = grantRepository;
|
|
|
|
this.grantRepository = grantRepository;
|
|
|
|
this.fileService = fileService;
|
|
|
|
this.fileService = fileService;
|
|
|
|
this.deadlineService = deadlineService;
|
|
|
|
this.deadlineService = deadlineService;
|
|
|
|
this.projectService = projectService;
|
|
|
|
this.projectService = projectService;
|
|
|
|
this.userService = userService;
|
|
|
|
this.userService = userService;
|
|
|
|
|
|
|
|
this.paperService = paperService;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Grant> findAll() {
|
|
|
|
public List<Grant> findAll() {
|
|
|
@ -86,6 +91,10 @@ public class GrantService {
|
|
|
|
if (grantDto.getLeaderId() != null) {
|
|
|
|
if (grantDto.getLeaderId() != null) {
|
|
|
|
grant.setLeader(userService.findById(grantDto.getLeaderId()));
|
|
|
|
grant.setLeader(userService.findById(grantDto.getLeaderId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
grant.getPapers().clear();
|
|
|
|
|
|
|
|
if (grantDto.getPaperIds() != null && !grantDto.getPaperIds().isEmpty()) {
|
|
|
|
|
|
|
|
grantDto.getPaperIds().forEach(paperIds -> grant.getPapers().add(paperService.findEntityById(paperIds)));
|
|
|
|
|
|
|
|
}
|
|
|
|
return grant;
|
|
|
|
return grant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -118,7 +127,7 @@ public class GrantService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public Grant create(String title, Project projectId, Date deadlineDate, User user) {
|
|
|
|
public Grant create(String title, Project projectId, Date deadlineDate, User user, Paper paper) {
|
|
|
|
Grant grant = new Grant();
|
|
|
|
Grant grant = new Grant();
|
|
|
|
grant.setTitle(title);
|
|
|
|
grant.setTitle(title);
|
|
|
|
grant.setComment("Комментарий к гранту 1");
|
|
|
|
grant.setComment("Комментарий к гранту 1");
|
|
|
@ -127,6 +136,7 @@ public class GrantService {
|
|
|
|
grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн"));
|
|
|
|
grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн"));
|
|
|
|
grant.getAuthors().add(user);
|
|
|
|
grant.getAuthors().add(user);
|
|
|
|
grant.setLeader(user);
|
|
|
|
grant.setLeader(user);
|
|
|
|
|
|
|
|
grant.getPapers().add(paper);
|
|
|
|
grant = grantRepository.save(grant);
|
|
|
|
grant = grantRepository.save(grant);
|
|
|
|
return grant;
|
|
|
|
return grant;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -156,4 +166,22 @@ public class GrantService {
|
|
|
|
.map(Grant::getLeader)
|
|
|
|
.map(Grant::getLeader)
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<Paper> getGrantPapers(List<Integer> paperIds) {
|
|
|
|
|
|
|
|
return paperService.findAllSelect(paperIds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<Paper> getAllPapers() {
|
|
|
|
|
|
|
|
return paperService.findAll();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void attachPaper(GrantDto grantDto) {
|
|
|
|
|
|
|
|
if (!grantDto.getPaperIds().isEmpty()) {
|
|
|
|
|
|
|
|
grantDto.getPapers().clear();
|
|
|
|
|
|
|
|
grantDto.setPapers(getGrantPapers(grantDto.getPaperIds()));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
grantDto.getPapers().clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|