Merge branch '101-projecgt-timeline' of gitlab.com:romanov73/ng-tracker into 101-projecgt-timeline

This commit is contained in:
Васин Антон 2019-06-03 14:40:09 +03:00
commit dc52968ddf
11 changed files with 153 additions and 145 deletions

View File

@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Collections;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.springframework.util.ObjectUtils.isEmpty; import static org.springframework.util.ObjectUtils.isEmpty;
@ -116,7 +117,7 @@ public class ConferenceService extends BaseService {
Conference newConference = copyFromDto(new Conference(), conferenceDto); Conference newConference = copyFromDto(new Conference(), conferenceDto);
newConference = conferenceRepository.save(newConference); newConference = conferenceRepository.save(newConference);
conferenceNotificationService.sendCreateNotification(newConference); conferenceNotificationService.sendCreateNotification(newConference);
eventService.createFromConference(newConference); eventService.createFromObject(newConference, Collections.emptyList());
return newConference; return newConference;
} }

View File

@ -90,7 +90,7 @@ public class GrantService extends BaseService {
public Integer create(GrantDto grantDto) throws IOException { public Integer 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.createFromGrant(newGrant); eventService.createFromObject(newGrant, Collections.emptyList());
grantNotificationService.sendCreateNotification(newGrant); grantNotificationService.sendCreateNotification(newGrant);
return newGrant.getId(); return newGrant.getId();
} }
@ -178,7 +178,7 @@ public class GrantService extends BaseService {
grant.getPapers().add(paper); grant.getPapers().add(paper);
grant = grantRepository.save(grant); grant = grantRepository.save(grant);
eventService.createFromGrant(grant); eventService.createFromObject(grant, Collections.emptyList());
grantNotificationService.sendCreateNotification(grant); grantNotificationService.sendCreateNotification(grant);
return grant; return grant;

View File

@ -42,8 +42,9 @@ public class LatexService {
InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream()); InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream());
try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
while ((bufferedReader.readLine()) != null) { String line = bufferedReader.readLine();
// while (line != null) {
line = bufferedReader.readLine();
} }
} }

View File

@ -17,8 +17,8 @@ import ru.ulstu.user.service.UserService;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import static org.springframework.util.ObjectUtils.isEmpty; import static org.springframework.util.ObjectUtils.isEmpty;
@ -72,7 +72,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); eventService.createFromObject(newProject, Collections.emptyList());
return newProject; return newProject;
} }

View File

