| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 5 | import edu.ucsb.cs156.example.entities.Job; | |
| 6 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 7 | import edu.ucsb.cs156.example.repositories.JobsRepository; | |
| 8 | import edu.ucsb.cs156.example.services.jobs.JobService; | |
| 9 | import io.swagger.v3.oas.annotations.Operation; | |
| 10 | import io.swagger.v3.oas.annotations.Parameter; | |
| 11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 12 | import java.util.Map; | |
| 13 | import lombok.extern.slf4j.Slf4j; | |
| 14 | import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PathVariable; | |
| 19 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestParam; | |
| 21 | import org.springframework.web.bind.annotation.RestController; | |
| 22 | ||
| 23 | @Tag(name = "Jobs") | |
| 24 | @RequestMapping("/api/jobs") | |
| 25 | @RestController | |
| 26 | @Slf4j | |
| 27 | public class JobsController extends ApiController { | |
| 28 | @Autowired private JobsRepository jobsRepository; | |
| 29 | ||
| 30 | @Autowired private JobService jobService; | |
| 31 | ||
| 32 | @Autowired ObjectMapper mapper; | |
| 33 | ||
| 34 | @Operation(summary = "List all jobs") | |
| 35 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 36 | @GetMapping("/all") | |
| 37 | public Iterable<Job> allJobs() { | |
| 38 | Iterable<Job> jobs = jobsRepository.findAll(); | |
| 39 |
1
1. allJobs : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/JobsController::allJobs → KILLED |
return jobs; |
| 40 | } | |
| 41 | ||
| 42 | @Operation(summary = "Delete all job records") | |
| 43 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 44 | @DeleteMapping("/all") | |
| 45 | public Map<String, String> deleteAllJobs() { | |
| 46 |
1
1. deleteAllJobs : removed call to edu/ucsb/cs156/example/repositories/JobsRepository::deleteAll → KILLED |
jobsRepository.deleteAll(); |
| 47 |
1
1. deleteAllJobs : replaced return value with Collections.emptyMap for edu/ucsb/cs156/example/controllers/JobsController::deleteAllJobs → KILLED |
return Map.of("message", "All jobs deleted"); |
| 48 | } | |
| 49 | ||
| 50 | @Operation(summary = "Get a specific Job Log by ID if it is in the database") | |
| 51 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 52 | @GetMapping("") | |
| 53 | public Job getJobLogById( | |
| 54 | @Parameter(name = "id", description = "ID of the job") @RequestParam Long id) | |
| 55 | throws JsonProcessingException { | |
| 56 | ||
| 57 | Job job = | |
| 58 |
1
1. lambda$getJobLogById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/JobsController::lambda$getJobLogById$0 → KILLED |
jobsRepository.findById(id).orElseThrow(() -> new EntityNotFoundException(Job.class, id)); |
| 59 | ||
| 60 |
1
1. getJobLogById : replaced return value with null for edu/ucsb/cs156/example/controllers/JobsController::getJobLogById → KILLED |
return job; |
| 61 | } | |
| 62 | ||
| 63 | @Operation(summary = "Delete specific job record") | |
| 64 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 65 | @DeleteMapping("") | |
| 66 | public Map<String, String> deleteAllJobs(@Parameter(name = "id") @RequestParam Long id) { | |
| 67 |
1
1. deleteAllJobs : negated conditional → KILLED |
if (!jobsRepository.existsById(id)) { |
| 68 |
1
1. deleteAllJobs : replaced return value with Collections.emptyMap for edu/ucsb/cs156/example/controllers/JobsController::deleteAllJobs → KILLED |
return Map.of("message", String.format("Job with id %d not found", id)); |
| 69 | } | |
| 70 |
1
1. deleteAllJobs : removed call to edu/ucsb/cs156/example/repositories/JobsRepository::deleteById → KILLED |
jobsRepository.deleteById(id); |
| 71 |
1
1. deleteAllJobs : replaced return value with Collections.emptyMap for edu/ucsb/cs156/example/controllers/JobsController::deleteAllJobs → KILLED |
return Map.of("message", String.format("Job with id %d deleted", id)); |
| 72 | } | |
| 73 | ||
| 74 | @Operation(summary = "Get long job logs") | |
| 75 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 76 | @GetMapping("/logs/{id}") | |
| 77 | public String getJobLogs(@Parameter(name = "id", description = "Job ID") @PathVariable Long id) { | |
| 78 | ||
| 79 |
1
1. getJobLogs : replaced return value with "" for edu/ucsb/cs156/example/controllers/JobsController::getJobLogs → KILLED |
return jobService.getJobLogs(id); |
| 80 | } | |
| 81 | } | |
Mutations | ||
| 39 |
1.1 |
|
| 46 |
1.1 |
|
| 47 |
1.1 |
|
| 58 |
1.1 |
|
| 60 |
1.1 |
|
| 67 |
1.1 |
|
| 68 |
1.1 |
|
| 70 |
1.1 |
|
| 71 |
1.1 |
|
| 79 |
1.1 |