schedule-refactor #45

Merged
sebastian merged 18 commits from schedule-refactor into master 2023-11-11 18:56:16 +01:00
7 changed files with 181 additions and 139 deletions
Showing only changes of commit d7d8d2060e - Show all commits

View File

@ -4,9 +4,11 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Remove entityManager from TaskService">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Basic Reschedule">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/core/tasks/TaskServiceTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/core/tasks/TaskServiceTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/api/controller/ScheduleController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/controller/ScheduleController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/core/schedules/ScheduleServiceTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/core/schedules/ScheduleServiceTest.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -85,81 +87,82 @@
<recent name="$PROJECT_DIR$/src/test/java/core/taskgroups" />
</key>
</component>
<component name="RunManager" selected="JUnit.TaskServiceTest">
<configuration name="TaskServiceTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<component name="RunManager" selected="JUnit.ScheduleServiceTest.deleteSchedule">
<configuration name="ScheduleRepositoryTest.getAllSchedulesOfUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.tasks.*" />
<option name="PATTERN" value="core.schedules.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskServiceTest" />
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskServiceTest.clearTasks" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.tasks.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskServiceTest" />
<option name="METHOD_NAME" value="clearTasks" />
<option name="PACKAGE_NAME" value="core.schedules" />
<option name="MAIN_CLASS_NAME" value="core.schedules.ScheduleRepositoryTest" />
<option name="METHOD_NAME" value="getAllSchedulesOfUser" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskServiceTest.deleteTask" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<configuration name="ScheduleServiceTest.deleteSchedule" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.tasks.*" />
<option name="PATTERN" value="core.schedules.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskServiceTest" />
<option name="METHOD_NAME" value="deleteTask" />
<option name="PACKAGE_NAME" value="core.schedules" />
<option name="MAIN_CLASS_NAME" value="core.schedules.ScheduleServiceTest" />
<option name="METHOD_NAME" value="deleteSchedule" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskServiceTest.finishTask" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<configuration name="ScheduleServiceTest.editBasicSchedule" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.tasks.*" />
<option name="PATTERN" value="core.schedules.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskServiceTest" />
<option name="METHOD_NAME" value="finishTask" />
<option name="PACKAGE_NAME" value="core.schedules" />
<option name="MAIN_CLASS_NAME" value="core.schedules.ScheduleServiceTest" />
<option name="METHOD_NAME" value="editBasicSchedule" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskServiceTest.loadAllTasks" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<configuration name="ScheduleServiceTest.getAllSchedulesOfUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.tasks.*" />
<option name="PATTERN" value="core.schedules.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskServiceTest" />
<option name="METHOD_NAME" value="loadAllTasks" />
<option name="PACKAGE_NAME" value="core.schedules" />
<option name="MAIN_CLASS_NAME" value="core.schedules.ScheduleServiceTest" />
<option name="METHOD_NAME" value="getAllSchedulesOfUser" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ScheduleServiceTest.scheduleBasic" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.schedules.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.schedules" />
<option name="MAIN_CLASS_NAME" value="core.schedules.ScheduleServiceTest" />
<option name="METHOD_NAME" value="scheduleBasic" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
@ -174,11 +177,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.TaskServiceTest" />
<item itemvalue="JUnit.TaskServiceTest.loadAllTasks" />
<item itemvalue="JUnit.TaskServiceTest.finishTask" />
<item itemvalue="JUnit.TaskServiceTest.clearTasks" />
<item itemvalue="JUnit.TaskServiceTest.deleteTask" />
<item itemvalue="JUnit.ScheduleServiceTest.deleteSchedule" />
<item itemvalue="JUnit.ScheduleServiceTest.editBasicSchedule" />
<item itemvalue="JUnit.ScheduleServiceTest.scheduleBasic" />
<item itemvalue="JUnit.ScheduleServiceTest.getAllSchedulesOfUser" />
<item itemvalue="JUnit.ScheduleRepositoryTest.getAllSchedulesOfUser" />
</list>
</recent_temporary>
</component>
@ -482,17 +485,45 @@
<option name="project" value="LOCAL" />
<updated>1699695051881</updated>
</task>
<option name="localTasksCounter" value="34" />
<task id="LOCAL-00034" summary="Update gitignore and add Clear ScheduleCode">
<option name="closed" value="true" />
<created>1699705458914</created>
<option name="number" value="00034" />
<option name="presentableId" value="LOCAL-00034" />
<option name="project" value="LOCAL" />
<updated>1699705458914</updated>
</task>
<task id="LOCAL-00035" summary="Get All Schedules of User">
<option name="closed" value="true" />
<created>1699708881009</created>
<option name="number" value="00035" />
<option name="presentableId" value="LOCAL-00035" />
<option name="project" value="LOCAL" />
<updated>1699708881009</updated>
</task>
<task id="LOCAL-00036" summary="Get All Schedules of Task + create Basic Schedule">
<option name="closed" value="true" />
<created>1699711238266</created>
<option name="number" value="00036" />
<option name="presentableId" value="LOCAL-00036" />
<option name="project" value="LOCAL" />
<updated>1699711238266</updated>
</task>
<task id="LOCAL-00037" summary="Basic Reschedule">
<option name="closed" value="true" />
<created>1699714216432</created>
<option name="number" value="00037" />
<option name="presentableId" value="LOCAL-00037" />
<option name="project" value="LOCAL" />
<updated>1699714216432</updated>
</task>
<option name="localTasksCounter" value="38" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Fix Foreign Key Constraint Fail when deleting Taskgroups" />
<MESSAGE value="Stop and Finish TaskSchedules" />
<MESSAGE value="Include TaskScheduleStopResponse" />
<MESSAGE value="Fix starting schedule and returning active time of schedule after stop" />
<MESSAGE value="Remove update spamming in console" />
<MESSAGE value="Start task now from Taskoverview in Dashboard" />
<MESSAGE value="Load worked minutes when reloading dashboard" />
@ -514,31 +545,25 @@
<MESSAGE value="Deleting Task test" />
<MESSAGE value="Consider increased number of tasks" />
<MESSAGE value="Remove entityManager from TaskService" />
<option name="LAST_COMMIT_MESSAGE" value="Remove entityManager from TaskService" />
<MESSAGE value="Update gitignore and add Clear ScheduleCode" />
<MESSAGE value="Get All Schedules of User" />
<MESSAGE value="Get All Schedules of Task + create Basic Schedule" />
<MESSAGE value="Basic Reschedule" />
<option name="LAST_COMMIT_MESSAGE" value="Basic Reschedule" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java</url>
<line>87</line>
<option name="timeStamp" value="5" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java</url>
<line>94</line>
<option name="timeStamp" value="6" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java</url>
<line>202</line>
<option name="timeStamp" value="10" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/core/entities/User.java</url>
<line>57</line>
<option name="timeStamp" value="12" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/core/services/TaskScheduleService.java</url>
<line>50</line>
<option name="timeStamp" value="32" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>

