JobsController.java

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
Location : allJobs
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests]/[method:admin_can_get_all_jobs()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/JobsController::allJobs → KILLED

70

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests]/[method:admin_can_delete_all_jobs()]
removed call to edu/ucsb/cs156/frontiers/repositories/JobsRepository::deleteAll → KILLED

71

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests]/[method:admin_can_delete_all_jobs()]
replaced return value with Collections.emptyMap for edu/ucsb/cs156/frontiers/controllers/JobsController::deleteAllJobs → KILLED

82

1.1
Location : lambda$getJobLogById$0
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests]/[method:api_getJobLogById__admin_logged_in__returns_not_found_for_missing_job()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::lambda$getJobLogById$0 → KILLED

84

1.1
Location : getJobLogById
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests]/[method:api_getJobLogById__admin_logged_in__returns_job_by_id()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::getJobLogById → KILLED

91

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests]/[method:admin_can_delete_specific_job()]
negated conditional → KILLED

92

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests]/[method:admin_gets_reasonable_error_when_deleting_non_existing_job()]
replaced return value with Collections.emptyMap for edu/ucsb/cs156/frontiers/controllers/JobsController::deleteAllJobs → KILLED

94

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests]/[method:admin_can_delete_specific_job()]
removed call to edu/ucsb/cs156/frontiers/repositories/JobsRepository::deleteById → KILLED

95

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests]/[method:admin_can_delete_specific_job()]
replaced return value with Collections.emptyMap for edu/ucsb/cs156/frontiers/controllers/JobsController::deleteAllJobs → KILLED

103

1.1
Location : getJobLogs
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests]/[method:test_getJobLogs_admin_can_get_job_log()]
replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/JobsController::getJobLogs → KILLED

112

1.1
Location : launchUpdateAllJob
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerDetailedTests]/[method:admin_can_launch_updateAll_job()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchUpdateAllJob → KILLED

127

1.1
Location : launchAuditAllCoursesJob
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerJobsTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerJobsTests]/[method:admin_can_launch_auditAllCourses_job()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchAuditAllCoursesJob → KILLED

143

1.1
Location : launchPushTeamsToGithubJob
Killed by : edu.ucsb.cs156.frontiers.controllers.JobsControllerJobsTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.JobsControllerJobsTests]/[method:admin_can_launch_pushTeamsToGithub_job()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/JobsController::launchPushTeamsToGithubJob → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0