issue-20 #46
@ -4,9 +4,11 @@ package core.api.controller;
|
|||||||
import core.api.models.auth.SimpleStatusResponse;
|
import core.api.models.auth.SimpleStatusResponse;
|
||||||
import core.api.models.timemanager.taskSchedule.*;
|
import core.api.models.timemanager.taskSchedule.*;
|
||||||
import core.api.models.timemanager.taskSchedule.scheduleInfos.AdvancedScheduleFieldInfo;
|
import core.api.models.timemanager.taskSchedule.scheduleInfos.AdvancedScheduleFieldInfo;
|
||||||
|
import core.api.models.timemanager.taskSchedule.scheduleInfos.AdvancedScheduleInfo;
|
||||||
import core.api.models.timemanager.taskSchedule.scheduleInfos.BasicScheduleFieldInfo;
|
import core.api.models.timemanager.taskSchedule.scheduleInfos.BasicScheduleFieldInfo;
|
||||||
import core.api.models.timemanager.taskSchedule.scheduleInfos.ScheduleFieldInfo;
|
import core.api.models.timemanager.taskSchedule.scheduleInfos.ScheduleFieldInfo;
|
||||||
import core.entities.timemanager.AbstractSchedule;
|
import core.entities.timemanager.AbstractSchedule;
|
||||||
|
import core.entities.timemanager.AdvancedTaskSchedule;
|
||||||
import core.entities.timemanager.BasicTaskSchedule;
|
import core.entities.timemanager.BasicTaskSchedule;
|
||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
import core.services.*;
|
import core.services.*;
|
||||||
@ -91,6 +93,13 @@ public class ScheduleController {
|
|||||||
} else {
|
} else {
|
||||||
return ResponseEntity.ok(updatedSchedule.getResult().toScheduleInfo());
|
return ResponseEntity.ok(updatedSchedule.getResult().toScheduleInfo());
|
||||||
}
|
}
|
||||||
|
} else if(permissionResult.getResult() instanceof AdvancedTaskSchedule && scheduleFieldInfo instanceof AdvancedScheduleFieldInfo) {
|
||||||
|
ServiceResult<AbstractSchedule> updatedSchedule = taskScheduleService.editAdvancedSchedule((AdvancedTaskSchedule) permissionResult.getResult(), (AdvancedScheduleFieldInfo) scheduleFieldInfo);
|
||||||
|
if(updatedSchedule.getExitCode() == ServiceExitCode.INVALID_OPERATION) {
|
||||||
|
return ResponseEntity.status(400).body(new SimpleStatusResponse("failed"));
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.ok(updatedSchedule.getResult().toScheduleInfo());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResponseEntity.status(400).body(new SimpleStatusResponse("failed"));
|
return ResponseEntity.status(400).body(new SimpleStatusResponse("failed"));
|
||||||
|
@ -68,7 +68,7 @@ public class TaskScheduleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ServiceResult<AbstractSchedule> editBasicSchedule(BasicTaskSchedule schedule, BasicScheduleFieldInfo scheduleFieldInfo) {
|
public ServiceResult<AbstractSchedule> editBasicSchedule(BasicTaskSchedule schedule, BasicScheduleFieldInfo scheduleFieldInfo) {
|
||||||
if(schedule.getTask().isFinished() || scheduleFieldInfo.getScheduleDate().isBefore(LocalDate.now())) {
|
if(schedule.getTask().isFinished() || scheduleFieldInfo.getScheduleDate().isBefore(LocalDate.now()) || schedule.isActive()) {
|
||||||
return new ServiceResult<>(ServiceExitCode.INVALID_OPERATION);
|
return new ServiceResult<>(ServiceExitCode.INVALID_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +77,24 @@ public class TaskScheduleService {
|
|||||||
return new ServiceResult<>(schedule);
|
return new ServiceResult<>(schedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServiceResult<AbstractSchedule> editAdvancedSchedule(AdvancedTaskSchedule schedule, AdvancedScheduleFieldInfo scheduleFieldInfo) {
|
||||||
|
LocalDate startDate = scheduleFieldInfo.getScheduleStartTime().toLocalDate();
|
||||||
|
LocalDate endDate = scheduleFieldInfo.getScheduleStopTime().toLocalDate();
|
||||||
|
|
||||||
|
if(schedule.getTask().isFinished() || startDate.isBefore(LocalDate.now()) || endDate.isBefore(LocalDate.now()) || schedule.isActive()) {
|
||||||
|
return new ServiceResult<>(ServiceExitCode.INVALID_OPERATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(scheduleFieldInfo.getScheduleStartTime().isAfter(scheduleFieldInfo.getScheduleStopTime())) {
|
||||||
|
return new ServiceResult<>(ServiceExitCode.INVALID_PARAMETER);
|
||||||
|
}
|
||||||
|
|
||||||
|
schedule.setStartTime(scheduleFieldInfo.getScheduleStartTime());
|
||||||
|
schedule.setStopTime(scheduleFieldInfo.getScheduleStopTime());
|
||||||
|
scheduleRepository.save(schedule);
|
||||||
|
return new ServiceResult<>(schedule);
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteSchedule(AbstractSchedule schedule) {
|
public void deleteSchedule(AbstractSchedule schedule) {
|
||||||
scheduleRepository.delete(schedule);
|
scheduleRepository.delete(schedule);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package core.schedules;
|
package core.schedules;
|
||||||
|
|
||||||
import core.api.models.timemanager.taskSchedule.scheduleInfos.AdvancedScheduleFieldInfo;
|
import core.api.models.timemanager.taskSchedule.scheduleInfos.AdvancedScheduleFieldInfo;
|
||||||
|
import core.api.models.timemanager.taskSchedule.scheduleInfos.AdvancedScheduleInfo;
|
||||||
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.entities.timemanager.AbstractSchedule;
|
import core.entities.timemanager.AbstractSchedule;
|
||||||
@ -96,6 +97,11 @@ public class ScheduleServiceTest {
|
|||||||
ServiceResult<AbstractSchedule> result_3 = taskScheduleService.editBasicSchedule(entityManager.find(BasicTaskSchedule.class, 1L), new BasicScheduleFieldInfo(LocalDate.now()));
|
ServiceResult<AbstractSchedule> result_3 = taskScheduleService.editBasicSchedule(entityManager.find(BasicTaskSchedule.class, 1L), new BasicScheduleFieldInfo(LocalDate.now()));
|
||||||
assertEquals(ServiceExitCode.OK, result_3.getExitCode());
|
assertEquals(ServiceExitCode.OK, result_3.getExitCode());
|
||||||
assertNotEquals(((BasicTaskSchedule) result_3.getResult()).getScheduleDate(), oldDate);
|
assertNotEquals(((BasicTaskSchedule) result_3.getResult()).getScheduleDate(), oldDate);
|
||||||
|
|
||||||
|
//Situation 4: Reschedule already running schedule
|
||||||
|
ServiceResult<AbstractSchedule> result_4 = taskScheduleService.editBasicSchedule(entityManager.find(BasicTaskSchedule.class, 4L),
|
||||||
|
new BasicScheduleFieldInfo(LocalDate.now()));
|
||||||
|
assertEquals(ServiceExitCode.INVALID_OPERATION, result_4.getExitCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -269,4 +275,43 @@ public class ScheduleServiceTest {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SqlGroup({
|
||||||
|
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
|
||||||
|
@Sql("classpath:taskRepositoryEntries.sql"),
|
||||||
|
@Sql("classpath:basicScheduleEntries.sql")
|
||||||
|
})
|
||||||
|
void editscheduleAdvanced() {
|
||||||
|
//Situation 1: Schedule finished Task
|
||||||
|
ServiceResult<AbstractSchedule> result_1 = taskScheduleService.editAdvancedSchedule(entityManager.find(AdvancedTaskSchedule.class, 12L),
|
||||||
|
new AdvancedScheduleFieldInfo(LocalDateTime.now().plusHours(1L), LocalDateTime.now().plusHours(2L)));
|
||||||
|
assertEquals(ServiceExitCode.INVALID_OPERATION, result_1.getExitCode());
|
||||||
|
|
||||||
|
//Situation 2: Schedule Start is before today
|
||||||
|
ServiceResult<AbstractSchedule> result_2 = taskScheduleService.editAdvancedSchedule(entityManager.find(AdvancedTaskSchedule.class, 11L),
|
||||||
|
new AdvancedScheduleFieldInfo(LocalDateTime.now().minusDays(1L), LocalDateTime.now().plusHours(2L)));
|
||||||
|
assertEquals(ServiceExitCode.INVALID_OPERATION, result_2.getExitCode());
|
||||||
|
|
||||||
|
//Situation 3: Schedule End is before today
|
||||||
|
ServiceResult<AbstractSchedule> result_3 = taskScheduleService.editAdvancedSchedule(entityManager.find(AdvancedTaskSchedule.class, 11L),
|
||||||
|
new AdvancedScheduleFieldInfo(LocalDateTime.now().minusDays(2L), LocalDateTime.now().minusDays(1L)));
|
||||||
|
assertEquals(ServiceExitCode.INVALID_OPERATION, result_3.getExitCode());
|
||||||
|
|
||||||
|
//Situation 4: Start after stop
|
||||||
|
ServiceResult<AbstractSchedule> result_4 = taskScheduleService.editAdvancedSchedule(entityManager.find(AdvancedTaskSchedule.class, 11L),
|
||||||
|
new AdvancedScheduleFieldInfo(LocalDateTime.now().plusHours(2L), LocalDateTime.now().plusHours(1L)));
|
||||||
|
assertEquals(ServiceExitCode.INVALID_PARAMETER, result_4.getExitCode());
|
||||||
|
|
||||||
|
//Situation 5: Valid schedule
|
||||||
|
ServiceResult<AbstractSchedule> result_5 = taskScheduleService.editAdvancedSchedule(entityManager.find(AdvancedTaskSchedule.class, 11L),
|
||||||
|
new AdvancedScheduleFieldInfo(LocalDateTime.now(), LocalDateTime.now().plusHours(1L)));
|
||||||
|
assertEquals(ServiceExitCode.OK, result_5.getExitCode());
|
||||||
|
assertThat(entityManager.find(AdvancedTaskSchedule.class, result_5.getResult().getScheduleID())).isNotNull();
|
||||||
|
|
||||||
|
//Situation 6: reschedule already running schedule
|
||||||
|
ServiceResult<AbstractSchedule> result_6 = taskScheduleService.editAdvancedSchedule(entityManager.find(AdvancedTaskSchedule.class, 9L),
|
||||||
|
new AdvancedScheduleFieldInfo(LocalDateTime.now(), LocalDateTime.now().plusHours(1L)));
|
||||||
|
assertEquals(ServiceExitCode.INVALID_OPERATION, result_6.getExitCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,5 @@ INSERT INTO abstract_schedule (schedule_type, scheduleid, start_time, stop_time,
|
|||||||
VALUES (1, 8, null, null, null, 16, '2023-11-15 12:30:00.000', '2023-11-15 14:45:30.500'),
|
VALUES (1, 8, null, null, null, 16, '2023-11-15 12:30:00.000', '2023-11-15 14:45:30.500'),
|
||||||
(1, 9, '2023-11-16 12:35:00.000', null, null, 17, '2023-11-16 12:30:00.000', '2023-11-16 14:45:30.500'),
|
(1, 9, '2023-11-16 12:35:00.000', null, null, 17, '2023-11-16 12:30:00.000', '2023-11-16 14:45:30.500'),
|
||||||
(1, 10, '2023-11-17 12:35:00.000', '2023-11-17 12:45:00.000', null, 17, '2023-11-16 12:30:00.000', '2023-11-16 14:45:30.500'),
|
(1, 10, '2023-11-17 12:35:00.000', '2023-11-17 12:45:00.000', null, 17, '2023-11-16 12:30:00.000', '2023-11-16 14:45:30.500'),
|
||||||
(1, 11, null, null, null, 17, '2010-11-16 12:30:00.000', '2010-11-16 14:45:30.500');
|
(1, 11, null, null, null, 17, '2010-11-16 12:30:00.000', '2010-11-16 14:45:30.500'),
|
||||||
|
(1, 12, null, null, null, 18, '2010-11-16 12:30:00.000', '2010-11-16 14:45:30.500');
|
Loading…
Reference in New Issue
Block a user