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