@ -18,14 +18,15 @@ import ru.ulstu.tags.service.TagService;
import ru.ulstu.timeline.service.EventService; import ru.ulstu.timeline.service.EventService;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.springframework.util.ObjectUtils.isEmpty; import static org.springframework.util.ObjectUtils.isEmpty;
@ -83,7 +84,7 @@ public class TaskService {
public Integer create(TaskDto taskDto) throws IOException { public Integer create(TaskDto taskDto) throws IOException {
Task newTask = copyFromDto(new Task(), taskDto); Task newTask = copyFromDto(new Task(), taskDto);
newTask = taskRepository.save(newTask); newTask = taskRepository.save(newTask);
eventService.createFromTask(newTask); eventService.createFromObject(newTask, Collections.emptyList());
return newTask.getId(); return newTask.getId();
} }

View File

@ -1,10 +1,12 @@
package ru.ulstu.timeline.service; package ru.ulstu.timeline.service;
import com.sun.jna.platform.win32.COM.util.Convert;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.Conference;
import ru.ulstu.core.model.BaseEntity;
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;
@ -34,6 +36,13 @@ public class EventService {
private final TimelineService timelineService; private final TimelineService timelineService;
private final UserService userService; private final UserService userService;
private String objectClassName = "";
private Paper newPaper = new Paper();
private Conference newConference = new Conference();
private Grant newGrant = new Grant();
private Project newProject = new Project();
private Task newTask = new Task();
public EventService(EventRepository eventRepository, public EventService(EventRepository eventRepository,
@Lazy TimelineService timelineService, @Lazy TimelineService timelineService,
UserService userService) { UserService userService) {
@ -107,35 +116,133 @@ public class EventService {
} }
public void createFromPaper(Paper newPaper) { public void createFromPaper(Paper newPaper) {
createFromPaper(newPaper, Collections.emptyList()); createFromObject(newPaper, Collections.emptyList());
} }
public void createFromPaper(Paper newPaper, List<Event> events) { public void createFromObject(Object newObject, List<Event> events) {
List<Timeline> timelines = timelineService.findAll(); List<Timeline> timelines = timelineService.findAll();
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
timeline.getEvents().removeAll(events); objectClassName = newObject.getClass().getName();
for (Deadline deadline : newPaper.getDeadlines() switch(objectClassName) {
.stream() case "ru.ulstu.paper.model.Paper":
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) newPaper = (Paper)newObject;
.collect(Collectors.toList())) { timeline.getEvents().removeAll(events);
Event newEvent = new Event(); for (Deadline deadline : newPaper.getDeadlines()
newEvent.setTitle("Дедлайн статьи"); .stream()
newEvent.setStatus(Event.EventStatus.NEW); .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
newEvent.setExecuteDate(deadline.getDate()); .collect(Collectors.toList())) {
newEvent.setCreateDate(new Date()); Event newEvent = new Event();
newEvent.setUpdateDate(new Date()); newEvent.setTitle("Дедлайн статьи");
newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); newEvent.setStatus(Event.EventStatus.NEW);
newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); newEvent.setExecuteDate(deadline.getDate());
newEvent.setPaper(newPaper); newEvent.setCreateDate(new Date());
timeline.getEvents().add(eventRepository.save(newEvent)); newEvent.setUpdateDate(new Date());
} newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'");
timelineService.save(timeline); newEvent.setRecipients(new ArrayList(newPaper.getAuthors()));
} newEvent.setPaper(newPaper);
timeline.getEvents().add(eventRepository.save(newEvent));
}
timelineService.save(timeline);
break;
case "ru.ulstu.conference.model.Conference":
newConference = (Conference)newObject;
for (Deadline deadline : newConference.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() + "' конференции '" + newConference.getTitle() + "'");
newConference.getUsers().forEach(conferenceUser -> newEvent.getRecipients().add(conferenceUser.getUser()));
newEvent.setConference(newConference);
save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
break;
case "ru.ulstu.grant.model.Grant":
newGrant = (Grant)newObject;
for (Deadline deadline : newGrant.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() + "' гранта '" + newGrant.getTitle() + "'");
if (newGrant.getAuthors() != null) {
newEvent.setRecipients(new ArrayList(newGrant.getAuthors()));
}
newEvent.getRecipients().add(newGrant.getLeader());
newEvent.setGrant(newGrant);
eventRepository.save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
break;
case "ru.ulstu.project.model.Project":
newProject = (Project)newObject;
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.setProject(newProject);
eventRepository.save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
break;
case "ru.ulstu.students.model.Task":
newTask = (Task)newObject;
for (Deadline deadline : newTask.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() + "' задачи '" + newTask.getTitle() + "'");
newEvent.getRecipients().add(userService.getCurrentUser());
newEvent.setTask(newTask);
eventRepository.save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
System.out.println("5");
break;
default:
System.out.println("No such object");
break;
}
}
public void updatePaperDeadlines(Paper paper) { public void updatePaperDeadlines(Paper paper) {
List<Event> foundEvents = eventRepository.findAllByPaper(paper); List<Event> foundEvents = eventRepository.findAllByPaper(paper);
eventRepository.delete(foundEvents); eventRepository.delete(foundEvents);
createFromPaper(paper, foundEvents); createFromObject(paper, foundEvents);
} }
public List<Event> findByCurrentDate() { public List<Event> findByCurrentDate() {
@ -150,97 +257,19 @@ public class EventService {
return convert(findAllFuture(), EventDto::new); return convert(findAllFuture(), EventDto::new);
} }
public void createFromConference(Conference newConference) {
List<Timeline> timelines = timelineService.findAll();
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
for (Deadline deadline : newConference.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() + "' конференции '" + newConference.getTitle() + "'");
newConference.getUsers().forEach(conferenceUser -> newEvent.getRecipients().add(conferenceUser.getUser()));
newEvent.setConference(newConference);
save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
}
public void updateConferenceDeadlines(Conference conference) { public void updateConferenceDeadlines(Conference conference) {
eventRepository.delete(eventRepository.findAllByConference(conference)); eventRepository.delete(eventRepository.findAllByConference(conference));
createFromConference(conference); createFromObject(conference, Collections.emptyList());
}
public void createFromGrant(Grant newGrant) {
List<Timeline> timelines = timelineService.findAll();
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
for (Deadline deadline : newGrant.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() + "' гранта '" + newGrant.getTitle() + "'");
if (newGrant.getAuthors() != null) {
newEvent.setRecipients(new ArrayList(newGrant.getAuthors()));
}
newEvent.getRecipients().add(newGrant.getLeader());
newEvent.setGrant(newGrant);
eventRepository.save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
} }
public void updateGrantDeadlines(Grant grant) { public void updateGrantDeadlines(Grant grant) {
eventRepository.delete(eventRepository.findAllByGrant(grant)); eventRepository.delete(eventRepository.findAllByGrant(grant));
createFromGrant(grant); createFromObject(grant, Collections.emptyList());
}
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) { public void updateProjectDeadlines(Project project) {
eventRepository.delete(eventRepository.findAllByProject(project)); eventRepository.delete(eventRepository.findAllByProject(project));
createFromProject(project); createFromObject(project, Collections.emptyList());
} }
public void removeConferencesEvent(Conference conference) { public void removeConferencesEvent(Conference conference) {
@ -248,32 +277,8 @@ public class EventService {
eventList.forEach(event -> eventRepository.delete(event.getId())); eventList.forEach(event -> eventRepository.delete(event.getId()));
} }
public void createFromTask(Task newTask) {
List<Timeline> timelines = timelineService.findAll();
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
for (Deadline deadline : newTask.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() + "' задачи '" + newTask.getTitle() + "'");
newEvent.getRecipients().add(userService.getCurrentUser());
newEvent.setTask(newTask);
eventRepository.save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
}
}
public void updateTaskDeadlines(Task task) { public void updateTaskDeadlines(Task task) {
eventRepository.delete(eventRepository.findAllByTask(task)); eventRepository.delete(eventRepository.findAllByTask(task));
createFromTask(task); createFromObject(task, Collections.emptyList());
} }
} }

