Adapt Task to consider subtasks and implement service to create Subtasks
All checks were successful
Java CI with Maven / build-and-push-frontend (push) Successful in 7s
Java CI with Maven / build-and-push-backend (push) Successful in 7s

This commit is contained in:
Sebastian Böckelmann 2024-03-16 10:33:35 +01:00
parent f7d844fd51
commit 160c379116
2 changed files with 43 additions and 1 deletions

View File

@ -33,6 +33,13 @@ public class Task {
@OneToOne(mappedBy = "task", cascade = CascadeType.ALL, orphanRemoval = true)
private TaskSerieItem taskSerieItem;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Task> subtasks;
@ManyToOne
@JoinColumn(name = "parent")
private Task parent;
public Task() {
this.basicTaskSchedules = new ArrayList<>();
}
@ -149,6 +156,27 @@ public class Task {
this.basicTaskSchedules = basicTaskSchedules;
}
public void addSubtask(Task subtask) {
subtask.setParent(this);
this.subtasks.add(subtask);
}
public Set<Task> getSubtasks() {
return subtasks;
}
public void setSubtasks(Set<Task> subtasks) {
this.subtasks = subtasks;
}
public Task getParent() {
return parent;
}
public void setParent(Task parent) {
this.parent = parent;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -49,6 +49,21 @@ public class TaskService {
return new ServiceResult<>(task);
}
public ServiceResult<Task> createSubTask(Task parentTask, TaskFieldInfo taskFieldInfo) {
if(taskFieldInfo.getStartDate().isBefore(parentTask.getStartDate()) ||
taskFieldInfo.getDeadline().isAfter(parentTask.getDeadline()) ||
taskFieldInfo.getDeadline().isBefore(taskFieldInfo.getStartDate())) {
return new ServiceResult<>(ServiceExitCode.INVALID_PARAMETER);
}
Task task = new Task(parentTask.getTaskgroup(), taskFieldInfo);
parentTask.getTaskgroup().getTasks().add(task);
parentTask.addSubtask(task);
taskRepository.save(task);
return new ServiceResult<>(task);
}
private boolean existTaskByName(Collection<Task> tasks, String name) {
for(Task task : tasks) {
if(task.getTaskName().equals(name)) {
@ -94,7 +109,6 @@ public class TaskService {
taskSeriesService.deleteTaskSeriesItem(task);
}
taskRepository.delete(task);
}
public void clearTasks(Taskgroup taskgroup) {