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