JobsController.java

1
package edu.ucsb.cs156.courses.controllers;
2
3
import com.fasterxml.jackson.databind.ObjectMapper;
4
5
import io.swagger.annotations.Api;
6
import io.swagger.annotations.ApiOperation;
7
import io.swagger.annotations.ApiParam;
8
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.context.annotation.Import;
11
import org.springframework.security.access.prepost.PreAuthorize;
12
import org.springframework.web.bind.annotation.GetMapping;
13
import org.springframework.web.bind.annotation.PostMapping;
14
15
16
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestParam;
18
import org.springframework.web.bind.annotation.RestController;
19
20
import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection;
21
import edu.ucsb.cs156.courses.entities.Job;
22
import edu.ucsb.cs156.courses.jobs.UpdateCourseDataJob;
23
import edu.ucsb.cs156.courses.jobs.UpdateCourseDataJobFactory;
24
import edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersSingleSubjectJob;
25
26
import edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersSingleSubjectJobFactory;
27
import edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJob;
28
29
import edu.ucsb.cs156.courses.jobs.UpdateCourseDataRangeOfQuartersJobFactory;
30
31
import edu.ucsb.cs156.courses.jobs.UpdateCourseDataWithQuarterJob;
32
import edu.ucsb.cs156.courses.jobs.UpdateCourseDataWithQuarterJobFactory;
33
import edu.ucsb.cs156.courses.jobs.TestJob;
34
import edu.ucsb.cs156.courses.repositories.JobsRepository;
35
import edu.ucsb.cs156.courses.services.jobs.JobService;
36
37
38
@Api(description = "Jobs")
39
@RequestMapping("/api/jobs")
40
@RestController
41
public class JobsController extends ApiController {
42
    @Autowired
43
    private JobsRepository jobsRepository;
44
45
    @Autowired
46
    private ConvertedSectionCollection convertedSectionCollection;
47
48
    @Autowired
49
    private JobService jobService;
50
51
    @Autowired
52
    ObjectMapper mapper;
53
54
    @Autowired
55
    UpdateCourseDataJobFactory updateCourseDataJobFactory;
56
57
    @Autowired
58
    UpdateCourseDataWithQuarterJobFactory updateCourseDataWithQuarterJobFactory;
59
60
    @Autowired
61
    UpdateCourseDataRangeOfQuartersJobFactory updateCourseDataRangeOfQuartersJobFactory;
62
63
    @Autowired
64
    UpdateCourseDataRangeOfQuartersSingleSubjectJobFactory updateCourseDataRangeOfQuartersSingleSubjectJobFactory;
65
66
    @ApiOperation(value = "List all jobs")
67
    @PreAuthorize("hasRole('ROLE_ADMIN')")
68
    @GetMapping("/all")
69
    public Iterable<Job> allJobs() {
70
        Iterable<Job> jobs = jobsRepository.findAll();
71 1 1. allJobs : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::allJobs → KILLED
        return jobs;
72
    }
73
74
    @ApiOperation(value = "Launch Test Job (click fail if you want to test exception handling)")
75
    @PreAuthorize("hasRole('ROLE_ADMIN')")
76
    @PostMapping("/launch/testjob")
77
    public Job launchTestJob(
78
        @ApiParam("fail") @RequestParam Boolean fail, 
79
        @ApiParam("sleepMs") @RequestParam Integer sleepMs
80
    ) {
81
82
        TestJob testJob = TestJob.builder()
83
        .fail(fail)
84
        .sleepMs(sleepMs)
85
        .build();
86 1 1. launchTestJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchTestJob → KILLED
        return jobService.runAsJob(testJob);
87
    }
88
    
89
    @ApiOperation(value = "Launch Job to Update Course Data")
90
    @PreAuthorize("hasRole('ROLE_ADMIN')")
91
    @PostMapping("/launch/updateCourses")
92
    public Job launchUpdateCourseDataJob(
93
        @ApiParam("quarter (YYYYQ format)") @RequestParam String quarterYYYYQ,
94
        @ApiParam("subject area") @RequestParam String subjectArea
95
    ) {
96
       
97
        UpdateCourseDataJob updateCourseDataJob = updateCourseDataJobFactory.create(
98
            subjectArea,
99
            quarterYYYYQ);
100
101 1 1. launchUpdateCourseDataJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataJob → KILLED
        return jobService.runAsJob(updateCourseDataJob);
102
    }
103
104
    @ApiOperation(value = "Launch Job to Update Course Data using Quarter")
105
    @PreAuthorize("hasRole('ROLE_ADMIN')")
106
    @PostMapping("/launch/updateQuarterCourses")
107
    public Job launchUpdateCourseDataWithQuarterJob(
108
        @ApiParam("quarter (YYYYQ format)") @RequestParam String quarterYYYYQ
109
    ) {
110
       
111
        UpdateCourseDataWithQuarterJob updateCourseDataWithQuarterJob = updateCourseDataWithQuarterJobFactory.create(
112
            quarterYYYYQ);
113
114 1 1. launchUpdateCourseDataWithQuarterJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataWithQuarterJob → KILLED
        return jobService.runAsJob(updateCourseDataWithQuarterJob);
115
    }
116
117
118
    @ApiOperation(value = "Launch Job to Update Course Data for range of quarters")
119
    @PreAuthorize("hasRole('ROLE_ADMIN')")
120
    @PostMapping("/launch/updateCoursesRangeOfQuarters")
121
    public Job launchUpdateCourseDataRangeOfQuartersJob(
122
        @ApiParam("quarter (YYYYQ format)") @RequestParam String start_quarterYYYYQ,
123
        @ApiParam("quarter (YYYYQ format)") @RequestParam String end_quarterYYYYQ
124
    ) {
125
       
126
        UpdateCourseDataRangeOfQuartersJob updateCourseDataRangeOfQuartersJob = updateCourseDataRangeOfQuartersJobFactory.create(
127
            start_quarterYYYYQ, end_quarterYYYYQ);
128
129 1 1. launchUpdateCourseDataRangeOfQuartersJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataRangeOfQuartersJob → KILLED
        return jobService.runAsJob(updateCourseDataRangeOfQuartersJob);
130
    }
131
132
    @ApiOperation(value = "Launch Job to Update Course Data for a range of quarters for a single subject")
133
    @PreAuthorize("hasRole('ROLE_ADMIN')")
134
    @PostMapping("/launch/updateCoursesRangeOfQuartersSingleSubject")
135
    public Job launchUpdateCourseDataRangeOfQuartersSingleSubjectJob(
136
        @ApiParam("subject area") @RequestParam String subjectArea,
137
        @ApiParam("quarter (YYYYQ format)") @RequestParam String start_quarterYYYYQ,
138
        @ApiParam("quarter (YYYYQ format)") @RequestParam String end_quarterYYYYQ
139
    ) {
140
       
141
        UpdateCourseDataRangeOfQuartersSingleSubjectJob updateCourseDataRangeOfQuartersSingleSubjectJob = 
142
        updateCourseDataRangeOfQuartersSingleSubjectJobFactory.create(
143
            subjectArea, start_quarterYYYYQ, end_quarterYYYYQ);
144
145 1 1. launchUpdateCourseDataRangeOfQuartersSingleSubjectJob : replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataRangeOfQuartersSingleSubjectJob → KILLED
        return jobService.runAsJob(updateCourseDataRangeOfQuartersSingleSubjectJob);
146
    }
147
148
149
}