View File

@ -90,4 +90,19 @@ public class ScheduleController {
return ResponseEntity.status(400).body(new SimpleStatusResponse("failed"));
}
@DeleteMapping("/schedules/{scheduleID}")
public ResponseEntity<?> deleteSchedule(@PathVariable long scheduleID) {
PermissionResult<AbstractSchedule> permissionResult = taskScheduleService.getSchedulePermissions(scheduleID, 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"));
}
taskScheduleService.deleteSchedule(permissionResult.getResult());
return ResponseEntity.ok(new SimpleStatusResponse("success"));
}
}

View File

@ -51,4 +51,8 @@ public class TaskScheduleService {
scheduleRepository.save(schedule);
return new ServiceResult<>(schedule);
}
public void deleteSchedule(AbstractSchedule schedule) {
scheduleRepository.delete(schedule);
}
}

View File

@ -95,4 +95,17 @@ public class ScheduleServiceTest {
assertEquals(ServiceExitCode.OK, result_3.getExitCode());
assertNotEquals(((BasicTaskSchedule) result_3.getResult()).getScheduleDate(), oldDate);
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql"),
@Sql("classpath:basicScheduleEntries.sql")
})
void deleteSchedule() {
for(long i=1; i<=2; i++) {
taskScheduleService.deleteSchedule(entityManager.find(BasicTaskSchedule.class, i));
assertThat(entityManager.find(BasicTaskSchedule.class, i)).isNull();
}
}
}

View File

