|
|
@ -9,8 +9,10 @@ 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.model.repository.GrantRepository;
|
|
|
|
import ru.ulstu.grant.model.repository.GrantRepository;
|
|
|
|
import ru.ulstu.paper.model.PaperDto;
|
|
|
|
|
|
|
|
import ru.ulstu.project.model.Project;
|
|
|
|
import ru.ulstu.project.model.Project;
|
|
|
|
|
|
|
|
import ru.ulstu.project.model.ProjectDto;
|
|
|
|
|
|
|
|
import ru.ulstu.project.repository.ProjectRepository;
|
|
|
|
|
|
|
|
import ru.ulstu.project.service.ProjectService;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
@ -26,29 +28,32 @@ public class GrantService {
|
|
|
|
private final static int MAX_DISPLAY_SIZE = 40;
|
|
|
|
private final static int MAX_DISPLAY_SIZE = 40;
|
|
|
|
|
|
|
|
|
|
|
|
private final GrantRepository grantRepository;
|
|
|
|
private final GrantRepository grantRepository;
|
|
|
|
|
|
|
|
private final ProjectService projectService;
|
|
|
|
private final DeadlineService deadlineService;
|
|
|
|
private final DeadlineService deadlineService;
|
|
|
|
private final FileService fileService;
|
|
|
|
private final FileService fileService;
|
|
|
|
|
|
|
|
|
|
|
|
public GrantService(GrantRepository grantRepository,
|
|
|
|
public GrantService(GrantRepository grantRepository,
|
|
|
|
FileService fileService,
|
|
|
|
FileService fileService,
|
|
|
|
DeadlineService deadlineService) {
|
|
|
|
DeadlineService deadlineService,
|
|
|
|
|
|
|
|
ProjectService projectService) {
|
|
|
|
this.grantRepository = grantRepository;
|
|
|
|
this.grantRepository = grantRepository;
|
|
|
|
|
|
|
|
this.projectService = projectService;
|
|
|
|
this.fileService = fileService;
|
|
|
|
this.fileService = fileService;
|
|
|
|
this.deadlineService = deadlineService;
|
|
|
|
this.deadlineService = deadlineService;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Grant> findAll() {
|
|
|
|
public List<Grant> findAll() {
|
|
|
|
return sortGrants(grantRepository.findAll());
|
|
|
|
return grantRepository.findAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<GrantDto> findAllDto() {
|
|
|
|
public List<GrantDto> findAllDto() {
|
|
|
|
List<GrantDto> grants = convert(findAll(), ru.ulstu.grant.model.GrantDto::new);
|
|
|
|
List<GrantDto> grants = convert(findAll(), GrantDto::new);
|
|
|
|
grants.forEach(grantDto -> grantDto.setTitle(StringUtils.abbreviate(grantDto.getTitle(), MAX_DISPLAY_SIZE)));
|
|
|
|
grants.forEach(grantDto -> grantDto.setTitle(StringUtils.abbreviate(grantDto.getTitle(), MAX_DISPLAY_SIZE)));
|
|
|
|
return grants;
|
|
|
|
return grants;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public GrantDto findOneDto(Integer id) {
|
|
|
|
public GrantDto findOneDto(Integer id) {
|
|
|
|
return new ru.ulstu.grant.model.GrantDto(grantRepository.findOne(id));
|
|
|
|
return new GrantDto(grantRepository.findOne(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
@ -63,7 +68,10 @@ public class GrantService {
|
|
|
|
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());
|
|
|
|
//grant.setProject(grantDto.getProject()); //TODO: Исправить!
|
|
|
|
if (grantDto.getProject() != null) {
|
|
|
|
|
|
|
|
grant.setProject(projectService.findById(grantDto.getProject().getId()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//grant. setdeadlineDate(grant.getdeadlineDate() == null ? new Date() : grant.getdeadlineDate());
|
|
|
|
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
|
|
|
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
|
|
|
if (grantDto.getApplicationFileName() != null) {
|
|
|
|
if (grantDto.getApplicationFileName() != null) {
|
|
|
|
grant.setApplication(fileService.createFileFromTmp(grantDto.getApplicationFileName()));
|
|
|
|
grant.setApplication(fileService.createFileFromTmp(grantDto.getApplicationFileName()));
|
|
|
@ -71,6 +79,11 @@ public class GrantService {
|
|
|
|
return grant;
|
|
|
|
return grant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void createProject(GrantDto grantDto) {
|
|
|
|
|
|
|
|
grantDto.setProject(
|
|
|
|
|
|
|
|
new ProjectDto(projectService.save(new ProjectDto(grantDto.getTitle()))));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public Integer update(GrantDto grantDto) throws IOException {
|
|
|
|
public Integer update(GrantDto grantDto) throws IOException {
|
|
|
|
Grant grant = grantRepository.findOne(grantDto.getId());
|
|
|
|
Grant grant = grantRepository.findOne(grantDto.getId());
|
|
|
@ -130,7 +143,7 @@ public class GrantService {
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ru.ulstu.grant.model.GrantDto findGrant(int id) {
|
|
|
|
public GrantDto findGrant(int id) {
|
|
|
|
return new ru.ulstu.grant.model.GrantDto(grantRepository.getOne(id));
|
|
|
|
return new ru.ulstu.grant.model.GrantDto(grantRepository.getOne(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|