Mutations

71

1.1
Location : allJobs
Killed by : edu.ucsb.cs156.courses.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.JobsControllerTests]/[method:admin_can_get_all_jobs()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::allJobs → KILLED

86

1.1
Location : launchTestJob
Killed by : edu.ucsb.cs156.courses.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.JobsControllerTests]/[method:admin_can_launch_test_job()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchTestJob → KILLED

101

1.1
Location : launchUpdateCourseDataJob
Killed by : edu.ucsb.cs156.courses.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.JobsControllerTests]/[method:admin_can_launch_update_courses_job()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataJob → KILLED

114

1.1
Location : launchUpdateCourseDataWithQuarterJob
Killed by : edu.ucsb.cs156.courses.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.JobsControllerTests]/[method:admin_can_launch_update_courses_job_with_quarter()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataWithQuarterJob → KILLED

129

1.1
Location : launchUpdateCourseDataRangeOfQuartersJob
Killed by : edu.ucsb.cs156.courses.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.JobsControllerTests]/[method:admin_can_launch_update_courses_range_of_quarters_job()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataRangeOfQuartersJob → KILLED

145

1.1
Location : launchUpdateCourseDataRangeOfQuartersSingleSubjectJob
Killed by : edu.ucsb.cs156.courses.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.JobsControllerTests]/[method:admin_can_launch_update_courses_range_of_quarters_single_subject_job()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/JobsController::launchUpdateCourseDataRangeOfQuartersSingleSubjectJob → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3