1 | package edu.ucsb.cs156.happiercows.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 | import lombok.extern.slf4j.Slf4j; | |
9 | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | |
11 | import org.springframework.context.annotation.Import; | |
12 | import org.springframework.security.access.prepost.PreAuthorize; | |
13 | import org.springframework.web.bind.annotation.GetMapping; | |
14 | import org.springframework.web.bind.annotation.PostMapping; | |
15 | import org.springframework.web.bind.annotation.PutMapping; | |
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.happiercows.entities.jobs.Job; | |
21 | import edu.ucsb.cs156.happiercows.jobs.InstructorReportJob; | |
22 | import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJob; | |
23 | import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobFactory; | |
24 | import edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobFactory; | |
25 | import edu.ucsb.cs156.happiercows.jobs.TestJob; | |
26 | import edu.ucsb.cs156.happiercows.jobs.UpdateCowHealthJob; | |
27 | import edu.ucsb.cs156.happiercows.jobs.UpdateCowHealthJobFactory; | |
28 | import edu.ucsb.cs156.happiercows.repositories.jobs.JobsRepository; | |
29 | import edu.ucsb.cs156.happiercows.services.jobs.JobContextConsumer; | |
30 | import edu.ucsb.cs156.happiercows.services.jobs.JobService; | |
31 | ||
32 | ||
33 | ||
34 | @Slf4j | |
35 | @Api(description = "Jobs") | |
36 | @RequestMapping("/api/jobs") | |
37 | @RestController | |
38 | public class JobsController extends ApiController { | |
39 | @Autowired | |
40 | private JobsRepository jobsRepository; | |
41 | ||
42 | @Autowired | |
43 | private JobService jobService; | |
44 | ||
45 | @Autowired | |
46 | ObjectMapper mapper; | |
47 | ||
48 | @Autowired | |
49 | UpdateCowHealthJobFactory updateCowHealthJobFactory; | |
50 | ||
51 | @Autowired | |
52 | MilkTheCowsJobFactory milkTheCowsJobFactory; | |
53 | ||
54 | @Autowired | |
55 | SetCowHealthJobFactory setCowHealthJobFactory; | |
56 | ||
57 | @ApiOperation(value = "List all jobs") | |
58 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
59 | @GetMapping("/all") | |
60 | public Iterable<Job> allJobs() { | |
61 | Iterable<Job> jobs = jobsRepository.findAll(); | |
62 |
1
1. allJobs : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::allJobs → KILLED |
return jobs; |
63 | } | |
64 | ||
65 | @ApiOperation(value = "Launch Test Job (click fail if you want to test exception handling)") | |
66 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
67 | @PostMapping("/launch/testjob") | |
68 | public Job launchTestJob( | |
69 | @ApiParam("fail") @RequestParam Boolean fail, | |
70 | @ApiParam("sleepMs") @RequestParam Integer sleepMs | |
71 | ) { | |
72 | TestJob testJob = TestJob.builder() | |
73 | .fail(fail) | |
74 | .sleepMs(sleepMs) | |
75 | .build(); | |
76 | ||
77 |
1
1. launchTestJob : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchTestJob → KILLED |
return jobService.runAsJob(testJob); |
78 | } | |
79 | ||
80 | @ApiOperation(value = "Launch Job to Milk the Cows (click fail if you want to test exception handling)") | |
81 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
82 | @PostMapping("/launch/milkthecowjob") | |
83 | public Job launchTestJob( | |
84 | ) { | |
85 | JobContextConsumer milkTheCowsJob = milkTheCowsJobFactory.create(); | |
86 |
1
1. launchTestJob : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchTestJob → KILLED |
return jobService.runAsJob(milkTheCowsJob); |
87 | } | |
88 | ||
89 | @ApiOperation(value = "Launch Job to Update Cow Health") | |
90 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
91 | @PostMapping("/launch/updatecowhealth") | |
92 | public Job updateCowHealth( | |
93 | ) { | |
94 | JobContextConsumer updateCowHealthJob = updateCowHealthJobFactory.create(); | |
95 |
1
1. updateCowHealth : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::updateCowHealth → KILLED |
return jobService.runAsJob(updateCowHealthJob); |
96 | } | |
97 | ||
98 | @ApiOperation(value = "Launch Job to Set Cow Health") | |
99 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
100 | @PostMapping("/launch/setcowhealth") | |
101 | public Job setCowHealth( | |
102 | @ApiParam("commonsID") @RequestParam Long commonsID, | |
103 | @ApiParam("health") @RequestParam double health | |
104 | ) { | |
105 | JobContextConsumer setCowHealthJob = setCowHealthJobFactory.create(commonsID, health); | |
106 |
1
1. setCowHealth : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::setCowHealth → KILLED |
return jobService.runAsJob(setCowHealthJob); |
107 | } | |
108 | ||
109 | @ApiOperation(value = "Launch Job to Produce Instructor Report") | |
110 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
111 | @PostMapping("/launch/instructorreport") | |
112 | public Job instructorReport( | |
113 | ) { | |
114 | InstructorReportJob instructorReportJob = | |
115 | InstructorReportJob.builder().build(); | |
116 | | |
117 |
1
1. instructorReport : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::instructorReport → KILLED |
return jobService.runAsJob(instructorReportJob); |
118 | } | |
119 | } | |
Mutations | ||
62 |
1.1 |
|
77 |
1.1 |
|
86 |
1.1 |
|
95 |
1.1 |
|
106 |
1.1 |
|
117 |
1.1 |