#101 event service edited
This commit is contained in:
parent
a5ac2bcbc2
commit
267bd5b0f3
@ -27,6 +27,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||
@ -116,7 +117,7 @@ public class ConferenceService extends BaseService {
|
||||
Conference newConference = copyFromDto(new Conference(), conferenceDto);
|
||||
newConference = conferenceRepository.save(newConference);
|
||||
conferenceNotificationService.sendCreateNotification(newConference);
|
||||
eventService.createFromConference(newConference);
|
||||
eventService.createFromObject(newConference, Collections.emptyList());
|
||||
return newConference;
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ public class GrantService extends BaseService {
|
||||
public Integer create(GrantDto grantDto) throws IOException {
|
||||
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
||||
newGrant = grantRepository.save(newGrant);
|
||||
eventService.createFromGrant(newGrant);
|
||||
eventService.createFromObject(newGrant, Collections.emptyList());
|
||||
grantNotificationService.sendCreateNotification(newGrant);
|
||||
return newGrant.getId();
|
||||
}
|
||||
@ -178,7 +178,7 @@ public class GrantService extends BaseService {
|
||||
grant.getPapers().add(paper);
|
||||
grant = grantRepository.save(grant);
|
||||
|
||||
eventService.createFromGrant(grant);
|
||||
eventService.createFromObject(grant, Collections.emptyList());
|
||||
grantNotificationService.sendCreateNotification(grant);
|
||||
|
||||
return grant;
|
||||
|
@ -17,8 +17,8 @@ import ru.ulstu.user.service.UserService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||
@ -72,7 +72,7 @@ public class ProjectService {
|
||||
public Project create(ProjectDto projectDto) throws IOException {
|
||||
Project newProject = copyFromDto(new Project(), projectDto);
|
||||
newProject = projectRepository.save(newProject);
|
||||
eventService.createFromProject(newProject);
|
||||
eventService.createFromObject(newProject, Collections.emptyList());
|
||||
return newProject;
|
||||
}
|
||||
|
||||
|
@ -18,14 +18,15 @@ import ru.ulstu.tags.service.TagService;
|
||||
import ru.ulstu.timeline.service.EventService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||
@ -83,7 +84,7 @@ public class TaskService {
|
||||
public Integer create(TaskDto taskDto) throws IOException {
|
||||
Task newTask = copyFromDto(new Task(), taskDto);
|
||||
newTask = taskRepository.save(newTask);
|
||||
eventService.createFromTask(newTask);
|
||||
eventService.createFromObject(newTask, Collections.emptyList());
|
||||
return newTask.getId();
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
package ru.ulstu.timeline.service;
|
||||
|
||||
import com.sun.jna.platform.win32.COM.util.Convert;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulstu.conference.model.Conference;
|
||||
import ru.ulstu.core.model.BaseEntity;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.grant.model.Grant;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
@ -34,6 +36,13 @@ public class EventService {
|
||||
private final TimelineService timelineService;
|
||||
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,
|
||||
@Lazy TimelineService timelineService,
|
||||
UserService userService) {
|
||||
@ -107,12 +116,17 @@ public class EventService {
|
||||
}
|
||||
|
||||
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();
|
||||
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
|
||||
objectClassName = newObject.getClass().getName();
|
||||
|
||||
switch(objectClassName) {
|
||||
case "ru.ulstu.paper.model.Paper":
|
||||
newPaper = (Paper)newObject;
|
||||
timeline.getEvents().removeAll(events);
|
||||
for (Deadline deadline : newPaper.getDeadlines()
|
||||
.stream()
|
||||
@ -130,30 +144,9 @@ public class EventService {
|
||||
timeline.getEvents().add(eventRepository.save(newEvent));
|
||||
}
|
||||
timelineService.save(timeline);
|
||||
}
|
||||
|
||||
public void updatePaperDeadlines(Paper paper) {
|
||||
List<Event> foundEvents = eventRepository.findAllByPaper(paper);
|
||||
eventRepository.delete(foundEvents);
|
||||
createFromPaper(paper, foundEvents);
|
||||
}
|
||||
|
||||
public List<Event> findByCurrentDate() {
|
||||
return eventRepository.findByCurrentDate();
|
||||
}
|
||||
|
||||
public List<Event> findAllFuture() {
|
||||
return eventRepository.findAllFuture();
|
||||
}
|
||||
|
||||
public List<EventDto> findAllFutureDto() {
|
||||
return convert(findAllFuture(), EventDto::new);
|
||||
}
|
||||
|
||||
public void createFromConference(Conference newConference) {
|
||||
List<Timeline> timelines = timelineService.findAll();
|
||||
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
|
||||
|
||||
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()))
|
||||
@ -172,17 +165,9 @@ public class EventService {
|
||||
timeline.getEvents().add(newEvent);
|
||||
timelineService.save(timeline);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateConferenceDeadlines(Conference conference) {
|
||||
eventRepository.delete(eventRepository.findAllByConference(conference));
|
||||
createFromConference(conference);
|
||||
}
|
||||
|
||||
public void createFromGrant(Grant newGrant) {
|
||||
List<Timeline> timelines = timelineService.findAll();
|
||||
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
|
||||
|
||||
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()))
|
||||
@ -204,17 +189,9 @@ public class EventService {
|
||||
timeline.getEvents().add(newEvent);
|
||||
timelineService.save(timeline);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateGrantDeadlines(Grant grant) {
|
||||
eventRepository.delete(eventRepository.findAllByGrant(grant));
|
||||
createFromGrant(grant);
|
||||
}
|
||||
|
||||
public void createFromProject(Project newProject) {
|
||||
List<Timeline> timelines = timelineService.findAll();
|
||||
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
|
||||
|
||||
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()))
|
||||
@ -229,29 +206,15 @@ public class EventService {
|
||||
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) {
|
||||
List<Event> eventList = eventRepository.findAllByConference(conference);
|
||||
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);
|
||||
|
||||
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()))
|
||||
@ -270,10 +233,54 @@ public class EventService {
|
||||
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) {
|
||||
List<Event> foundEvents = eventRepository.findAllByPaper(paper);
|
||||
eventRepository.delete(foundEvents);
|
||||
createFromObject(paper, foundEvents);
|
||||
}
|
||||
|
||||
public List<Event> findByCurrentDate() {
|
||||
return eventRepository.findByCurrentDate();
|
||||
}
|
||||
|
||||
public List<Event> findAllFuture() {
|
||||
return eventRepository.findAllFuture();
|
||||
}
|
||||
|
||||
public List<EventDto> findAllFutureDto() {
|
||||
return convert(findAllFuture(), EventDto::new);
|
||||
}
|
||||
|
||||
public void updateConferenceDeadlines(Conference conference) {
|
||||
eventRepository.delete(eventRepository.findAllByConference(conference));
|
||||
createFromObject(conference, Collections.emptyList());
|
||||
}
|
||||
|
||||
public void updateGrantDeadlines(Grant grant) {
|
||||
eventRepository.delete(eventRepository.findAllByGrant(grant));
|
||||
createFromObject(grant, Collections.emptyList());
|
||||
}
|
||||
|
||||
public void updateProjectDeadlines(Project project) {
|
||||
eventRepository.delete(eventRepository.findAllByProject(project));
|
||||
createFromObject(project, Collections.emptyList());
|
||||
}
|
||||
|
||||
public void removeConferencesEvent(Conference conference) {
|
||||
List<Event> eventList = eventRepository.findAllByConference(conference);
|
||||
eventList.forEach(event -> eventRepository.delete(event.getId()));
|
||||
}
|
||||
|
||||
public void updateTaskDeadlines(Task task) {
|
||||
eventRepository.delete(eventRepository.findAllByTask(task));
|
||||
createFromTask(task);
|
||||
createFromObject(task, Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,6 @@
|
||||
<include file="db/changelog-20190523_000000-schema.xml"/>
|
||||
<include file="db/changelog-20190528_000000-schema.xml"/>
|
||||
<include file="db/changelog-20190528_000002-schema.xml"/>
|
||||
<include file="db/changelog-20190529_000000-schema.xml"/>
|
||||
<include file="db/changelog-20190529_000001-schema.xml"/>
|
||||
<include file="db/changelog-20190601_000001-schema.xml"/>
|
||||
</databaseChangeLog>
|
Loading…
Reference in New Issue
Block a user