| 1 | package edu.ucsb.cs.citelines.controller; | |
| 2 | ||
| 3 | import edu.ucsb.cs.citelines.entity.Researcher; | |
| 4 | import edu.ucsb.cs.citelines.repository.ResearcherRepository; | |
| 5 | import edu.ucsb.cs.citelines.utilities.CanonicalFormConverter; | |
| 6 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | import lombok.extern.slf4j.Slf4j; | |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | import org.springframework.http.ResponseEntity; | |
| 11 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 12 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 13 | import org.springframework.web.bind.annotation.GetMapping; | |
| 14 | import org.springframework.web.bind.annotation.PostMapping; | |
| 15 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 16 | import org.springframework.web.bind.annotation.RequestParam; | |
| 17 | import org.springframework.web.bind.annotation.RestController; | |
| 18 | ||
| 19 | @Tag(name = "Researchers") | |
| 20 | @RequestMapping("/api/admin/researchers") | |
| 21 | @RestController | |
| 22 | @Slf4j | |
| 23 | public class ResearchersController extends ApiController { | |
| 24 | ||
| 25 | @Autowired ResearcherRepository researcherRepository; | |
| 26 | ||
| 27 | @Operation(summary = "Create a new Researcher") | |
| 28 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 29 | @PostMapping("/post") | |
| 30 | public Researcher postResearcher(@RequestParam String email) { | |
| 31 | String convertedEmail = CanonicalFormConverter.convertToValidEmail(email).strip(); | |
| 32 | Researcher researcher = Researcher.builder().email(convertedEmail).build(); | |
| 33 | researcherRepository.save(researcher); | |
| 34 |
1
1. postResearcher : replaced return value with null for edu/ucsb/cs/citelines/controller/ResearchersController::postResearcher → KILLED |
return researcher; |
| 35 | } | |
| 36 | ||
| 37 | @Operation(summary = "List all Researchers") | |
| 38 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 39 | @GetMapping("/get") | |
| 40 | public Iterable<Researcher> allResearchers() { | |
| 41 |
1
1. allResearchers : replaced return value with Collections.emptyList for edu/ucsb/cs/citelines/controller/ResearchersController::allResearchers → KILLED |
return researcherRepository.findAll(); |
| 42 | } | |
| 43 | ||
| 44 | @Operation(summary = "Delete a Researcher by email") | |
| 45 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 46 | @DeleteMapping("/delete") | |
| 47 | public ResponseEntity<String> deleteResearcher(@RequestParam String email) { | |
| 48 | Researcher researcher = researcherRepository.findById(email).orElse(null); | |
| 49 |
1
1. deleteResearcher : negated conditional → KILLED |
if (researcher == null) { |
| 50 |
1
1. deleteResearcher : replaced return value with null for edu/ucsb/cs/citelines/controller/ResearchersController::deleteResearcher → KILLED |
return ResponseEntity.status(404) |
| 51 | .body(String.format("Researcher with email %s not found.", email)); | |
| 52 | } | |
| 53 |
1
1. deleteResearcher : removed call to edu/ucsb/cs/citelines/repository/ResearcherRepository::delete → KILLED |
researcherRepository.delete(researcher); |
| 54 |
1
1. deleteResearcher : replaced return value with null for edu/ucsb/cs/citelines/controller/ResearchersController::deleteResearcher → KILLED |
return ResponseEntity.status(200) |
| 55 | .body(String.format("Researcher with email %s deleted.", email)); | |
| 56 | } | |
| 57 | } | |
Mutations | ||
| 34 |
1.1 |
|
| 41 |
1.1 |
|
| 49 |
1.1 |
|
| 50 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |