issue-77 #105

Merged
sebastian merged 17 commits from issue-77 into master 2024-03-16 10:12:35 +01:00
10 changed files with 158 additions and 28 deletions
Showing only changes of commit c093720a07 - Show all commits

View File

@ -2,6 +2,7 @@ package core.api.models.timemanager.tasks;
import core.api.models.timemanager.taskgroup.TaskgroupEntityInfo;
import core.entities.timemanager.Task;
import core.services.TaskSeriesService;
import java.time.LocalDate;
@ -30,7 +31,11 @@ public class TaskEntityInfo {
public TaskEntityInfo(Task task) {
this.taskID = task.getTaskID();
this.taskName = task.getTaskName();
if(task.getTaskSerieItem() != null) {
this.taskName = TaskSeriesService.insertNameIndex(task.getTaskSerieItem().getSeriesIndex(), task.getTaskName());
} else {
this.taskName = task.getTaskName();
}
this.eta = task.getEta();
this.startDate = task.getStartDate();
this.deadline = task.getDeadline();

View File

@ -3,6 +3,7 @@ package core.api.models.timemanager.tasks;
import core.api.models.timemanager.taskgroup.TaskgroupEntityInfo;
import core.entities.timemanager.Task;
import core.entities.timemanager.Taskgroup;
import core.services.TaskSeriesService;
import java.time.LocalDate;
import java.util.List;
@ -20,7 +21,11 @@ public class TaskOverviewInfo {
public TaskOverviewInfo(Task task) {
this.taskID = task.getTaskID();
this.taskName = task.getTaskName();
if(task.getTaskSerieItem() != null) {
this.taskName = TaskSeriesService.insertNameIndex(task.getTaskSerieItem().getSeriesIndex(), task.getTaskName());
} else {
this.taskName = task.getTaskName();
}
this.activeMinutes = task.getWorkTime();
this.eta = task.getEta();
this.limit = task.getDeadline();

View File

@ -1,6 +1,7 @@
package core.api.models.timemanager.tasks;
import core.entities.timemanager.Task;
import core.services.TaskSeriesService;
public class TaskShortInfo {
@ -11,7 +12,12 @@ public class TaskShortInfo {
public TaskShortInfo(Task task) {
this.taskID = task.getTaskID();
this.taskName = task.getTaskName();
if(task.getTaskSerieItem() != null) {
this.taskName = TaskSeriesService.insertNameIndex(task.getTaskSerieItem().getSeriesIndex(), task.getTaskName());
} else {
this.taskName = task.getTaskName();
}
this.finishable = task.isFinishable();
}

View File

@ -3,6 +3,7 @@ package core.api.models.timemanager.tasks;
import core.api.models.timemanager.taskgroup.TaskgroupEntityInfo;
import core.entities.timemanager.Task;
import core.entities.timemanager.Taskgroup;
import core.services.TaskSeriesService;
import java.time.LocalDate;
import java.util.ArrayList;
@ -31,7 +32,11 @@ public class TaskTaskgroupInfo {
public TaskTaskgroupInfo(Task task) {
this.taskID = task.getTaskID();
this.taskName = task.getTaskName();
if(task.getTaskSerieItem() != null) {
this.taskName = TaskSeriesService.insertNameIndex(task.getTaskSerieItem().getSeriesIndex(), task.getTaskName());
} else {
this.taskName = task.getTaskName();
}
this.eta = task.getEta();
this.startDate = task.getStartDate();
this.deadline = task.getDeadline();

View File

@ -30,9 +30,8 @@ public class Task {
@OneToMany(mappedBy = "task", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
private List<AbstractSchedule> basicTaskSchedules;
private int workTime;
@ManyToOne
@JoinColumn(referencedColumnName = "taskSerieID")
private TaskSerie taskSerie;
@OneToOne(mappedBy = "task", cascade = CascadeType.ALL, orphanRemoval = true)
private TaskSerieItem taskSerieItem;
public Task() {
this.basicTaskSchedules = new ArrayList<>();
@ -131,12 +130,12 @@ public class Task {
this.taskID = taskID;
}
public TaskSerie getTaskSerie() {
return taskSerie;
public TaskSerieItem getTaskSerieItem() {
return taskSerieItem;
}
public void setTaskSerie(TaskSerie taskSerie) {
this.taskSerie = taskSerie;
public void setTaskSerieItem(TaskSerieItem taskSerieItem) {
this.taskSerieItem = taskSerieItem;
}
public List<AbstractSchedule> getBasicTaskSchedules() {
@ -155,7 +154,7 @@ public class Task {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
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

View File

@ -12,8 +12,8 @@ public class TaskSerie {
@GeneratedValue(strategy = GenerationType.AUTO)
private long taskSerieID;
@OneToMany(orphanRemoval = false, cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "taskSerie")
List<Task> tasks = new ArrayList<>();
@OneToMany(fetch = FetchType.EAGER, mappedBy = "taskSerie")
List<TaskSerieItem> tasks = new ArrayList<>();
@ -22,15 +22,21 @@ public class TaskSerie {
return taskSerieID;
}
public List<Task> getTasks() {
public void setTaskSerieID(long taskSerieID) {
this.taskSerieID = taskSerieID;
}
public List<TaskSerieItem> getTasks() {
return tasks;
}
public void setTasks(List<Task> tasks) {
public void setTasks(List<TaskSerieItem> tasks) {
this.tasks = tasks;
}
public void addTask(Task task) {
this.tasks.add(task);
public TaskSerieItem addTask(Task task) {
TaskSerieItem taskSerieItem = new TaskSerieItem(this, task, this.tasks.size()+1);
this.tasks.add(taskSerieItem);
return taskSerieItem;
}
}

View File

@ -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;
}
}

View File

@ -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> {
}

View File

@ -5,18 +5,25 @@ import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatDayInfo;
import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatWeekInfo;
import core.entities.timemanager.Task;
import core.entities.timemanager.TaskSerie;
import core.entities.timemanager.TaskSerieItem;
import core.repositories.timemanager.TaskRepository;
import core.repositories.timemanager.TaskSerieItemRepository;
import core.repositories.timemanager.TaskSeriesRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
@Service
public class TaskSeriesService {
@Autowired private TaskRepository taskRepository;
@Autowired private TaskSeriesRepository taskSeriesRepository;
@Autowired private TaskSerieItemRepository taskSerieItemRepository;
public ServiceExitCode createTaskSeries(Task rootTask, TaskRepeatWeekInfo taskRepeatInfo) {
return ServiceExitCode.OK;
@ -27,9 +34,13 @@ public class TaskSeriesService {
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());
TaskSerie taskSerie = new TaskSerie();
TaskSerieItem rootItem = taskSerie.addTask(rootTask);
rootTask.setTaskSerieItem(rootItem);
int index = 2;
while(currentTaskDate.isBefore(taskRepeatInfo.getEndingDate())) {
Task task = Task.cloneTask(rootTask);
@ -39,18 +50,30 @@ public class TaskSeriesService {
} else if(taskRepeatInfo.getDeadlineStrategy() == DeadlineStrategy.DEADLINE_FIT_START) {
task.setDeadline(currentTaskDate.plusDays(taskRepeatInfo.getOffset()-1));
}
taskSerie.addTask(task);
task.setTaskSerie(taskSerie);
task.setTaskName(task.getTaskName().replace("${i}", convertIndexToString(index)));
TaskSerieItem taskSerieItem = taskSerie.addTask(task);
taskList.add(task);
task.setTaskSerieItem(taskSerieItem);
currentTaskDate = currentTaskDate.plusDays(taskRepeatInfo.getOffset());
index++;
}
taskSeriesRepository.save(taskSerie);
taskRepository.saveAll(taskSerie.getTasks());
taskRepository.saveAll(taskList);
taskSerieItemRepository.saveAll(taskSerie.getTasks());
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) {
if(index < 10) {
return "0" + index;
@ -58,4 +81,8 @@ public class TaskSeriesService {
return String.valueOf(index);
}
}
public static String insertNameIndex(int seriesIndex, String taskName) {
return taskName.replaceAll("\\$\\{i}", convertIndexToString(seriesIndex));
}
}

View File

@ -6,6 +6,8 @@ import core.entities.timemanager.AbstractSchedule;
import core.entities.timemanager.Task;
import core.entities.timemanager.Taskgroup;
import core.repositories.timemanager.TaskRepository;
import core.repositories.timemanager.TaskSerieItemRepository;
import core.repositories.timemanager.TaskSeriesRepository;
import core.repositories.timemanager.TaskgroupRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -20,13 +22,17 @@ public class TaskService {
private final TaskScheduleService taskScheduleService;
private final TaskgroupRepository taskgroupRepository;
private final TaskSeriesService taskSeriesService;
public TaskService(@Autowired TaskRepository taskRepository,
@Autowired TaskScheduleService taskScheduleService,
TaskgroupRepository taskgroupRepository) {
@Autowired TaskgroupRepository taskgroupRepository,
@Autowired TaskSeriesService taskSeriesService) {
this.taskRepository = taskRepository;
this.taskScheduleService = taskScheduleService;
this.taskgroupRepository = taskgroupRepository;
this.taskSeriesService = taskSeriesService;
}
public ServiceResult<Task> createTask(Taskgroup taskgroup, TaskFieldInfo taskFieldInfo) {
@ -86,13 +92,11 @@ public class TaskService {
}
public void deleteTask(Task task) {
//taskScheduleService.deleteScheduleByTask(task);
System.err.println(task.getTaskID());
task.getTaskgroup().getTasks().remove(task);
taskgroupRepository.save(task.getTaskgroup());
task.setTaskgroup(null);
taskRepository.save(task);
taskSeriesService.deleteTaskSeriesItem(task);
taskRepository.delete(task);
}
public void clearTasks(Taskgroup taskgroup) {