issue-57 #71

Merged
sebastian merged 2 commits from issue-57 into master 2023-11-18 08:39:12 +01:00
3 changed files with 28 additions and 15 deletions
Showing only changes of commit 938087f8b3 - Show all commits

View File

@ -208,4 +208,8 @@ public class TaskScheduleService {
}
return activatedSchedules;
}
public void deleteSchedules(List<AbstractSchedule> taskSchedules) {
scheduleRepository.deleteAll(taskSchedules);
}
}

View File

@ -2,6 +2,7 @@ package core.services;
import core.api.models.timemanager.tasks.TaskFieldInfo;
import core.api.models.timemanager.tasks.TaskScope;
import core.entities.timemanager.AbstractSchedule;
import core.entities.timemanager.Task;
import core.entities.timemanager.Taskgroup;
import core.repositories.timemanager.TaskRepository;
@ -103,21 +104,20 @@ public class TaskService {
task.finish();
taskRepository.save(task);
/*List<BasicTaskSchedule> removedBasicTaskSchedules = new LinkedList<>();
for(BasicTaskSchedule basicTaskSchedule : task.getBasicTaskSchedules()) {
List<AbstractSchedule> removedBasicTaskSchedules = new LinkedList<>();
for(AbstractSchedule basicTaskSchedule : task.getBasicTaskSchedules()) {
if(basicTaskSchedule.getStartTime() == null) {
removedBasicTaskSchedules.add(basicTaskSchedule);
} else if(basicTaskSchedule.getFinishedTime() == null) {
} else if(basicTaskSchedule.getStopTime() == null) {
ServiceResult<?> result = taskScheduleService.stopSchedule(basicTaskSchedule, true);
System.out.println(result);
}
}
for(BasicTaskSchedule deletedTaskSchedule: removedBasicTaskSchedules) {
task.getBasicTaskSchedules().remove(deletedTaskSchedule);
task.getBasicTaskSchedules().removeAll(removedBasicTaskSchedules);
taskRepository.save(task);
taskScheduleService.deleteBasicSchedule(deletedTaskSchedule);
}*/
taskScheduleService.deleteSchedules(removedBasicTaskSchedules);
}
public List<Task> loadAllTasks(String username, TaskScope scope) {

View File

@ -2,6 +2,7 @@ package core.tasks;
import core.api.models.timemanager.tasks.TaskFieldInfo;
import core.api.models.timemanager.tasks.TaskScope;
import core.entities.timemanager.BasicTaskSchedule;
import core.entities.timemanager.Task;
import core.entities.timemanager.Taskgroup;
import core.repositories.timemanager.TaskRepository;
@ -43,7 +44,8 @@ public class TaskServiceTest {
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
@Sql("classpath:taskRepositoryEntries.sql"),
@Sql("classpath:basicScheduleEntries.sql")
})
void createTask() {
//Situation 1: Task with that name already exists in a taskgroup
@ -85,7 +87,8 @@ public class TaskServiceTest {
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
@Sql("classpath:taskRepositoryEntries.sql"),
@Sql("classpath:basicScheduleEntries.sql")
})
void getTaskPermissions() {
//Situation 1: correct task and username
@ -110,7 +113,8 @@ public class TaskServiceTest {
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
@Sql("classpath:taskRepositoryEntries.sql"),
@Sql("classpath:basicScheduleEntries.sql")
})
void editTask() {
//Situation 1: Nothing is updated
@ -182,7 +186,8 @@ public class TaskServiceTest {
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
@Sql("classpath:taskRepositoryEntries.sql"),
@Sql("classpath:basicScheduleEntries.sql")
})
void deleteTask() {
for(long i=1; i<=15; i++) {
@ -194,7 +199,8 @@ public class TaskServiceTest {
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
@Sql("classpath:taskRepositoryEntries.sql"),
@Sql("classpath:basicScheduleEntries.sql")
})
void clearTasks() {
//Situation 1: Delete from taskgroup with no tasks
@ -212,7 +218,8 @@ public class TaskServiceTest {
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
@Sql("classpath:taskRepositoryEntries.sql"),
@Sql("classpath:basicScheduleEntries.sql")
})
void finishTask() {
taskService.finishTask(entityManager.find(Task.class, 1L));
@ -220,12 +227,14 @@ public class TaskServiceTest {
taskService.finishTask(entityManager.find(Task.class, 2L));
assertTrue(entityManager.find(Task.class, 1L).isFinished());
assertThat(entityManager.find(BasicTaskSchedule.class, 2L)).isNull();
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
@Sql("classpath:taskRepositoryEntries.sql"),
@Sql("classpath:basicScheduleEntries.sql")
})
void loadAllTasks() {
//Situation 1: No tasks existing