View File

@ -2,7 +2,7 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="anton" id="20190528_000000-3"> <changeSet author="anton" id="20190528_000002-1">
<createTable tableName="deadline_executors"> <createTable tableName="deadline_executors">
<column name="deadline_id" type="integer"/> <column name="deadline_id" type="integer"/>
<column name="executors_id" type="integer"/> <column name="executors_id" type="integer"/>

View File

@ -2,9 +2,9 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="anton" id="20190428_000000-1"> <changeSet author="anton" id="20190601_000000-1">
<update tableName="project"> <update tableName="project">
<column name="status" value="APPLICATION"/> <column name="status" value="TECHNICAL_TASK"/>
</update> </update>
</changeSet> </changeSet>
</databaseChangeLog> </databaseChangeLog>

View File

@ -35,7 +35,6 @@
<include file="db/changelog-20190422_000000-schema.xml"/> <include file="db/changelog-20190422_000000-schema.xml"/>
<include file="db/changelog-20190424_000000-schema.xml"/> <include file="db/changelog-20190424_000000-schema.xml"/>
<include file="db/changelog-20190426_000000-schema.xml"/> <include file="db/changelog-20190426_000000-schema.xml"/>
<include file="db/changelog-20190428_000000-schema.xml"/>
<include file="db/changelog-20190430_000000-schema.xml"/> <include file="db/changelog-20190430_000000-schema.xml"/>
<include file="db/changelog-20190505_000000-schema.xml"/> <include file="db/changelog-20190505_000000-schema.xml"/>
<include file="db/changelog-20190505_000001-schema.xml"/> <include file="db/changelog-20190505_000001-schema.xml"/>
@ -52,4 +51,5 @@
<include file="db/changelog-20190528_000002-schema.xml"/> <include file="db/changelog-20190528_000002-schema.xml"/>
<include file="db/changelog-20190529_000000-schema.xml"/> <include file="db/changelog-20190529_000000-schema.xml"/>
<include file="db/changelog-20190529_000001-schema.xml"/> <include file="db/changelog-20190529_000001-schema.xml"/>
<include file="db/changelog-20190601_000001-schema.xml"/>
</databaseChangeLog> </databaseChangeLog>

View File

@ -99,7 +99,7 @@ public class ProjectServiceTest {
public void create() throws IOException { public void create() throws IOException {
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
when(projectRepository.save(new Project())).thenReturn(project); when(projectRepository.save(new Project())).thenReturn(project);
eventService.createFromProject(new Project()); eventService.createFromObject(new Project(), Collections.emptyList());
projectDto.setTitle(TITLE); projectDto.setTitle(TITLE);
projectDto.setDeadlines(deadlines); projectDto.setDeadlines(deadlines);

View File

@ -136,7 +136,7 @@ public class TaskServiceTest {
when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags); when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags);
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
when(taskRepository.save(new Task())).thenReturn(task); when(taskRepository.save(new Task())).thenReturn(task);
eventService.createFromTask(new Task()); eventService.createFromObject(new Task(), Collections.emptyList());
taskDto.setTags(tags); taskDto.setTags(tags);
taskDto.setDeadlines(deadlines); taskDto.setDeadlines(deadlines);