#101 project deadlines on timeline

This commit is contained in:
a.vasin 2019-05-29 18:27:34 +04:00
parent eceb8ec528
commit eb30d07d10
5 changed files with 71 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import ru.ulstu.grant.repository.GrantRepository;
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.repository.ProjectRepository; import ru.ulstu.project.repository.ProjectRepository;
import ru.ulstu.timeline.service.EventService;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
@ -28,17 +29,20 @@ public class ProjectService {
private final DeadlineService deadlineService; private final DeadlineService deadlineService;
private final GrantRepository grantRepository; private final GrantRepository grantRepository;
private final FileService fileService; private final FileService fileService;
private final EventService eventService;
private final UserService userService; private final UserService userService;
public ProjectService(ProjectRepository projectRepository, public ProjectService(ProjectRepository projectRepository,
DeadlineService deadlineService, DeadlineService deadlineService,
GrantRepository grantRepository, GrantRepository grantRepository,
FileService fileService, FileService fileService,
EventService eventService,
UserService userService) { UserService userService) {
this.projectRepository = projectRepository; this.projectRepository = projectRepository;
this.deadlineService = deadlineService; this.deadlineService = deadlineService;
this.grantRepository = grantRepository; this.grantRepository = grantRepository;
this.fileService = fileService; this.fileService = fileService;
this.eventService = eventService;
this.userService = userService; this.userService = userService;
} }
@ -64,6 +68,7 @@ public class ProjectService {
public Project create(ProjectDto projectDto) throws IOException { public Project create(ProjectDto projectDto) throws IOException {
Project newProject = copyFromDto(new Project(), projectDto); Project newProject = copyFromDto(new Project(), projectDto);
newProject = projectRepository.save(newProject); newProject = projectRepository.save(newProject);
eventService.createFromProject(newProject);
return newProject; return newProject;
} }
@ -74,6 +79,7 @@ public class ProjectService {
fileService.deleteFile(project.getApplication()); fileService.deleteFile(project.getApplication());
} }
projectRepository.save(copyFromDto(project, projectDto)); projectRepository.save(copyFromDto(project, projectDto));
eventService.updateProjectDeadlines(project);
return project; return project;
} }

View File

@ -5,6 +5,7 @@ import ru.ulstu.conference.model.Conference;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.project.model.Project;
import ru.ulstu.students.model.Task; import ru.ulstu.students.model.Task;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
@ -88,6 +89,10 @@ public class Event extends BaseEntity {
@JoinColumn(name = "grant_id") @JoinColumn(name = "grant_id")
private Grant grant; private Grant grant;
@ManyToOne
@JoinColumn(name = "project_id")
private Project project;
@ManyToOne @ManyToOne
@JoinColumn(name = "task_id") @JoinColumn(name = "task_id")
private Task task; private Task task;
@ -196,6 +201,14 @@ public class Event extends BaseEntity {
this.grant = grant; this.grant = grant;
} }
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
public Task getTask() { public Task getTask() {
return task; return task;
} }

View File

