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