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