|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.validation.Errors;
|
|
|
|
|
import ru.ulstu.deadline.model.Deadline;
|
|
|
|
|
import ru.ulstu.deadline.service.DeadlineService;
|
|
|
|
|
import ru.ulstu.file.model.FileDataDto;
|
|
|
|
|
import ru.ulstu.file.service.FileService;
|
|
|
|
@ -76,13 +77,11 @@ public class GrantService extends BaseService {
|
|
|
|
|
this.pingService = pingService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//++
|
|
|
|
|
public GrantDto getExistGrantById(Integer id) {
|
|
|
|
|
GrantDto grantDto = new GrantDto(findById(id));
|
|
|
|
|
return grantDto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//++
|
|
|
|
|
public List<Grant> findAll() {
|
|
|
|
|
return grantRepository.findAll();
|
|
|
|
|
}
|
|
|
|
@ -91,7 +90,6 @@ public class GrantService extends BaseService {
|
|
|
|
|
return convert(findAll(), GrantDto::new);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//++
|
|
|
|
|
@Transactional
|
|
|
|
|
public Grant create(GrantDto grantDto) throws IOException {
|
|
|
|
|
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
|
|
|
@ -164,7 +162,6 @@ public class GrantService extends BaseService {
|
|
|
|
|
return grant.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//++
|
|
|
|
|
@Transactional
|
|
|
|
|
public boolean delete(Integer grantId) throws IOException {
|
|
|
|
|
Grant grant = findById(grantId);
|
|
|
|
@ -175,30 +172,10 @@ public class GrantService extends BaseService {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//++
|
|
|
|
|
public List<Grant.GrantStatus> getGrantStatuses() {
|
|
|
|
|
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.createFromGrant(grant);
|
|
|
|
|
// grantNotificationService.sendCreateNotification(grant);
|
|
|
|
|
//
|
|
|
|
|
// return grant;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public boolean save(GrantDto grantDto, Errors errors) throws IOException {
|
|
|
|
|
grantDto.setName(grantDto.getTitle());
|
|
|
|
|
filterEmptyDeadlines(grantDto);
|
|
|
|
@ -278,26 +255,24 @@ public class GrantService extends BaseService {
|
|
|
|
|
.collect(toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//++
|
|
|
|
|
public List<PaperDto> getGrantPapers(List<Integer> paperIds) {
|
|
|
|
|
return paperService.findAllSelect(paperIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//++
|
|
|
|
|
public List<PaperDto> getAllUncompletedPapers() {
|
|
|
|
|
return paperService.findAllNotCompleted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void attachPaper(GrantDto grantDto) {
|
|
|
|
|
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());
|
|
|
|
@ -329,10 +304,11 @@ public class GrantService extends BaseService {
|
|
|
|
|
.collect(toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void filterEmptyDeadlines(GrantDto grantDto) {
|
|
|
|
|
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
|
|
|
|
@ -354,12 +330,10 @@ public class GrantService extends BaseService {
|
|
|
|
|
return grantRepository.findAllActive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//+
|
|
|
|
|
public Grant findById(Integer id) {
|
|
|
|
|
return grantRepository.findOne(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//+
|
|
|
|
|
@Transactional
|
|
|
|
|
public void ping(int grantId) throws IOException {
|
|
|
|
|
pingService.addPing(findById(grantId));
|
|
|
|
|