@ -316,6 +316,65 @@ export class ScheduleService {
);
}
/**
* deletes schedule
* deletes a schedule
* @param scheduleID internal id of schedule
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public schedulesScheduleIDDelete(scheduleID: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<SimpleStatusResponse>;
public schedulesScheduleIDDelete(scheduleID: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<SimpleStatusResponse>>;
public schedulesScheduleIDDelete(scheduleID: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<SimpleStatusResponse>>;
public schedulesScheduleIDDelete(scheduleID: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
if (scheduleID === null || scheduleID === undefined) {
throw new Error('Required parameter scheduleID was null or undefined when calling schedulesScheduleIDDelete.');
}
let localVarHeaders = this.defaultHeaders;
let localVarCredential: string | undefined;
// authentication (API_TOKEN) required
localVarCredential = this.configuration.lookupCredential('API_TOKEN');
if (localVarCredential) {
localVarHeaders = localVarHeaders.set('Authorization', 'Bearer ' + localVarCredential);
}
let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
if (localVarHttpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = [
'application/json'
];
localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
}
if (localVarHttpHeaderAcceptSelected !== undefined) {
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
}
let localVarHttpContext: HttpContext | undefined = options && options.context;
if (localVarHttpContext === undefined) {
localVarHttpContext = new HttpContext();
}
let responseType_: 'text' | 'json' = 'json';
if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) {
responseType_ = 'text';
}
return this.httpClient.delete<SimpleStatusResponse>(`${this.configuration.basePath}/schedules/${encodeURIComponent(String(scheduleID))}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
/**
* reschedules task
* reschedules a task
@ -386,69 +445,6 @@ export class ScheduleService {
);
}
/**
* deletes schedule
* deletes a schedule
* @param scheduleID internal id of schedule
* @param scheduleType internal id of task
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public schedulesScheduleIDScheduleTypeDelete(scheduleID: number, scheduleType: 'BASIC' | 'MODERATE' | 'ADVANCED', observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<SimpleStatusResponse>;
public schedulesScheduleIDScheduleTypeDelete(scheduleID: number, scheduleType: 'BASIC' | 'MODERATE' | 'ADVANCED', observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<SimpleStatusResponse>>;
public schedulesScheduleIDScheduleTypeDelete(scheduleID: number, scheduleType: 'BASIC' | 'MODERATE' | 'ADVANCED', observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<SimpleStatusResponse>>;
public schedulesScheduleIDScheduleTypeDelete(scheduleID: number, scheduleType: 'BASIC' | 'MODERATE' | 'ADVANCED', observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
if (scheduleID === null || scheduleID === undefined) {
throw new Error('Required parameter scheduleID was null or undefined when calling schedulesScheduleIDScheduleTypeDelete.');
}
if (scheduleType === null || scheduleType === undefined) {
throw new Error('Required parameter scheduleType was null or undefined when calling schedulesScheduleIDScheduleTypeDelete.');
}
let localVarHeaders = this.defaultHeaders;
let localVarCredential: string | undefined;
// authentication (API_TOKEN) required
localVarCredential = this.configuration.lookupCredential('API_TOKEN');
if (localVarCredential) {
localVarHeaders = localVarHeaders.set('Authorization', 'Bearer ' + localVarCredential);
}
let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
if (localVarHttpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = [
'application/json'
];
localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
}
if (localVarHttpHeaderAcceptSelected !== undefined) {
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
}
let localVarHttpContext: HttpContext | undefined = options && options.context;
if (localVarHttpContext === undefined) {
localVarHttpContext = new HttpContext();
}
let responseType_: 'text' | 'json' = 'json';
if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) {
responseType_ = 'text';
}
return this.httpClient.delete<SimpleStatusResponse>(`${this.configuration.basePath}/schedules/${encodeURIComponent(String(scheduleID))}/${encodeURIComponent(String(scheduleType))}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
/**
* @param scheduleID internal id of schedule
* @param finish internal id of schedule

View File

@ -38,7 +38,7 @@ export class ScheduleDashboardComponent implements OnInit{
}
deleteSchedule(deletedSchedule: ScheduleInfo) {
this.scheduleService.schedulesScheduleIDScheduleTypeDelete(deletedSchedule.scheduleID, 'BASIC').subscribe({
this.scheduleService.schedulesScheduleIDDelete(deletedSchedule.scheduleID).subscribe({
next: resp => {
this.schedules = this.schedules.filter(schedule => schedule.scheduleID !== deletedSchedule.scheduleID);
},

View File

@ -1394,7 +1394,6 @@ paths:
schema:
type: object
$ref: "#/components/schemas/SimpleStatusResponse"
/schedules/{scheduleID}/{scheduleType}:
delete:
security:
- API_TOKEN: []
@ -1410,16 +1409,6 @@ paths:
schema:
type: number
example: 1
- name: scheduleType
in: path
description: internal id of task
required: true
schema:
type: string
enum:
- BASIC
- MODERATE
- ADVANCED
responses:
200:
description: operation successfull