| 1 | package edu.ucsb.cs156.frontiers.controllers; | |
| 2 | ||
| 3 | import static org.springframework.data.domain.Sort.by; | |
| 4 | ||
| 5 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 6 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 7 | import edu.ucsb.cs156.frontiers.entities.Job; | |
| 8 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
| 9 | import edu.ucsb.cs156.frontiers.jobs.AddTeamMemberToGithubJob; | |
| 10 | import edu.ucsb.cs156.frontiers.jobs.AddTeamToGithubJob; | |
| 11 | import edu.ucsb.cs156.frontiers.jobs.DeleteTeamFromGithubJob; | |
| 12 | import edu.ucsb.cs156.frontiers.jobs.DeleteTeamMemberFromGithubJob; | |
| 13 | import edu.ucsb.cs156.frontiers.jobs.MembershipAuditJob; | |
| 14 | import edu.ucsb.cs156.frontiers.jobs.PushTeamsToGithubJob; | |
| 15 | import edu.ucsb.cs156.frontiers.jobs.UpdateAllJob; | |
| 16 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 17 | import edu.ucsb.cs156.frontiers.repositories.CourseStaffRepository; | |
| 18 | import edu.ucsb.cs156.frontiers.repositories.JobsRepository; | |
| 19 | import edu.ucsb.cs156.frontiers.repositories.RosterStudentRepository; | |
| 20 | import edu.ucsb.cs156.frontiers.repositories.TeamMemberRepository; | |
| 21 | import edu.ucsb.cs156.frontiers.repositories.TeamRepository; | |
| 22 | import edu.ucsb.cs156.frontiers.services.GithubTeamService; | |
| 23 | import edu.ucsb.cs156.frontiers.services.OrganizationMemberService; | |
| 24 | import edu.ucsb.cs156.frontiers.services.UpdateUserService; | |
| 25 | import edu.ucsb.cs156.frontiers.services.jobs.JobService; | |
| 26 | import io.swagger.v3.oas.annotations.Operation; | |
| 27 | import io.swagger.v3.oas.annotations.Parameter; | |
| 28 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 29 | import java.util.Map; | |
| 30 | import lombok.extern.slf4j.Slf4j; | |
| 31 | import org.springframework.beans.factory.annotation.Autowired; | |
| 32 | import org.springframework.data.domain.Sort; | |
| 33 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 34 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 35 | import org.springframework.web.bind.annotation.GetMapping; | |
| 36 | import org.springframework.web.bind.annotation.PathVariable; | |
| 37 | import org.springframework.web.bind.annotation.PostMapping; | |
| 38 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 39 | import org.springframework.web.bind.annotation.RequestParam; | |
| 40 | import org.springframework.web.bind.annotation.RestController; | |
| 41 | ||
| 42 | @Tag(name = "Jobs") | |
| 43 | @RequestMapping("/api/jobs") | |
| 44 | @RestController | |
| 45 | @Slf4j | |
| 46 | public class JobsController extends ApiController { | |
| 47 | @Autowired private JobsRepository jobsRepository; | |
| 48 | ||
| 49 | @Autowired private JobService jobService; | |
| 50 | ||
| 51 | @Autowired private UpdateUserService updateUserService; | |
| 52 | ||
| 53 | @Autowired ObjectMapper mapper; | |
| 54 | @Autowired private RosterStudentRepository rosterStudentRepository; | |
| 55 | @Autowired private CourseRepository courseRepository; | |
| 56 | @Autowired private OrganizationMemberService organizationMemberService; | |
| 57 | @Autowired private CourseStaffRepository courseStaffRepository; | |
| 58 | @Autowired private TeamRepository teamRepository; | |
| 59 | @Autowired private TeamMemberRepository teamMemberRepository; | |
| 60 | @Autowired private GithubTeamService githubTeamService; | |
| 61 | ||
| 62 | @Operation(summary = "List all jobs") | |
| 63 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 64 | @GetMapping("/all") | |
| 65 | public Iterable<Job> allJobs() { | |
| 66 | Iterable<Job> jobs = jobsRepository.findAll(by(Sort.Direction.DESC, "createdAt")); | |
| 67 |
1
1. allJobs : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/JobsController::allJobs → KILLED |
return jobs; |
| 68 | } | |
| 69 | ||
| 70 | @Operation(summary = "Delete all job records") | |
| 71 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 72 | @DeleteMapping("/all") | |
| 73 | public Map<String, String> deleteAllJobs() { | |
| 74 |
1
1. deleteAllJobs : removed call to edu/ucsb/cs156/frontiers/repositories/JobsRepository::deleteAll → KILLED |
jobsRepository.deleteAll(); |
| 75 |
1
1. deleteAllJobs : replaced return value with Collections.emptyMap for edu/ucsb/cs156/frontiers/controllers/JobsController::deleteAllJobs → KILLED |
return Map.of("message", "All jobs deleted"); |
| 76 | } | |
| 77 | ||
| 78 | @Operation(summary = "Get a specific Job Log by ID if it is in the database") | |
| 79 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 80 | @GetMapping("") | |
| 81 | public Job getJobLogById( | |
| 82 | @Parameter(name = "id", description = "ID of the job") @RequestParam Long id) | |
| 83 | throws JsonProcessingException { | |
| 84 | ||
| 85 | Job job = | |
| 86 |
1
1. lambda$getJobLogById$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::lambda$getJobLogById$0 → KILLED |
jobsRepository.findById(id).orElseThrow(() -> new EntityNotFoundException(Job.class, id)); |
| 87 | ||
| 88 |
1
1. getJobLogById : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::getJobLogById → KILLED |
return job; |
| 89 | } | |
| 90 | ||
| 91 | @Operation(summary = "Delete specific job record") | |
| 92 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 93 | @DeleteMapping("") | |
| 94 | public Map<String, String> deleteAllJobs(@Parameter(name = "id") @RequestParam Long id) { | |
| 95 |
1
1. deleteAllJobs : negated conditional → KILLED |
if (!jobsRepository.existsById(id)) { |
| 96 |
1
1. deleteAllJobs : replaced return value with Collections.emptyMap for edu/ucsb/cs156/frontiers/controllers/JobsController::deleteAllJobs → KILLED |
return Map.of("message", String.format("Job with id %d not found", id)); |
| 97 | } | |
| 98 |
1
1. deleteAllJobs : removed call to edu/ucsb/cs156/frontiers/repositories/JobsRepository::deleteById → KILLED |
jobsRepository.deleteById(id); |
| 99 |
1
1. deleteAllJobs : replaced return value with Collections.emptyMap for edu/ucsb/cs156/frontiers/controllers/JobsController::deleteAllJobs → KILLED |
return Map.of("message", String.format("Job with id %d deleted", id)); |
| 100 | } | |
| 101 | ||
| 102 | @Operation(summary = "Get long job logs") | |
| 103 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 104 | @GetMapping("/logs/{id}") | |
| 105 | public String getJobLogs(@Parameter(name = "id", description = "Job ID") @PathVariable Long id) { | |
| 106 | ||
| 107 |
1
1. getJobLogs : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/JobsController::getJobLogs → KILLED |
return jobService.getJobLogs(id); |
| 108 | } | |
| 109 | ||
| 110 | @Operation(summary = "Launch UpdateAll job") | |
| 111 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 112 | @PostMapping("/launch/updateAll") | |
| 113 | public Job launchUpdateAllJob() { | |
| 114 | ||
| 115 | UpdateAllJob job = UpdateAllJob.builder().updateUserService(updateUserService).build(); | |
| 116 |
1
1. launchUpdateAllJob : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchUpdateAllJob → KILLED |
return jobService.runAsJob(job); |
| 117 | } | |
| 118 | ||
| 119 | @Operation(summary = "Launch Audit All Courses Job") | |
| 120 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 121 | @PostMapping("/launch/auditAllCourses") | |
| 122 | public Job launchAuditAllCoursesJob() { | |
| 123 | ||
| 124 | MembershipAuditJob job = | |
| 125 | MembershipAuditJob.builder() | |
| 126 | .rosterStudentRepository(rosterStudentRepository) | |
| 127 | .courseRepository(courseRepository) | |
| 128 | .organizationMemberService(organizationMemberService) | |
| 129 | .courseStaffRepository(courseStaffRepository) | |
| 130 | .build(); | |
| 131 |
1
1. launchAuditAllCoursesJob : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchAuditAllCoursesJob → KILLED |
return jobService.runAsJob(job); |
| 132 | } | |
| 133 | ||
| 134 | @Operation(summary = "Launch Push Teams to GitHub Job") | |
| 135 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 136 | @PostMapping("/launch/pushTeamsToGithub") | |
| 137 | public Job launchPushTeamsToGithubJob(@Parameter(name = "courseId") @RequestParam Long courseId) { | |
| 138 | ||
| 139 | PushTeamsToGithubJob job = | |
| 140 | PushTeamsToGithubJob.builder() | |
| 141 | .courseId(courseId) | |
| 142 | .courseRepository(courseRepository) | |
| 143 | .teamRepository(teamRepository) | |
| 144 | .teamMemberRepository(teamMemberRepository) | |
| 145 | .githubTeamService(githubTeamService) | |
| 146 | .build(); | |
| 147 |
1
1. launchPushTeamsToGithubJob : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchPushTeamsToGithubJob → KILLED |
return jobService.runAsJob(job); |
| 148 | } | |
| 149 | ||
| 150 | @Operation(summary = "Launch Delete Team Member From GitHub Job") | |
| 151 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 152 | @PostMapping("/launch/deleteTeamMemberFromGithub") | |
| 153 | public Job launchDeleteTeamMemberFromGithubJob( | |
| 154 | @Parameter(name = "memberGithubLogin") @RequestParam String memberGithubLogin, | |
| 155 | @Parameter(name = "githubTeamId") @RequestParam Integer githubTeamId, | |
| 156 | @Parameter(name = "courseId") @RequestParam Long courseId) { | |
| 157 | ||
| 158 | DeleteTeamMemberFromGithubJob job = | |
| 159 | DeleteTeamMemberFromGithubJob.builder() | |
| 160 | .memberGithubLogin(memberGithubLogin) | |
| 161 | .githubTeamId(githubTeamId) | |
| 162 | .course(courseRepository.findById(courseId).get()) | |
| 163 | .githubTeamService(githubTeamService) | |
| 164 | .build(); | |
| 165 |
1
1. launchDeleteTeamMemberFromGithubJob : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchDeleteTeamMemberFromGithubJob → KILLED |
return jobService.runAsJob(job); |
| 166 | } | |
| 167 | ||
| 168 | @Operation(summary = "Launch Add Team Member To GitHub Job") | |
| 169 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 170 | @PostMapping("/launch/addTeamMemberToGithub") | |
| 171 | public Job launchAddTeamMemberToGithubJob( | |
| 172 | @Parameter(name = "memberGithubLogin") @RequestParam String memberGithubLogin, | |
| 173 | @Parameter(name = "githubTeamId") @RequestParam Integer githubTeamId, | |
| 174 | @Parameter(name = "teamMemberId") @RequestParam Long teamMemberId, | |
| 175 | @Parameter(name = "courseId") @RequestParam Long courseId) { | |
| 176 | ||
| 177 | AddTeamMemberToGithubJob job = | |
| 178 | AddTeamMemberToGithubJob.builder() | |
| 179 | .memberGithubLogin(memberGithubLogin) | |
| 180 | .githubTeamId(githubTeamId) | |
| 181 | .teamMemberId(teamMemberId) | |
| 182 | .course(courseRepository.findById(courseId).get()) | |
| 183 | .githubTeamService(githubTeamService) | |
| 184 | .teamMemberRepository(teamMemberRepository) | |
| 185 | .build(); | |
| 186 |
1
1. launchAddTeamMemberToGithubJob : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchAddTeamMemberToGithubJob → KILLED |
return jobService.runAsJob(job); |
| 187 | } | |
| 188 | ||
| 189 | @Operation(summary = "Launch Delete Team From GitHub Job") | |
| 190 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 191 | @PostMapping("/launch/deleteTeamFromGithub") | |
| 192 | public Job launchDeleteTeamFromGithubJob( | |
| 193 | @Parameter(name = "githubTeamId") @RequestParam Integer githubTeamId, | |
| 194 | @Parameter(name = "courseId") @RequestParam Long courseId) { | |
| 195 | ||
| 196 | DeleteTeamFromGithubJob job = | |
| 197 | DeleteTeamFromGithubJob.builder() | |
| 198 | .githubTeamId(githubTeamId) | |
| 199 | .course(courseRepository.findById(courseId).get()) | |
| 200 | .githubTeamService(githubTeamService) | |
| 201 | .build(); | |
| 202 |
1
1. launchDeleteTeamFromGithubJob : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchDeleteTeamFromGithubJob → KILLED |
return jobService.runAsJob(job); |
| 203 | } | |
| 204 | ||
| 205 | @Operation(summary = "Launch Add Team To GitHub Job") | |
| 206 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 207 | @PostMapping("/launch/addTeamToGithub") | |
| 208 | public Job launchAddTeamToGithubJob( | |
| 209 | @Parameter(name = "teamName") @RequestParam String teamName, | |
| 210 | @Parameter(name = "courseId") @RequestParam Long courseId) { | |
| 211 | ||
| 212 | AddTeamToGithubJob job = | |
| 213 | AddTeamToGithubJob.builder() | |
| 214 | .teamName(teamName) | |
| 215 | .course(courseRepository.findById(courseId).get()) | |
| 216 | .teamRepository(teamRepository) | |
| 217 | .githubTeamService(githubTeamService) | |
| 218 | .build(); | |
| 219 |
1
1. launchAddTeamToGithubJob : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchAddTeamToGithubJob → KILLED |
return jobService.runAsJob(job); |
| 220 | } | |
| 221 | } | |
Mutations | ||
| 67 |
1.1 |
|
| 74 |
1.1 |
|
| 75 |
1.1 |
|
| 86 |
1.1 |
|
| 88 |
1.1 |
|
| 95 |
1.1 |
|
| 96 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 107 |
1.1 |
|
| 116 |
1.1 |
|
| 131 |
1.1 |
|
| 147 |
1.1 |
|
| 165 |
1.1 |
|
| 186 |
1.1 |
|
| 202 |
1.1 |
|
| 219 |
1.1 |