Deleting of Tasks, Taskseries and TaskSerieItems
This commit is contained in:
parent
59ee88b5fe
commit
c093720a07
@ -2,6 +2,7 @@ package core.api.models.timemanager.tasks;
|
|||||||
|
|
||||||
import core.api.models.timemanager.taskgroup.TaskgroupEntityInfo;
|
import core.api.models.timemanager.taskgroup.TaskgroupEntityInfo;
|
||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
|
import core.services.TaskSeriesService;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
@ -30,7 +31,11 @@ public class TaskEntityInfo {
|
|||||||
|
|
||||||
public TaskEntityInfo(Task task) {
|
public TaskEntityInfo(Task task) {
|
||||||
this.taskID = task.getTaskID();
|
this.taskID = task.getTaskID();
|
||||||
|
if(task.getTaskSerieItem() != null) {
|
||||||
|
this.taskName = TaskSeriesService.insertNameIndex(task.getTaskSerieItem().getSeriesIndex(), task.getTaskName());
|
||||||
|
} else {
|
||||||
this.taskName = task.getTaskName();
|
this.taskName = task.getTaskName();
|
||||||
|
}
|
||||||
this.eta = task.getEta();
|
this.eta = task.getEta();
|
||||||
this.startDate = task.getStartDate();
|
this.startDate = task.getStartDate();
|
||||||
this.deadline = task.getDeadline();
|
this.deadline = task.getDeadline();
|
||||||
|
@ -3,6 +3,7 @@ package core.api.models.timemanager.tasks;
|
|||||||
import core.api.models.timemanager.taskgroup.TaskgroupEntityInfo;
|
import core.api.models.timemanager.taskgroup.TaskgroupEntityInfo;
|
||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
import core.entities.timemanager.Taskgroup;
|
import core.entities.timemanager.Taskgroup;
|
||||||
|
import core.services.TaskSeriesService;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -20,7 +21,11 @@ public class TaskOverviewInfo {
|
|||||||
|
|
||||||
public TaskOverviewInfo(Task task) {
|
public TaskOverviewInfo(Task task) {
|
||||||
this.taskID = task.getTaskID();
|
this.taskID = task.getTaskID();
|
||||||
|
if(task.getTaskSerieItem() != null) {
|
||||||
|
this.taskName = TaskSeriesService.insertNameIndex(task.getTaskSerieItem().getSeriesIndex(), task.getTaskName());
|
||||||
|
} else {
|
||||||
this.taskName = task.getTaskName();
|
this.taskName = task.getTaskName();
|
||||||
|
}
|
||||||
this.activeMinutes = task.getWorkTime();
|
this.activeMinutes = task.getWorkTime();
|
||||||
this.eta = task.getEta();
|
this.eta = task.getEta();
|
||||||
this.limit = task.getDeadline();
|
this.limit = task.getDeadline();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package core.api.models.timemanager.tasks;
|
package core.api.models.timemanager.tasks;
|
||||||
|
|
||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
|
import core.services.TaskSeriesService;
|
||||||
|
|
||||||
public class TaskShortInfo {
|
public class TaskShortInfo {
|
||||||
|
|
||||||
@ -11,7 +12,12 @@ public class TaskShortInfo {
|
|||||||
|
|
||||||
public TaskShortInfo(Task task) {
|
public TaskShortInfo(Task task) {
|
||||||
this.taskID = task.getTaskID();
|
this.taskID = task.getTaskID();
|
||||||
|
if(task.getTaskSerieItem() != null) {
|
||||||
|
this.taskName = TaskSeriesService.insertNameIndex(task.getTaskSerieItem().getSeriesIndex(), task.getTaskName());
|
||||||
|
} else {
|
||||||
this.taskName = task.getTaskName();
|
this.taskName = task.getTaskName();
|
||||||
|
}
|
||||||
|
|
||||||
this.finishable = task.isFinishable();
|
this.finishable = task.isFinishable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package core.api.models.timemanager.tasks;
|
|||||||
import core.api.models.timemanager.taskgroup.TaskgroupEntityInfo;
|
import core.api.models.timemanager.taskgroup.TaskgroupEntityInfo;
|
||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
import core.entities.timemanager.Taskgroup;
|
import core.entities.timemanager.Taskgroup;
|
||||||
|
import core.services.TaskSeriesService;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -31,7 +32,11 @@ public class TaskTaskgroupInfo {
|
|||||||
|
|
||||||
public TaskTaskgroupInfo(Task task) {
|
public TaskTaskgroupInfo(Task task) {
|
||||||
this.taskID = task.getTaskID();
|
this.taskID = task.getTaskID();
|
||||||
|
if(task.getTaskSerieItem() != null) {
|
||||||
|
this.taskName = TaskSeriesService.insertNameIndex(task.getTaskSerieItem().getSeriesIndex(), task.getTaskName());
|
||||||
|
} else {
|
||||||
this.taskName = task.getTaskName();
|
this.taskName = task.getTaskName();
|
||||||
|
}
|
||||||
this.eta = task.getEta();
|
this.eta = task.getEta();
|
||||||
this.startDate = task.getStartDate();
|
this.startDate = task.getStartDate();
|
||||||
this.deadline = task.getDeadline();
|
this.deadline = task.getDeadline();
|
||||||
|
@ -30,9 +30,8 @@ public class Task {
|
|||||||
@OneToMany(mappedBy = "task", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
|
@OneToMany(mappedBy = "task", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
|
||||||
private List<AbstractSchedule> basicTaskSchedules;
|
private List<AbstractSchedule> basicTaskSchedules;
|
||||||
private int workTime;
|
private int workTime;
|
||||||
@ManyToOne
|
@OneToOne(mappedBy = "task", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
@JoinColumn(referencedColumnName = "taskSerieID")
|
private TaskSerieItem taskSerieItem;
|
||||||
private TaskSerie taskSerie;
|
|
||||||
|
|
||||||
public Task() {
|
public Task() {
|
||||||
this.basicTaskSchedules = new ArrayList<>();
|
this.basicTaskSchedules = new ArrayList<>();
|
||||||
@ -131,12 +130,12 @@ public class Task {
|
|||||||
this.taskID = taskID;
|
this.taskID = taskID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskSerie getTaskSerie() {
|
public TaskSerieItem getTaskSerieItem() {
|
||||||
return taskSerie;
|
return taskSerieItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTaskSerie(TaskSerie taskSerie) {
|
public void setTaskSerieItem(TaskSerieItem taskSerieItem) {
|
||||||
this.taskSerie = taskSerie;
|
this.taskSerieItem = taskSerieItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AbstractSchedule> getBasicTaskSchedules() {
|
public List<AbstractSchedule> getBasicTaskSchedules() {
|
||||||
@ -155,7 +154,7 @@ public class Task {
|
|||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
Task task = (Task) o;
|
Task task = (Task) o;
|
||||||
return taskID == task.taskID && eta == task.eta && finished == task.finished && workTime == task.workTime && Objects.equals(taskgroup, task.taskgroup) && Objects.equals(taskName, task.taskName) && Objects.equals(startDate, task.startDate) && Objects.equals(deadline, task.deadline);
|
return taskID == task.taskID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -12,8 +12,8 @@ public class TaskSerie {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private long taskSerieID;
|
private long taskSerieID;
|
||||||
|
|
||||||
@OneToMany(orphanRemoval = false, cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "taskSerie")
|
@OneToMany(fetch = FetchType.EAGER, mappedBy = "taskSerie")
|
||||||
List<Task> tasks = new ArrayList<>();
|
List<TaskSerieItem> tasks = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -22,15 +22,21 @@ public class TaskSerie {
|
|||||||
return taskSerieID;
|
return taskSerieID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Task> getTasks() {
|
public void setTaskSerieID(long taskSerieID) {
|
||||||
|
this.taskSerieID = taskSerieID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TaskSerieItem> getTasks() {
|
||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTasks(List<Task> tasks) {
|
public void setTasks(List<TaskSerieItem> tasks) {
|
||||||
this.tasks = tasks;
|
this.tasks = tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTask(Task task) {
|
public TaskSerieItem addTask(Task task) {
|
||||||
this.tasks.add(task);
|
TaskSerieItem taskSerieItem = new TaskSerieItem(this, task, this.tasks.size()+1);
|
||||||
|
this.tasks.add(taskSerieItem);
|
||||||
|
return taskSerieItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
package core.entities.timemanager;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "task_series_items")
|
||||||
|
public class TaskSerieItem {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private long itemID;
|
||||||
|
|
||||||
|
@ManyToOne()
|
||||||
|
@JoinColumn(referencedColumnName = "taskSerieID")
|
||||||
|
private TaskSerie taskSerie;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name = "task_id")
|
||||||
|
private Task task;
|
||||||
|
|
||||||
|
|
||||||
|
private int seriesIndex;
|
||||||
|
|
||||||
|
public TaskSerieItem(TaskSerie taskSerie, Task task, int index) {
|
||||||
|
this.taskSerie = taskSerie;
|
||||||
|
this.seriesIndex = index;
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskSerieItem() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getItemID() {
|
||||||
|
return itemID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemID(long itemID) {
|
||||||
|
this.itemID = itemID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskSerie getTaskSerie() {
|
||||||
|
return taskSerie;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskSerie(TaskSerie taskSerie) {
|
||||||
|
this.taskSerie = taskSerie;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSeriesIndex() {
|
||||||
|
return seriesIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeriesIndex(int seriesIndex) {
|
||||||
|
this.seriesIndex = seriesIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task getTask() {
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTask(Task task) {
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package core.repositories.timemanager;
|
||||||
|
|
||||||
|
import core.entities.timemanager.TaskSerieItem;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface TaskSerieItemRepository extends CrudRepository<TaskSerieItem, Long> {
|
||||||
|
}
|
@ -5,18 +5,25 @@ import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatDayInfo;
|
|||||||
import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatWeekInfo;
|
import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatWeekInfo;
|
||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
import core.entities.timemanager.TaskSerie;
|
import core.entities.timemanager.TaskSerie;
|
||||||
|
import core.entities.timemanager.TaskSerieItem;
|
||||||
import core.repositories.timemanager.TaskRepository;
|
import core.repositories.timemanager.TaskRepository;
|
||||||
|
import core.repositories.timemanager.TaskSerieItemRepository;
|
||||||
import core.repositories.timemanager.TaskSeriesRepository;
|
import core.repositories.timemanager.TaskSeriesRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class TaskSeriesService {
|
public class TaskSeriesService {
|
||||||
|
|
||||||
@Autowired private TaskRepository taskRepository;
|
@Autowired private TaskRepository taskRepository;
|
||||||
@Autowired private TaskSeriesRepository taskSeriesRepository;
|
@Autowired private TaskSeriesRepository taskSeriesRepository;
|
||||||
|
@Autowired private TaskSerieItemRepository taskSerieItemRepository;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ServiceExitCode createTaskSeries(Task rootTask, TaskRepeatWeekInfo taskRepeatInfo) {
|
public ServiceExitCode createTaskSeries(Task rootTask, TaskRepeatWeekInfo taskRepeatInfo) {
|
||||||
return ServiceExitCode.OK;
|
return ServiceExitCode.OK;
|
||||||
@ -27,9 +34,13 @@ public class TaskSeriesService {
|
|||||||
return ServiceExitCode.INVALID_PARAMETER;
|
return ServiceExitCode.INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
rootTask.setTaskName(rootTask.getTaskName().replace("${i}", convertIndexToString(1)));
|
List<Task> taskList = new ArrayList<>();
|
||||||
|
taskList.add(rootTask);
|
||||||
LocalDate currentTaskDate = rootTask.getStartDate().plusDays(taskRepeatInfo.getOffset());
|
LocalDate currentTaskDate = rootTask.getStartDate().plusDays(taskRepeatInfo.getOffset());
|
||||||
TaskSerie taskSerie = new TaskSerie();
|
TaskSerie taskSerie = new TaskSerie();
|
||||||
|
|
||||||
|
TaskSerieItem rootItem = taskSerie.addTask(rootTask);
|
||||||
|
rootTask.setTaskSerieItem(rootItem);
|
||||||
int index = 2;
|
int index = 2;
|
||||||
while(currentTaskDate.isBefore(taskRepeatInfo.getEndingDate())) {
|
while(currentTaskDate.isBefore(taskRepeatInfo.getEndingDate())) {
|
||||||
Task task = Task.cloneTask(rootTask);
|
Task task = Task.cloneTask(rootTask);
|
||||||
@ -39,18 +50,30 @@ public class TaskSeriesService {
|
|||||||
} else if(taskRepeatInfo.getDeadlineStrategy() == DeadlineStrategy.DEADLINE_FIT_START) {
|
} else if(taskRepeatInfo.getDeadlineStrategy() == DeadlineStrategy.DEADLINE_FIT_START) {
|
||||||
task.setDeadline(currentTaskDate.plusDays(taskRepeatInfo.getOffset()-1));
|
task.setDeadline(currentTaskDate.plusDays(taskRepeatInfo.getOffset()-1));
|
||||||
}
|
}
|
||||||
taskSerie.addTask(task);
|
TaskSerieItem taskSerieItem = taskSerie.addTask(task);
|
||||||
task.setTaskSerie(taskSerie);
|
taskList.add(task);
|
||||||
task.setTaskName(task.getTaskName().replace("${i}", convertIndexToString(index)));
|
task.setTaskSerieItem(taskSerieItem);
|
||||||
currentTaskDate = currentTaskDate.plusDays(taskRepeatInfo.getOffset());
|
currentTaskDate = currentTaskDate.plusDays(taskRepeatInfo.getOffset());
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
taskSeriesRepository.save(taskSerie);
|
taskSeriesRepository.save(taskSerie);
|
||||||
taskRepository.saveAll(taskSerie.getTasks());
|
taskRepository.saveAll(taskList);
|
||||||
|
taskSerieItemRepository.saveAll(taskSerie.getTasks());
|
||||||
|
|
||||||
return ServiceExitCode.OK;
|
return ServiceExitCode.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteTaskSeriesItem(Task task) {
|
||||||
|
TaskSerieItem item = task.getTaskSerieItem();
|
||||||
|
TaskSerie taskSerie = task.getTaskSerieItem().getTaskSerie();
|
||||||
|
task.setTaskSerieItem(null);
|
||||||
|
taskSerieItemRepository.delete(item);
|
||||||
|
if(taskSerie.getTasks().size() == 1) {
|
||||||
|
taskSeriesRepository.delete(taskSerie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String convertIndexToString(int index) {
|
public static String convertIndexToString(int index) {
|
||||||
if(index < 10) {
|
if(index < 10) {
|
||||||
return "0" + index;
|
return "0" + index;
|
||||||
@ -58,4 +81,8 @@ public class TaskSeriesService {
|
|||||||
return String.valueOf(index);
|
return String.valueOf(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String insertNameIndex(int seriesIndex, String taskName) {
|
||||||
|
return taskName.replaceAll("\\$\\{i}", convertIndexToString(seriesIndex));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import core.entities.timemanager.AbstractSchedule;
|
|||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
import core.entities.timemanager.Taskgroup;
|
import core.entities.timemanager.Taskgroup;
|
||||||
import core.repositories.timemanager.TaskRepository;
|
import core.repositories.timemanager.TaskRepository;
|
||||||
|
import core.repositories.timemanager.TaskSerieItemRepository;
|
||||||
|
import core.repositories.timemanager.TaskSeriesRepository;
|
||||||
import core.repositories.timemanager.TaskgroupRepository;
|
import core.repositories.timemanager.TaskgroupRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -20,13 +22,17 @@ public class TaskService {
|
|||||||
private final TaskScheduleService taskScheduleService;
|
private final TaskScheduleService taskScheduleService;
|
||||||
private final TaskgroupRepository taskgroupRepository;
|
private final TaskgroupRepository taskgroupRepository;
|
||||||
|
|
||||||
|
private final TaskSeriesService taskSeriesService;
|
||||||
|
|
||||||
|
|
||||||
public TaskService(@Autowired TaskRepository taskRepository,
|
public TaskService(@Autowired TaskRepository taskRepository,
|
||||||
@Autowired TaskScheduleService taskScheduleService,
|
@Autowired TaskScheduleService taskScheduleService,
|
||||||
TaskgroupRepository taskgroupRepository) {
|
@Autowired TaskgroupRepository taskgroupRepository,
|
||||||
|
@Autowired TaskSeriesService taskSeriesService) {
|
||||||
this.taskRepository = taskRepository;
|
this.taskRepository = taskRepository;
|
||||||
this.taskScheduleService = taskScheduleService;
|
this.taskScheduleService = taskScheduleService;
|
||||||
this.taskgroupRepository = taskgroupRepository;
|
this.taskgroupRepository = taskgroupRepository;
|
||||||
|
this.taskSeriesService = taskSeriesService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceResult<Task> createTask(Taskgroup taskgroup, TaskFieldInfo taskFieldInfo) {
|
public ServiceResult<Task> createTask(Taskgroup taskgroup, TaskFieldInfo taskFieldInfo) {
|
||||||
@ -86,13 +92,11 @@ public class TaskService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deleteTask(Task task) {
|
public void deleteTask(Task task) {
|
||||||
//taskScheduleService.deleteScheduleByTask(task);
|
|
||||||
System.err.println(task.getTaskID());
|
|
||||||
task.getTaskgroup().getTasks().remove(task);
|
task.getTaskgroup().getTasks().remove(task);
|
||||||
taskgroupRepository.save(task.getTaskgroup());
|
taskgroupRepository.save(task.getTaskgroup());
|
||||||
task.setTaskgroup(null);
|
taskSeriesService.deleteTaskSeriesItem(task);
|
||||||
taskRepository.save(task);
|
|
||||||
taskRepository.delete(task);
|
taskRepository.delete(task);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearTasks(Taskgroup taskgroup) {
|
public void clearTasks(Taskgroup taskgroup) {
|
||||||
|
Loading…
Reference in New Issue
Block a user