| 1 | package edu.ucsb.cs156.happiercows.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.happiercows.jobs.InstructorReportJob; | |
| 4 | import edu.ucsb.cs156.happiercows.jobs.InstructorReportJobFactory; | |
| 5 | import edu.ucsb.cs156.happiercows.jobs.InstructorReportJobSingleCommons; | |
| 6 | import edu.ucsb.cs156.happiercows.jobs.InstructorReportJobSingleCommonsFactory; | |
| 7 | import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobFactory; | |
| 8 | import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobFactoryInd; | |
| 9 | import edu.ucsb.cs156.happiercows.jobs.RecordCommonStatsJob; | |
| 10 | import edu.ucsb.cs156.happiercows.jobs.RecordCommonStatsJobFactory; | |
| 11 | import edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobFactory; | |
| 12 | import edu.ucsb.cs156.happiercows.jobs.TestJob; | |
| 13 | import edu.ucsb.cs156.happiercows.jobs.UpdateCowHealthJobFactory; | |
| 14 | import edu.ucsb.cs156.happiercows.jobs.UpdateCowHealthJobFactoryInd; | |
| 15 | import edu.ucsb.cs156.jobs.entities.Job; | |
| 16 | import edu.ucsb.cs156.jobs.services.JobContextConsumer; | |
| 17 | import edu.ucsb.cs156.jobs.services.JobService; | |
| 18 | import io.swagger.v3.oas.annotations.Operation; | |
| 19 | import io.swagger.v3.oas.annotations.Parameter; | |
| 20 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 21 | import org.springframework.beans.factory.annotation.Autowired; | |
| 22 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 23 | import org.springframework.web.bind.annotation.PostMapping; | |
| 24 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 25 | import org.springframework.web.bind.annotation.RequestParam; | |
| 26 | import org.springframework.web.bind.annotation.RestController; | |
| 27 | ||
| 28 | /** | |
| 29 | * Launch endpoints for this app's concrete jobs. The generic admin endpoints (list jobs, get | |
| 30 | * paginated jobs, get logs, delete jobs) come from the lib-jobs library's own controller. | |
| 31 | */ | |
| 32 | @Tag(name = "Jobs") | |
| 33 | @RequestMapping("/api/jobs") | |
| 34 | @RestController | |
| 35 | public class JobsController extends ApiController { | |
| 36 | ||
| 37 | @Autowired private JobService jobService; | |
| 38 | ||
| 39 | @Autowired UpdateCowHealthJobFactory updateCowHealthJobFactory; | |
| 40 | ||
| 41 | @Autowired MilkTheCowsJobFactory milkTheCowsJobFactory; | |
| 42 | ||
| 43 | @Autowired MilkTheCowsJobFactoryInd milkTheCowsJobFactoryInd; | |
| 44 | ||
| 45 | @Autowired SetCowHealthJobFactory setCowHealthJobFactory; | |
| 46 | ||
| 47 | @Autowired InstructorReportJobFactory instructorReportJobFactory; | |
| 48 | ||
| 49 | @Autowired InstructorReportJobSingleCommonsFactory instructorReportJobSingleCommonsFactory; | |
| 50 | ||
| 51 | @Autowired UpdateCowHealthJobFactoryInd updateCowHealthJobFactoryInd; | |
| 52 | ||
| 53 | @Autowired RecordCommonStatsJobFactory recordCommonStatsJobFactory; | |
| 54 | ||
| 55 | @Operation(summary = "Launch Test Job (click fail if you want to test exception handling)") | |
| 56 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 57 | @PostMapping("/launch/testjob") | |
| 58 | public Job launchTestJob( | |
| 59 | @Parameter(name = "fail") @RequestParam Boolean fail, | |
| 60 | @Parameter(name = "sleepMs") @RequestParam Integer sleepMs) { | |
| 61 | TestJob testJob = TestJob.builder().fail(fail).sleepMs(sleepMs).build(); | |
| 62 | ||
| 63 | // Reference: frontend/src/components/Jobs/TestJobForm.js | |
| 64 |
4
1. launchTestJob : negated conditional → KILLED 2. launchTestJob : negated conditional → KILLED 3. launchTestJob : changed conditional boundary → KILLED 4. launchTestJob : changed conditional boundary → KILLED |
if (sleepMs < 0 || sleepMs > 60000) { |
| 65 | throw new IllegalArgumentException("sleepMs must be between 0 and 60000"); | |
| 66 | } | |
| 67 | ||
| 68 |
1
1. launchTestJob : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchTestJob → KILLED |
return jobService.runAsJob(testJob); |
| 69 | } | |
| 70 | ||
| 71 | @Operation(summary = "Launch Job to Milk the Cows (click fail if you want to test exception handling)") | |
| 72 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 73 | @PostMapping("/launch/milkthecowjob") | |
| 74 | public Job launchMilkTheCowsJob() { | |
| 75 | JobContextConsumer milkTheCowsJob = milkTheCowsJobFactory.create(); | |
| 76 |
1
1. launchMilkTheCowsJob : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchMilkTheCowsJob → KILLED |
return jobService.runAsJob(milkTheCowsJob); |
| 77 | } | |
| 78 | ||
| 79 | @Operation(summary = "Launch Job to Milk the Cows for a single commons") | |
| 80 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 81 | @PostMapping("/launch/milkthecowjobsinglecommons") | |
| 82 | public Job launchMilkTheCowsJobSingleCommons( | |
| 83 | @Parameter(name = "commonsId") @RequestParam Long commonsId) { | |
| 84 | JobContextConsumer milkTheCowsJobInd = milkTheCowsJobFactoryInd.create(commonsId); | |
| 85 |
1
1. launchMilkTheCowsJobSingleCommons : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchMilkTheCowsJobSingleCommons → KILLED |
return jobService.runAsJob(milkTheCowsJobInd); |
| 86 | } | |
| 87 | ||
| 88 | @Operation(summary = "Launch Job to Update Cow Health") | |
| 89 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 90 | @PostMapping("/launch/updatecowhealth") | |
| 91 | public Job updateCowHealth() { | |
| 92 | JobContextConsumer updateCowHealthJob = updateCowHealthJobFactory.create(); | |
| 93 |
1
1. updateCowHealth : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::updateCowHealth → KILLED |
return jobService.runAsJob(updateCowHealthJob); |
| 94 | } | |
| 95 | ||
| 96 | @Operation(summary = "Launch Job to Update Cow Health for a single commons") | |
| 97 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 98 | @PostMapping("/launch/updatecowhealthsinglecommons") | |
| 99 | public Job updateCowHealthSingleCommons( | |
| 100 | @Parameter(name = "commonsId") @RequestParam Long commonsId) { | |
| 101 | JobContextConsumer updateCowHealthJobInd = updateCowHealthJobFactoryInd.create(commonsId); | |
| 102 |
1
1. updateCowHealthSingleCommons : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::updateCowHealthSingleCommons → KILLED |
return jobService.runAsJob(updateCowHealthJobInd); |
| 103 | } | |
| 104 | ||
| 105 | @Operation(summary = "Launch Job to Set Cow Health") | |
| 106 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 107 | @PostMapping("/launch/setcowhealth") | |
| 108 | public Job setCowHealth( | |
| 109 | @Parameter(name = "commonsID") @RequestParam Long commonsID, | |
| 110 | @Parameter(name = "health") @RequestParam double health) { | |
| 111 | JobContextConsumer setCowHealthJob = setCowHealthJobFactory.create(commonsID, health); | |
| 112 | ||
| 113 | // Reference: frontend/src/components/Jobs/SetCowHealthForm.js | |
| 114 |
4
1. setCowHealth : negated conditional → KILLED 2. setCowHealth : changed conditional boundary → KILLED 3. setCowHealth : negated conditional → KILLED 4. setCowHealth : changed conditional boundary → KILLED |
if (health < 0 || health > 100) { |
| 115 | throw new IllegalArgumentException("health must be between 0 and 100"); | |
| 116 | } | |
| 117 | ||
| 118 |
1
1. setCowHealth : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::setCowHealth → KILLED |
return jobService.runAsJob(setCowHealthJob); |
| 119 | } | |
| 120 | ||
| 121 | @Operation(summary = "Launch Job to Produce Instructor Report") | |
| 122 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 123 | @PostMapping("/launch/instructorreport") | |
| 124 | public Job instructorReport() { | |
| 125 | InstructorReportJob instructorReportJob = | |
| 126 | (InstructorReportJob) instructorReportJobFactory.create(); | |
| 127 |
1
1. instructorReport : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::instructorReport → KILLED |
return jobService.runAsJob(instructorReportJob); |
| 128 | } | |
| 129 | ||
| 130 | @Operation(summary = "Launch Job to Produce Instructor Report for a single commons") | |
| 131 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 132 | @PostMapping("/launch/instructorreportsinglecommons") | |
| 133 | public Job instructorReportSingleCommons( | |
| 134 | @Parameter(name = "commonsId") @RequestParam Long commonsId) { | |
| 135 | ||
| 136 | InstructorReportJobSingleCommons instructorReportJobSingleCommons = | |
| 137 | (InstructorReportJobSingleCommons) instructorReportJobSingleCommonsFactory.create(commonsId); | |
| 138 |
1
1. instructorReportSingleCommons : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::instructorReportSingleCommons → KILLED |
return jobService.runAsJob(instructorReportJobSingleCommons); |
| 139 | } | |
| 140 | ||
| 141 | @Operation(summary = "Launch Job to Record the Stats of all Commons") | |
| 142 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 143 | @PostMapping("/launch/recordcommonstats") | |
| 144 | public Job recordCommonStats() { | |
| 145 | ||
| 146 | RecordCommonStatsJob recordCommonStatsJob = | |
| 147 | (RecordCommonStatsJob) recordCommonStatsJobFactory.create(); | |
| 148 |
1
1. recordCommonStats : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::recordCommonStats → KILLED |
return jobService.runAsJob(recordCommonStatsJob); |
| 149 | } | |
| 150 | } | |
Mutations | ||
| 64 |
1.1 2.2 3.3 4.4 |
|
| 68 |
1.1 |
|
| 76 |
1.1 |
|
| 85 |
1.1 |
|
| 93 |
1.1 |
|
| 102 |
1.1 |
|
| 114 |
1.1 2.2 3.3 4.4 |
|
| 118 |
1.1 |
|
| 127 |
1.1 |
|
| 138 |
1.1 |
|
| 148 |
1.1 |