Remove unstarted schedules from db when task is finished
This commit is contained in:
		
							parent
							
								
									5441ce0fbc
								
							
						
					
					
						commit
						938087f8b3
					
				@ -208,4 +208,8 @@ public class TaskScheduleService {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return activatedSchedules;
 | 
					        return activatedSchedules;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void deleteSchedules(List<AbstractSchedule> taskSchedules) {
 | 
				
			||||||
 | 
					        scheduleRepository.deleteAll(taskSchedules);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@ package core.services;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import core.api.models.timemanager.tasks.TaskFieldInfo;
 | 
					import core.api.models.timemanager.tasks.TaskFieldInfo;
 | 
				
			||||||
import core.api.models.timemanager.tasks.TaskScope;
 | 
					import core.api.models.timemanager.tasks.TaskScope;
 | 
				
			||||||
 | 
					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;
 | 
				
			||||||
@ -103,21 +104,20 @@ public class TaskService {
 | 
				
			|||||||
        task.finish();
 | 
					        task.finish();
 | 
				
			||||||
        taskRepository.save(task);
 | 
					        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) {
 | 
					            if(basicTaskSchedule.getStartTime() == null) {
 | 
				
			||||||
                removedBasicTaskSchedules.add(basicTaskSchedule);
 | 
					                removedBasicTaskSchedules.add(basicTaskSchedule);
 | 
				
			||||||
            } else if(basicTaskSchedule.getFinishedTime() == null) {
 | 
					            } else if(basicTaskSchedule.getStopTime() == null) {
 | 
				
			||||||
                ServiceResult<?> result = taskScheduleService.stopSchedule(basicTaskSchedule, true);
 | 
					                ServiceResult<?> result = taskScheduleService.stopSchedule(basicTaskSchedule, true);
 | 
				
			||||||
                System.out.println(result);
 | 
					                System.out.println(result);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for(BasicTaskSchedule deletedTaskSchedule: removedBasicTaskSchedules) {
 | 
					        task.getBasicTaskSchedules().removeAll(removedBasicTaskSchedules);
 | 
				
			||||||
            task.getBasicTaskSchedules().remove(deletedTaskSchedule);
 | 
					 | 
				
			||||||
        taskRepository.save(task);
 | 
					        taskRepository.save(task);
 | 
				
			||||||
            taskScheduleService.deleteBasicSchedule(deletedTaskSchedule);
 | 
					        taskScheduleService.deleteSchedules(removedBasicTaskSchedules);
 | 
				
			||||||
        }*/
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public List<Task> loadAllTasks(String username, TaskScope scope) {
 | 
					    public List<Task> loadAllTasks(String username, TaskScope scope) {
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@ package core.tasks;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import core.api.models.timemanager.tasks.TaskFieldInfo;
 | 
					import core.api.models.timemanager.tasks.TaskFieldInfo;
 | 
				
			||||||
import core.api.models.timemanager.tasks.TaskScope;
 | 
					import core.api.models.timemanager.tasks.TaskScope;
 | 
				
			||||||
 | 
					import core.entities.timemanager.BasicTaskSchedule;
 | 
				
			||||||
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;
 | 
				
			||||||
@ -43,7 +44,8 @@ public class TaskServiceTest {
 | 
				
			|||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    @SqlGroup({
 | 
					    @SqlGroup({
 | 
				
			||||||
            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
					            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
				
			||||||
            @Sql("classpath:taskRepositoryEntries.sql")
 | 
					            @Sql("classpath:taskRepositoryEntries.sql"),
 | 
				
			||||||
 | 
					            @Sql("classpath:basicScheduleEntries.sql")
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    void createTask() {
 | 
					    void createTask() {
 | 
				
			||||||
        //Situation 1: Task with that name already exists in a taskgroup
 | 
					        //Situation 1: Task with that name already exists in a taskgroup
 | 
				
			||||||
@ -85,7 +87,8 @@ public class TaskServiceTest {
 | 
				
			|||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    @SqlGroup({
 | 
					    @SqlGroup({
 | 
				
			||||||
            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
					            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
				
			||||||
            @Sql("classpath:taskRepositoryEntries.sql")
 | 
					            @Sql("classpath:taskRepositoryEntries.sql"),
 | 
				
			||||||
 | 
					            @Sql("classpath:basicScheduleEntries.sql")
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    void getTaskPermissions() {
 | 
					    void getTaskPermissions() {
 | 
				
			||||||
        //Situation 1: correct task and username
 | 
					        //Situation 1: correct task and username
 | 
				
			||||||
@ -110,7 +113,8 @@ public class TaskServiceTest {
 | 
				
			|||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    @SqlGroup({
 | 
					    @SqlGroup({
 | 
				
			||||||
            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
					            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
				
			||||||
            @Sql("classpath:taskRepositoryEntries.sql")
 | 
					            @Sql("classpath:taskRepositoryEntries.sql"),
 | 
				
			||||||
 | 
					            @Sql("classpath:basicScheduleEntries.sql")
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    void editTask() {
 | 
					    void editTask() {
 | 
				
			||||||
        //Situation 1: Nothing is updated
 | 
					        //Situation 1: Nothing is updated
 | 
				
			||||||
@ -182,7 +186,8 @@ public class TaskServiceTest {
 | 
				
			|||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    @SqlGroup({
 | 
					    @SqlGroup({
 | 
				
			||||||
            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
					            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
				
			||||||
            @Sql("classpath:taskRepositoryEntries.sql")
 | 
					            @Sql("classpath:taskRepositoryEntries.sql"),
 | 
				
			||||||
 | 
					            @Sql("classpath:basicScheduleEntries.sql")
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    void deleteTask() {
 | 
					    void deleteTask() {
 | 
				
			||||||
        for(long i=1; i<=15; i++) {
 | 
					        for(long i=1; i<=15; i++) {
 | 
				
			||||||
@ -194,7 +199,8 @@ public class TaskServiceTest {
 | 
				
			|||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    @SqlGroup({
 | 
					    @SqlGroup({
 | 
				
			||||||
            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
					            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
				
			||||||
            @Sql("classpath:taskRepositoryEntries.sql")
 | 
					            @Sql("classpath:taskRepositoryEntries.sql"),
 | 
				
			||||||
 | 
					            @Sql("classpath:basicScheduleEntries.sql")
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    void clearTasks() {
 | 
					    void clearTasks() {
 | 
				
			||||||
        //Situation 1: Delete from taskgroup with no tasks
 | 
					        //Situation 1: Delete from taskgroup with no tasks
 | 
				
			||||||
@ -212,7 +218,8 @@ public class TaskServiceTest {
 | 
				
			|||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    @SqlGroup({
 | 
					    @SqlGroup({
 | 
				
			||||||
            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
					            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
				
			||||||
            @Sql("classpath:taskRepositoryEntries.sql")
 | 
					            @Sql("classpath:taskRepositoryEntries.sql"),
 | 
				
			||||||
 | 
					            @Sql("classpath:basicScheduleEntries.sql")
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    void finishTask() {
 | 
					    void finishTask() {
 | 
				
			||||||
        taskService.finishTask(entityManager.find(Task.class, 1L));
 | 
					        taskService.finishTask(entityManager.find(Task.class, 1L));
 | 
				
			||||||
@ -220,12 +227,14 @@ public class TaskServiceTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        taskService.finishTask(entityManager.find(Task.class, 2L));
 | 
					        taskService.finishTask(entityManager.find(Task.class, 2L));
 | 
				
			||||||
        assertTrue(entityManager.find(Task.class, 1L).isFinished());
 | 
					        assertTrue(entityManager.find(Task.class, 1L).isFinished());
 | 
				
			||||||
 | 
					        assertThat(entityManager.find(BasicTaskSchedule.class, 2L)).isNull();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    @SqlGroup({
 | 
					    @SqlGroup({
 | 
				
			||||||
            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
					            @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
 | 
				
			||||||
            @Sql("classpath:taskRepositoryEntries.sql")
 | 
					            @Sql("classpath:taskRepositoryEntries.sql"),
 | 
				
			||||||
 | 
					            @Sql("classpath:basicScheduleEntries.sql")
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    void loadAllTasks() {
 | 
					    void loadAllTasks() {
 | 
				
			||||||
        //Situation 1: No tasks existing
 | 
					        //Situation 1: No tasks existing
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user