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