@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceDto;
import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.students.model.TaskDto; import ru.ulstu.students.model.TaskDto;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
@ -30,6 +31,7 @@ public class EventDto {
private PaperDto paperDto; private PaperDto paperDto;
private ConferenceDto conferenceDto; private ConferenceDto conferenceDto;
private GrantDto grantDto; private GrantDto grantDto;
private ProjectDto projectDto;
private TaskDto taskDto; private TaskDto taskDto;
@JsonCreator @JsonCreator
@ -45,6 +47,7 @@ public class EventDto {
@JsonProperty("recipients") List<UserDto> recipients, @JsonProperty("recipients") List<UserDto> recipients,
@JsonProperty("conferenceDto") ConferenceDto conferenceDto, @JsonProperty("conferenceDto") ConferenceDto conferenceDto,
@JsonProperty("grantDto") GrantDto grantDto, @JsonProperty("grantDto") GrantDto grantDto,
@JsonProperty("projectDto") ProjectDto projectDto,
@JsonProperty("taskDto") TaskDto taskDto) { @JsonProperty("taskDto") TaskDto taskDto) {
this.id = id; this.id = id;
this.title = title; this.title = title;
@ -58,6 +61,7 @@ public class EventDto {
this.paperDto = paperDto; this.paperDto = paperDto;
this.conferenceDto = conferenceDto; this.conferenceDto = conferenceDto;
this.grantDto = grantDto; this.grantDto = grantDto;
this.projectDto = projectDto;
this.taskDto = taskDto; this.taskDto = taskDto;
} }
@ -80,6 +84,9 @@ public class EventDto {
if (grantDto != null) { if (grantDto != null) {
this.grantDto = new GrantDto(event.getGrant()); this.grantDto = new GrantDto(event.getGrant());
} }
if (projectDto != null) {
this.projectDto = new ProjectDto(event.getProject());
}
if (taskDto != null) { if (taskDto != null) {
this.taskDto = new TaskDto(event.getTask()); this.taskDto = new TaskDto(event.getTask());
} }
@ -145,6 +152,14 @@ public class EventDto {
this.grantDto = grantDto; this.grantDto = grantDto;
} }
public ProjectDto getProjectDto() {
return projectDto;
}
public void setProjectDto(ProjectDto projectDto) {
this.projectDto = projectDto;
}
public TaskDto getTaskDto() { public TaskDto getTaskDto() {
return taskDto; return taskDto;
} }

View File

@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.Query;
import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.Conference;
import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.project.model.Project;
import ru.ulstu.students.model.Task; import ru.ulstu.students.model.Task;
import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.Event;
@ -23,5 +24,7 @@ public interface EventRepository extends JpaRepository<Event, Integer> {
List<Event> findAllByGrant(Grant grant); List<Event> findAllByGrant(Grant grant);
List<Event> findAllByProject(Project project);
List<Event> findAllByTask(Task task); List<Event> findAllByTask(Task task);
} }

View File

@ -8,11 +8,13 @@ import ru.ulstu.conference.model.Conference;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.project.model.Project;
import ru.ulstu.students.model.Task; import ru.ulstu.students.model.Task;
import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.Event;
import ru.ulstu.timeline.model.EventDto; import ru.ulstu.timeline.model.EventDto;
import ru.ulstu.timeline.model.Timeline; import ru.ulstu.timeline.model.Timeline;
import ru.ulstu.timeline.repository.EventRepository; import ru.ulstu.timeline.repository.EventRepository;
import ru.ulstu.user.model.User;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
@ -205,6 +207,38 @@ public class EventService {
createFromGrant(grant); createFromGrant(grant);
} }
public void createFromProject(Project newProject) {
List<Timeline> timelines = timelineService.findAll();
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
for (Deadline deadline : newProject.getDeadlines()
.stream()
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
.collect(Collectors.toList())) {
Event newEvent = new Event();
newEvent.setTitle("Дедлайн проекта");
newEvent.setStatus(Event.EventStatus.NEW);
newEvent.setExecuteDate(deadline.getDate());
newEvent.setCreateDate(new Date());
newEvent.setUpdateDate(new Date());
newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' проекта '" + newProject.getTitle() + "'");
if (newProject.getExecutors() != null) {
newEvent.setRecipients(new ArrayList(newProject.getExecutors()));
}
newEvent.getRecipients().add((User) newProject.getExecutors());
newEvent.setProject(newProject);
eventRepository.save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
}
public void updateProjectDeadlines(Project project) {
eventRepository.delete(eventRepository.findAllByProject(project));
createFromProject(project);
}
public void removeConferencesEvent(Conference conference) { public void removeConferencesEvent(Conference conference) {
List<Event> eventList = eventRepository.findAllByConference(conference); List<Event> eventList = eventRepository.findAllByConference(conference);
eventList.forEach(event -> eventRepository.delete(event.getId())); eventList.forEach(event -> eventRepository.delete(event.getId()));