| 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.DeleteTeamMemberFromGithubJob; | |
| 10 | import edu.ucsb.cs156.frontiers.jobs.MembershipAuditJob; | |
| 11 | import edu.ucsb.cs156.frontiers.jobs.PushTeamsToGithubJob; | |
| 12 | import edu.ucsb.cs156.frontiers.jobs.UpdateAllJob; | |
| 13 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 14 | import edu.ucsb.cs156.frontiers.repositories.CourseStaffRepository; | |
| 15 | import edu.ucsb.cs156.frontiers.repositories.JobsRepository; | |
| 16 | import edu.ucsb.cs156.frontiers.repositories.RosterStudentRepository; | |
| 17 | import edu.ucsb.cs156.frontiers.repositories.TeamMemberRepository; | |
| 18 | import edu.ucsb.cs156.frontiers.repositories.TeamRepository; | |
| 19 | import edu.ucsb.cs156.frontiers.services.GithubTeamService; | |
| 20 | import edu.ucsb.cs156.frontiers.services.OrganizationMemberService; | |
| 21 | import edu.ucsb.cs156.frontiers.services.UpdateUserService; | |
| 22 | import edu.ucsb.cs156.frontiers.services.jobs.JobService; | |
| 23 | import io.swagger.v3.oas.annotations.Operation; | |
| 24 | import io.swagger.v3.oas.annotations.Parameter; | |
| 25 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 26 | import java.util.Map; | |
| 27 | import lombok.extern.slf4j.Slf4j; | |
| 28 | import org.springframework.beans.factory.annotation.Autowired; | |
| 29 | import org.springframework.data.domain.Sort; | |
| 30 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 31 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 32 | import org.springframework.web.bind.annotation.GetMapping; | |
| 33 | import org.springframework.web.bind.annotation.PathVariable; | |
| 34 | import org.springframework.web.bind.annotation.PostMapping; | |
| 35 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 36 | import org.springframework.web.bind.annotation.RequestParam; | |
| 37 | import org.springframework.web.bind.annotation.RestController; | |
| 38 | ||
| 39 | @Tag(name = "Jobs") | |
| 40 | @RequestMapping("/api/jobs") | |
| 41 | @RestController | |
| 42 | @Slf4j | |
| 43 | public class JobsController extends ApiController { | |
| 44 | @Autowired private JobsRepository jobsRepository; | |
| 45 | ||
| 46 | @Autowired private JobService jobService; | |
| 47 | ||
| 48 | @Autowired private UpdateUserService updateUserService; | |
| 49 | ||
| 50 | @Autowired ObjectMapper mapper; | |
| 51 | @Autowired private RosterStudentRepository rosterStudentRepository; | |
| 52 | @Autowired private CourseRepository courseRepository; | |
| 53 | @Autowired private OrganizationMemberService organizationMemberService; | |
| 54 | @Autowired private CourseStaffRepository courseStaffRepository; | |
| 55 | @Autowired private TeamRepository teamRepository; | |
| 56 | @Autowired private TeamMemberRepository teamMemberRepository; | |
| 57 | @Autowired private GithubTeamService githubTeamService; | |
| 58 | ||
| 59 | @Operation(summary = "List all jobs") | |
| 60 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 61 | @GetMapping("/all") | |
| 62 | public Iterable<Job> allJobs() { | |
| 63 | Iterable<Job> jobs = jobsRepository.findAll(by(Sort.Direction.DESC, "createdAt")); | |
| 64 |
1
1. allJobs : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/JobsController::allJobs → KILLED |
return jobs; |
| 65 | } | |
| 66 | ||
| 67 | @Operation(summary = "Delete all job records") | |
| 68 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 69 | @DeleteMapping("/all") | |
| 70 | public Map<String, String> deleteAllJobs() { | |
| 71 |
1
1. deleteAllJobs : removed call to edu/ucsb/cs156/frontiers/repositories/JobsRepository::deleteAll → KILLED |
jobsRepository.deleteAll(); |
| 72 |
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"); |
| 73 | } | |
| 74 | ||
| 75 | @Operation(summary = "Get a specific Job Log by ID if it is in the database") | |
| 76 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 77 | @GetMapping("") | |
| 78 | public Job getJobLogById( | |
| 79 | @Parameter(name = "id", description = "ID of the job") @RequestParam Long id) | |
| 80 | throws JsonProcessingException { | |
| 81 | ||
| 82 | Job job = | |
| 83 |
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)); |
| 84 | ||
| 85 |
1
1. getJobLogById : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::getJobLogById → KILLED |
return job; |
| 86 | } | |
| 87 | ||
| 88 | @Operation(summary = "Delete specific job record") | |
| 89 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 90 | @DeleteMapping("") | |
| 91 | public Map<String, String> deleteAllJobs(@Parameter(name = "id") @RequestParam Long id) { | |
| 92 |
1
1. deleteAllJobs : negated conditional → KILLED |
if (!jobsRepository.existsById(id)) { |
| 93 |
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)); |
| 94 | } | |
| 95 |
1
1. deleteAllJobs : removed call to edu/ucsb/cs156/frontiers/repositories/JobsRepository::deleteById → KILLED |
jobsRepository.deleteById(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 deleted", id)); |
| 97 | } | |
| 98 | ||
| 99 | @Operation(summary = "Get long job logs") | |
| 100 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 101 | @GetMapping("/logs/{id}") | |
| 102 | public String getJobLogs(@Parameter(name = "id", description = "Job ID") @PathVariable Long id) { | |
| 103 | ||
| 104 |
1
1. getJobLogs : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/JobsController::getJobLogs → KILLED |
return jobService.getJobLogs(id); |
| 105 | } | |
| 106 | ||
| 107 | @Operation(summary = "Launch UpdateAll job") | |
| 108 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 109 | @PostMapping("/launch/updateAll") | |
| 110 | public Job launchUpdateAllJob() { | |
| 111 | ||
| 112 | UpdateAllJob job = UpdateAllJob.builder().updateUserService(updateUserService).build(); | |
| 113 |
1
1. launchUpdateAllJob : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchUpdateAllJob → KILLED |
return jobService.runAsJob(job); |
| 114 | } | |
| 115 | ||
| 116 | @Operation(summary = "Launch Audit All Courses Job") | |
| 117 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 118 | @PostMapping("/launch/auditAllCourses") | |
| 119 | public Job launchAuditAllCoursesJob() { | |
| 120 | ||
| 121 | MembershipAuditJob job = | |
| 122 | MembershipAuditJob.builder() | |
| 123 | .rosterStudentRepository(rosterStudentRepository) | |
| 124 | .courseRepository(courseRepository) | |
| 125 | .organizationMemberService(organizationMemberService) | |
| 126 | .courseStaffRepository(courseStaffRepository) | |
| 127 | .build(); | |
| 128 |
1
1. launchAuditAllCoursesJob : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchAuditAllCoursesJob → KILLED |
return jobService.runAsJob(job); |
| 129 | } | |
| 130 | ||
| 131 | @Operation(summary = "Launch Push Teams to GitHub Job") | |
| 132 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 133 | @PostMapping("/launch/pushTeamsToGithub") | |
| 134 | public Job launchPushTeamsToGithubJob(@Parameter(name = "courseId") @RequestParam Long courseId) { | |
| 135 | ||
| 136 | PushTeamsToGithubJob job = | |
| 137 | PushTeamsToGithubJob.builder() | |
| 138 | .courseId(courseId) | |
| 139 | .courseRepository(courseRepository) | |
| 140 | .teamRepository(teamRepository) | |
| 141 | .teamMemberRepository(teamMemberRepository) | |
| 142 | .githubTeamService(githubTeamService) | |
| 143 | .build(); | |
| 144 |
1
1. launchPushTeamsToGithubJob : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchPushTeamsToGithubJob → KILLED |
return jobService.runAsJob(job); |
| 145 | } | |
| 146 | ||
| 147 | @Operation(summary = "Launch Delete Team Member From GitHub Job") | |
| 148 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 149 | @PostMapping("/launch/deleteTeamMemberFromGithub") | |
| 150 | public Job launchDeleteTeamMemberFromGithubJob( | |
| 151 | @Parameter(name = "memberGithubLogin") @RequestParam String memberGithubLogin, | |
| 152 | @Parameter(name = "githubTeamId") @RequestParam Integer githubTeamId, | |
| 153 | @Parameter(name = "courseId") @RequestParam Long courseId) { | |
| 154 | ||
| 155 | DeleteTeamMemberFromGithubJob job = | |
| 156 | DeleteTeamMemberFromGithubJob.builder() | |
| 157 | .memberGithubLogin(memberGithubLogin) | |
| 158 | .githubTeamId(githubTeamId) | |
| 159 | .course(courseRepository.findById(courseId).get()) | |
| 160 | .githubTeamService(githubTeamService) | |
| 161 | .build(); | |
| 162 |
1
1. launchDeleteTeamMemberFromGithubJob : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchDeleteTeamMemberFromGithubJob → KILLED |
return jobService.runAsJob(job); |
| 163 | } | |
| 164 | } | |
Mutations | ||
| 64 |
1.1 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 83 |
1.1 |
|
| 85 |
1.1 |
|
| 92 |
1.1 |
|
| 93 |
1.1 |
|
| 95 |
1.1 |
|
| 96 |
1.1 |
|
| 104 |
1.1 |
|
| 113 |
1.1 |
|
| 128 |
1.1 |
|
| 144 |
1.1 |
|
| 162 |
1.1 |