Delete Tasks by Taskgroup and Fix NullpointerException in TaskEntityInfo Constructor
All checks were successful
Java CI with Maven / build-and-push-frontend (push) Successful in 8s
Java CI with Maven / build-and-push-backend (push) Successful in 7s

This commit is contained in:
Sebastian Böckelmann 2024-03-16 14:28:25 +01:00
parent 125ab10a00
commit dcdba67f22
5 changed files with 18 additions and 6 deletions

View File

@ -51,7 +51,7 @@ public class TaskEntityInfo {
this.hasActiveSchedules = task.hasActiveSchedule(); this.hasActiveSchedules = task.hasActiveSchedule();
this.hasPlannedSchedules = task.hasPlannedSchedules(); this.hasPlannedSchedules = task.hasPlannedSchedules();
this.hasTaskSerie = task.getTaskSerieItem() != null; this.hasTaskSerie = task.getTaskSerieItem() != null;
this.hasSubtasks = !task.getSubtasks().isEmpty(); this.hasSubtasks = task.getSubtasks() != null && !task.getSubtasks().isEmpty();
this.hasParent = task.getParent() != null; this.hasParent = task.getParent() != null;
} }

View File

@ -2,10 +2,12 @@ package core.repositories.timemanager;
import core.entities.timemanager.AbstractSchedule; import core.entities.timemanager.AbstractSchedule;
import core.entities.timemanager.Taskgroup; import core.entities.timemanager.Taskgroup;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import javax.transaction.Transactional;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -20,4 +22,9 @@ public interface ScheduleRepository extends CrudRepository<AbstractSchedule, Lon
@Query(value = "SELECT s FROM AbstractSchedule s WHERE s.task.taskgroup.user.username = ?1 AND s.startTime is NOT NULL and s.stopTime is NULL") @Query(value = "SELECT s FROM AbstractSchedule s WHERE s.task.taskgroup.user.username = ?1 AND s.startTime is NOT NULL and s.stopTime is NULL")
Optional<AbstractSchedule> getActiveScheduleOfUser(String username); Optional<AbstractSchedule> getActiveScheduleOfUser(String username);
@Modifying
@Transactional
@Query(value = "DELETE FROM AbstractSchedule a WHERE a.task IN (SELECT t FROM Task t WHERE t.taskgroup = ?1)")
void deleteByTaskgroup(Taskgroup taskgroup);
} }

View File

@ -7,10 +7,7 @@ import core.api.models.timemanager.taskSchedule.scheduleInfos.AdvancedScheduleIn
import core.api.models.timemanager.taskSchedule.scheduleInfos.BasicScheduleFieldInfo; import core.api.models.timemanager.taskSchedule.scheduleInfos.BasicScheduleFieldInfo;
import core.api.models.timemanager.taskSchedule.ForgottenScheduleInfo; import core.api.models.timemanager.taskSchedule.ForgottenScheduleInfo;
import core.api.models.timemanager.taskSchedule.scheduleInfos.ScheduleInfo; import core.api.models.timemanager.taskSchedule.scheduleInfos.ScheduleInfo;
import core.entities.timemanager.AbstractSchedule; import core.entities.timemanager.*;
import core.entities.timemanager.AdvancedTaskSchedule;
import core.entities.timemanager.BasicTaskSchedule;
import core.entities.timemanager.Task;
import core.repositories.UserRepository; import core.repositories.UserRepository;
import core.repositories.timemanager.AdvancedScheduleRepository; import core.repositories.timemanager.AdvancedScheduleRepository;
import core.repositories.timemanager.ScheduleRepository; import core.repositories.timemanager.ScheduleRepository;
@ -259,4 +256,8 @@ public class TaskScheduleService {
schedule.setStopTime(schedule.getStartTime().plusMinutes(manualScheduleStopInfo.getDuration())); schedule.setStopTime(schedule.getStartTime().plusMinutes(manualScheduleStopInfo.getDuration()));
scheduleRepository.save(schedule); scheduleRepository.save(schedule);
} }
public void deleteSchedulesByTaskgroup(Taskgroup taskgroup) {
scheduleRepository.deleteByTaskgroup(taskgroup);
}
} }

View File

@ -113,6 +113,7 @@ public class TaskService {
public void clearTasks(Taskgroup taskgroup) { public void clearTasks(Taskgroup taskgroup) {
taskSeriesService.deleteTaskSerieByTaskgroup(taskgroup); taskSeriesService.deleteTaskSerieByTaskgroup(taskgroup);
taskScheduleService.deleteSchedulesByTaskgroup(taskgroup);
taskRepository.deleteAllByTaskgroup(taskgroup); taskRepository.deleteAllByTaskgroup(taskgroup);
} }

View File

@ -21,10 +21,12 @@ public class TaskgroupService {
private final TaskgroupRepository taskgroupRepository; private final TaskgroupRepository taskgroupRepository;
private final UserRepository userRepository; private final UserRepository userRepository;
private final TaskService taskService;
public TaskgroupService(@Autowired TaskgroupRepository taskgroupRepository, public TaskgroupService(@Autowired TaskgroupRepository taskgroupRepository,
@Autowired UserRepository userRepository) { @Autowired UserRepository userRepository, @Autowired TaskService taskService) {
this.taskgroupRepository = taskgroupRepository; this.taskgroupRepository = taskgroupRepository;
this.userRepository = userRepository; this.userRepository = userRepository;
this.taskService = taskService;
} }
public PermissionResult<Taskgroup> getTaskgroupByIDAndUsername(long taskgroupID, String username) { public PermissionResult<Taskgroup> getTaskgroupByIDAndUsername(long taskgroupID, String username) {
@ -97,6 +99,7 @@ public class TaskgroupService {
} }
public void deleteTaskgroup(Taskgroup taskgroup) { public void deleteTaskgroup(Taskgroup taskgroup) {
taskService.clearTasks(taskgroup);
taskgroupRepository.delete(taskgroup); taskgroupRepository.delete(taskgroup);
} }