1 | package edu.ucsb.cs156.courses.controllers; | |
2 | ||
3 | import com.fasterxml.jackson.databind.ObjectMapper; | |
4 | import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection; | |
5 | import edu.ucsb.cs156.courses.entities.Job; | |
6 | import edu.ucsb.cs156.courses.jobs.TestJob; | |
7 | import edu.ucsb.cs156.courses.jobs.UpdateCourseDataJobFactory; | |
8 | import edu.ucsb.cs156.courses.jobs.UploadGradeDataJob; | |
9 | import edu.ucsb.cs156.courses.jobs.UploadGradeDataJobFactory; | |
10 | import edu.ucsb.cs156.courses.repositories.JobsRepository; | |
11 | import edu.ucsb.cs156.courses.services.jobs.JobService; | |
12 | import io.swagger.v3.oas.annotations.Operation; | |
13 | import io.swagger.v3.oas.annotations.Parameter; | |
14 | import io.swagger.v3.oas.annotations.tags.Tag; | |
15 | import org.springframework.beans.factory.annotation.Autowired; | |
16 | import org.springframework.security.access.prepost.PreAuthorize; | |
17 | import org.springframework.web.bind.annotation.GetMapping; | |
18 | import org.springframework.web.bind.annotation.PostMapping; | |
19 | import org.springframework.web.bind.annotation.RequestMapping; | |
20 | import org.springframework.web.bind.annotation.RequestParam; | |
21 | import org.springframework.web.bind.annotation.RestController; | |
22 | ||
23 | @Tag(name = "Jobs") | |
24 | @RequestMapping("/api/jobs") | |
25 | @RestController | |
26 | public class JobsController extends ApiController { | |
27 | @Autowired private JobsRepository jobsRepository; | |
28 | ||
29 | @Autowired private ConvertedSectionCollection convertedSectionCollection; | |
30 | ||
31 | @Autowired private JobService jobService; | |
32 | ||
33 | @Autowired ObjectMapper mapper; | |
34 | ||
35 | @Autowired UpdateCourseDataJobFactory updateCourseDataJobFactory; | |
36 | ||
37 | @Autowired UploadGradeDataJobFactory updateGradeDataJobFactory; | |
38 | ||
39 | @Operation(summary = "List all jobs") | |
40 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
41 | @GetMapping("/all") | |
42 | public Iterable<Job> allJobs() { | |
43 | Iterable<Job> jobs = jobsRepository.findAll(); | |
44 |
1
1. allJobs : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::allJobs → KILLED |
return jobs; |
45 | } | |
46 | ||
47 | @Operation(summary = "Launch Test Job (click fail if you want to test exception handling)") | |
48 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
49 | @PostMapping("/launch/testjob") | |
50 | public Job launchTestJob( | |
51 | @Parameter(name = "fail") @RequestParam Boolean fail, | |
52 | @Parameter(name = "sleepMs") @RequestParam Integer sleepMs) { | |
53 | ||
54 | TestJob testJob = TestJob.builder().fail(fail).sleepMs(sleepMs).build(); | |
55 |
1
1. launchTestJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchTestJob → KILLED |
return jobService.runAsJob(testJob); |
56 | } | |
57 | ||
58 | @Operation(summary = "Launch Job to Update Course Data") | |
59 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
60 | @PostMapping("/launch/updateCourses") | |
61 | public Job launchUpdateCourseDataJob( | |
62 | @Parameter(name = "quarterYYYYQ", description = "quarter (YYYYQ format)") @RequestParam | |
63 | String quarterYYYYQ, | |
64 | @Parameter(name = "subject area") @RequestParam String subjectArea) { | |
65 | ||
66 | var job = updateCourseDataJobFactory.createForSubjectAndQuarter(subjectArea, quarterYYYYQ); | |
67 | ||
68 |
1
1. launchUpdateCourseDataJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataJob → KILLED |
return jobService.runAsJob(job); |
69 | } | |
70 | ||
71 | @Operation(summary = "Launch Job to Update Course Data using Quarter") | |
72 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
73 | @PostMapping("/launch/updateQuarterCourses") | |
74 | public Job launchUpdateCourseDataWithQuarterJob( | |
75 | @Parameter(name = "quarterYYYYQ", description = "quarter (YYYYQ format)") @RequestParam | |
76 | String quarterYYYYQ) { | |
77 | ||
78 | var job = updateCourseDataJobFactory.createForQuarter(quarterYYYYQ); | |
79 | ||
80 |
1
1. launchUpdateCourseDataWithQuarterJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataWithQuarterJob → KILLED |
return jobService.runAsJob(job); |
81 | } | |
82 | ||
83 | @Operation(summary = "Launch Job to Update Course Data for range of quarters") | |
84 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
85 | @PostMapping("/launch/updateCoursesRangeOfQuarters") | |
86 | public Job launchUpdateCourseDataRangeOfQuartersJob( | |
87 | @Parameter(name = "start_quarterYYYYQ", description = "start quarter (YYYYQ format)") | |
88 | @RequestParam | |
89 | String start_quarterYYYYQ, | |
90 | @Parameter(name = "end_quarterYYYYQ", description = "end quarter (YYYYQ format)") | |
91 | @RequestParam | |
92 | String end_quarterYYYYQ) { | |
93 | ||
94 | var job = | |
95 | updateCourseDataJobFactory.createForQuarterRange(start_quarterYYYYQ, end_quarterYYYYQ); | |
96 | ||
97 |
1
1. launchUpdateCourseDataRangeOfQuartersJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataRangeOfQuartersJob → KILLED |
return jobService.runAsJob(job); |
98 | } | |
99 | ||
100 | @Operation( | |
101 | summary = "Launch Job to Update Course Data for a range of quarters for a single subject") | |
102 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
103 | @PostMapping("/launch/updateCoursesRangeOfQuartersSingleSubject") | |
104 | public Job launchUpdateCourseDataRangeOfQuartersSingleSubjectJob( | |
105 | @Parameter(name = "subjectArea", description = "subject area") @RequestParam | |
106 | String subjectArea, | |
107 | @Parameter(name = "start_quarterYYYYQ", description = "start quarter (YYYYQ format)") | |
108 | @RequestParam | |
109 | String start_quarterYYYYQ, | |
110 | @Parameter(name = "end_quarterYYYYQ", description = "end quarter (YYYYQ format)") | |
111 | @RequestParam | |
112 | String end_quarterYYYYQ) { | |
113 | ||
114 | var job = | |
115 | updateCourseDataJobFactory.createForSubjectAndQuarterRange( | |
116 | subjectArea, start_quarterYYYYQ, end_quarterYYYYQ); | |
117 | ||
118 |
1
1. launchUpdateCourseDataRangeOfQuartersSingleSubjectJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataRangeOfQuartersSingleSubjectJob → KILLED |
return jobService.runAsJob(job); |
119 | } | |
120 | ||
121 | @Operation(summary = "Launch Job to update grade history") | |
122 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
123 | @PostMapping("/launch/uploadGradeData") | |
124 | public Job launchUploadGradeData() { | |
125 | UploadGradeDataJob updateGradeDataJob = updateGradeDataJobFactory.create(); | |
126 |
1
1. launchUploadGradeData : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUploadGradeData → KILLED |
return jobService.runAsJob(updateGradeDataJob); |
127 | } | |
128 | } | |
Mutations | ||
44 |
1.1 |
|
55 |
1.1 |
|
68 |
1.1 |
|
80 |
1.1 |
|
97 |
1.1 |
|
118 |
1.1 |
|
126 |
1.1 |