issue-106 #107

Merged
sebastian merged 18 commits from issue-106 into master 2024-03-17 09:17:11 +01:00
2 changed files with 43 additions and 1 deletions
Showing only changes of commit 160c379116 - Show all commits

View File

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

View File

@ -49,6 +49,21 @@ public class TaskService {
return new ServiceResult<>(task); 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) { private boolean existTaskByName(Collection<Task> tasks, String name) {
for(Task task : tasks) { for(Task task : tasks) {
if(task.getTaskName().equals(name)) { if(task.getTaskName().equals(name)) {
@ -94,7 +109,6 @@ public class TaskService {
taskSeriesService.deleteTaskSeriesItem(task); taskSeriesService.deleteTaskSeriesItem(task);
} }
taskRepository.delete(task); taskRepository.delete(task);
} }
public void clearTasks(Taskgroup taskgroup) { public void clearTasks(Taskgroup taskgroup) {