schedule-refactor #45
@ -141,7 +141,7 @@ public class ScheduleController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("schedules/{scheduleID}/activate")
|
@PostMapping("/schedules/{scheduleID}/activate")
|
||||||
public ResponseEntity<?> activateSchedule(@PathVariable long scheduleID) {
|
public ResponseEntity<?> activateSchedule(@PathVariable long scheduleID) {
|
||||||
PermissionResult<AbstractSchedule> permissionResult = taskScheduleService.getSchedulePermissions(scheduleID, SecurityContextHolder.getContext().getAuthentication().getName());
|
PermissionResult<AbstractSchedule> permissionResult = taskScheduleService.getSchedulePermissions(scheduleID, SecurityContextHolder.getContext().getAuthentication().getName());
|
||||||
if(permissionResult.isHasPermissions()) {
|
if(permissionResult.isHasPermissions()) {
|
||||||
@ -156,7 +156,7 @@ public class ScheduleController {
|
|||||||
return ResponseEntity.ok(new ScheduleActivateResponse(serviceResult.getResult().getStartTime()));
|
return ResponseEntity.ok(new ScheduleActivateResponse(serviceResult.getResult().getStartTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("schedules/{scheduleID}/stop/{finish}")
|
@PostMapping("/schedules/{scheduleID}/stop/{finish}")
|
||||||
public ResponseEntity<?> stopSchedule(@PathVariable long scheduleID, @PathVariable boolean finish) {
|
public ResponseEntity<?> stopSchedule(@PathVariable long scheduleID, @PathVariable boolean finish) {
|
||||||
PermissionResult<AbstractSchedule> permissionResult = taskScheduleService.getSchedulePermissions(scheduleID, SecurityContextHolder.getContext().getAuthentication().getName());
|
PermissionResult<AbstractSchedule> permissionResult = taskScheduleService.getSchedulePermissions(scheduleID, SecurityContextHolder.getContext().getAuthentication().getName());
|
||||||
if(permissionResult.isHasPermissions()) {
|
if(permissionResult.isHasPermissions()) {
|
||||||
@ -170,4 +170,23 @@ public class ScheduleController {
|
|||||||
ServiceResult<AbstractSchedule> serviceResult = taskScheduleService.stopSchedule(permissionResult.getResult(), finish);
|
ServiceResult<AbstractSchedule> serviceResult = taskScheduleService.stopSchedule(permissionResult.getResult(), finish);
|
||||||
return ResponseEntity.ok(new TaskScheduleStopResponse(serviceResult.getResult().getActiveTime()));
|
return ResponseEntity.ok(new TaskScheduleStopResponse(serviceResult.getResult().getActiveTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/schedules/{taskID}/forgotten")
|
||||||
|
public ResponseEntity<?> registerForgottenSchedule(@PathVariable long taskID, @RequestBody @Valid ForgottenScheduleInfo forgottenScheduleInfo) {
|
||||||
|
PermissionResult<Task> permissionResult = taskService.getTaskPermissions(taskID, SecurityContextHolder.getContext().getAuthentication().getName());
|
||||||
|
if(permissionResult.isHasPermissions()) {
|
||||||
|
return ResponseEntity.status(403).body(new SimpleStatusResponse("failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(permissionResult.getExitCode() == ServiceExitCode.MISSING_ENTITY) {
|
||||||
|
return ResponseEntity.status(404).body(new SimpleStatusResponse("failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceResult<AbstractSchedule> scheduleResult = taskScheduleService.registerForgottenSchedule(permissionResult.getResult(), forgottenScheduleInfo);
|
||||||
|
if(scheduleResult.getExitCode() == ServiceExitCode.INVALID_OPERATION) {
|
||||||
|
return ResponseEntity.status(400).body(new SimpleStatusResponse("failed"));
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.ok(new TaskScheduleStopResponse(scheduleResult.getResult().getActiveTime()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package core.api.models.timemanager.taskSchedule;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public class ForgottenScheduleInfo {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
|
public ForgottenScheduleInfo(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
this.endTime = endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ForgottenScheduleInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartTime(LocalDateTime startTime) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndTime(LocalDateTime endTime) {
|
||||||
|
this.endTime = endTime;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package core.services;
|
package core.services;
|
||||||
|
|
||||||
import core.api.models.timemanager.taskSchedule.BasicScheduleFieldInfo;
|
import core.api.models.timemanager.taskSchedule.BasicScheduleFieldInfo;
|
||||||
|
import core.api.models.timemanager.taskSchedule.ForgottenScheduleInfo;
|
||||||
import core.entities.timemanager.AbstractSchedule;
|
import core.entities.timemanager.AbstractSchedule;
|
||||||
import core.entities.timemanager.BasicTaskSchedule;
|
import core.entities.timemanager.BasicTaskSchedule;
|
||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
@ -122,4 +123,15 @@ public class TaskScheduleService {
|
|||||||
}
|
}
|
||||||
return new ServiceResult<>(schedule);
|
return new ServiceResult<>(schedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServiceResult<AbstractSchedule> registerForgottenSchedule(Task task, ForgottenScheduleInfo forgottenScheduleInfo) {
|
||||||
|
if(task.isFinished()) {
|
||||||
|
return new ServiceResult<>(ServiceExitCode.INVALID_OPERATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
BasicTaskSchedule basicTaskSchedule = new BasicTaskSchedule(task, forgottenScheduleInfo.getStartTime(), forgottenScheduleInfo.getEndTime(), forgottenScheduleInfo.getStartTime().toLocalDate());
|
||||||
|
scheduleRepository.save(basicTaskSchedule);
|
||||||
|
|
||||||
|
return new ServiceResult<>(basicTaskSchedule);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package core.schedules;
|
|||||||
|
|
||||||
import core.api.models.timemanager.taskSchedule.BasicScheduleFieldInfo;
|
import core.api.models.timemanager.taskSchedule.BasicScheduleFieldInfo;
|
||||||
import core.api.models.timemanager.taskSchedule.BasicScheduleInfo;
|
import core.api.models.timemanager.taskSchedule.BasicScheduleInfo;
|
||||||
|
import core.api.models.timemanager.taskSchedule.ForgottenScheduleInfo;
|
||||||
import core.entities.timemanager.AbstractSchedule;
|
import core.entities.timemanager.AbstractSchedule;
|
||||||
import core.entities.timemanager.BasicTaskSchedule;
|
import core.entities.timemanager.BasicTaskSchedule;
|
||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
@ -20,6 +21,7 @@ import javax.persistence.EntityManager;
|
|||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
@ -203,4 +205,26 @@ public class ScheduleServiceTest {
|
|||||||
assertTrue(result_3.getResult().getTask().isFinished());
|
assertTrue(result_3.getResult().getTask().isFinished());
|
||||||
assertFalse(result_3.getResult().isStartable());
|
assertFalse(result_3.getResult().isStartable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SqlGroup({
|
||||||
|
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
|
||||||
|
@Sql("classpath:taskRepositoryEntries.sql"),
|
||||||
|
@Sql("classpath:basicScheduleEntries.sql")
|
||||||
|
})
|
||||||
|
void registerForgottenSchedule() {
|
||||||
|
//Register task schedule for task that is already finished
|
||||||
|
LocalDateTime startTime = LocalDateTime.now().minusMinutes(10L);
|
||||||
|
LocalDateTime finishTime = LocalDateTime.now();
|
||||||
|
|
||||||
|
ServiceResult<AbstractSchedule> result_1 = taskScheduleService.registerForgottenSchedule(entityManager.find(Task.class, 2L), new ForgottenScheduleInfo(startTime, finishTime));
|
||||||
|
assertEquals(ServiceExitCode.INVALID_OPERATION, result_1.getExitCode());
|
||||||
|
|
||||||
|
ServiceResult<AbstractSchedule> result_2 = taskScheduleService.registerForgottenSchedule(entityManager.find(Task.class, 5L), new ForgottenScheduleInfo(startTime, finishTime));
|
||||||
|
assertEquals(ServiceExitCode.OK, result_2.getExitCode());
|
||||||
|
assertEquals(startTime, result_2.getResult().getStartTime());
|
||||||
|
assertEquals(finishTime, result_2.getResult().getStopTime());
|
||||||
|
assertThat(entityManager.find(BasicTaskSchedule.class, result_2.getResult().getScheduleID())).isNotNull();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
22
openapi.yaml
22
openapi.yaml
@ -1439,7 +1439,6 @@ paths:
|
|||||||
- schedule
|
- schedule
|
||||||
description: get all schedules of today
|
description: get all schedules of today
|
||||||
summary: get today's schedules
|
summary: get today's schedules
|
||||||
operationId: scheduleTaskNow
|
|
||||||
parameters:
|
parameters:
|
||||||
- name: date
|
- name: date
|
||||||
in: path
|
in: path
|
||||||
@ -2334,19 +2333,16 @@ components:
|
|||||||
example: true
|
example: true
|
||||||
ForgottenActivityRequest:
|
ForgottenActivityRequest:
|
||||||
required:
|
required:
|
||||||
- mode
|
- startTime
|
||||||
|
- endTime
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
properties:
|
properties:
|
||||||
mode:
|
startTime:
|
||||||
type: string
|
type: string
|
||||||
description: mode of register forgotten activity
|
format: date
|
||||||
example: MANUAL
|
description: time the schedule was started
|
||||||
enum:
|
endTime:
|
||||||
- MANUAL
|
type: string
|
||||||
- LAST
|
format: date
|
||||||
- PLANNED
|
description: time the schedule was stopped
|
||||||
minutesSpent:
|
|
||||||
type: number
|
|
||||||
description: number of minutes spent on task
|
|
||||||
example: 10
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user