| 1 | package edu.ucsb.cs.citelines.controller; | |
| 2 | ||
| 3 | import edu.ucsb.cs.citelines.entity.Project; | |
| 4 | import edu.ucsb.cs.citelines.entity.ProjectCollaborator; | |
| 5 | import edu.ucsb.cs.citelines.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs.citelines.repository.ProjectCollaboratorRepository; | |
| 7 | import edu.ucsb.cs.citelines.repository.ProjectRepository; | |
| 8 | import io.swagger.v3.oas.annotations.Operation; | |
| 9 | import io.swagger.v3.oas.annotations.Parameter; | |
| 10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 11 | import lombok.extern.slf4j.Slf4j; | |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | import org.springframework.http.ResponseEntity; | |
| 14 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | import org.springframework.transaction.annotation.Transactional; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 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 = "ProjectCollaborators") | |
| 24 | @RequestMapping("/api/projectcollaborators") | |
| 25 | @RestController | |
| 26 | @Slf4j | |
| 27 | public class ProjectCollaboratorsController extends ApiController { | |
| 28 | ||
| 29 | @Autowired private ProjectCollaboratorRepository projectCollaboratorRepository; | |
| 30 | ||
| 31 | @Autowired private ProjectRepository projectRepository; | |
| 32 | ||
| 33 | /** | |
| 34 | * This method adds a new collaborator to a project. | |
| 35 | * | |
| 36 | * @return the created ProjectCollaborator | |
| 37 | */ | |
| 38 | @Operation(summary = "Add a collaborator to a project") | |
| 39 | @PreAuthorize("@ProjectSecurity.hasOwnerPermissions(#root, #projectId)") | |
| 40 | @PostMapping("/post") | |
| 41 | public ProjectCollaborator postProjectCollaborator( | |
| 42 | @Parameter(name = "firstName") @RequestParam String firstName, | |
| 43 | @Parameter(name = "lastName") @RequestParam String lastName, | |
| 44 | @Parameter(name = "email") @RequestParam String email, | |
| 45 | @Parameter(name = "projectId") @RequestParam Long projectId) | |
| 46 | throws EntityNotFoundException { | |
| 47 | ||
| 48 | Project project = | |
| 49 | projectRepository | |
| 50 | .findById(projectId) | |
| 51 |
1
1. lambda$postProjectCollaborator$0 : replaced return value with null for edu/ucsb/cs/citelines/controller/ProjectCollaboratorsController::lambda$postProjectCollaborator$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Project.class, projectId)); |
| 52 | ||
| 53 | ProjectCollaborator collaborator = | |
| 54 | ProjectCollaborator.builder() | |
| 55 | .firstName(firstName) | |
| 56 | .lastName(lastName) | |
| 57 | .email(email.strip()) | |
| 58 | .project(project) | |
| 59 | .build(); | |
| 60 | ||
| 61 |
1
1. postProjectCollaborator : replaced return value with null for edu/ucsb/cs/citelines/controller/ProjectCollaboratorsController::postProjectCollaborator → KILLED |
return projectCollaboratorRepository.save(collaborator); |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * This method returns a list of collaborators for a given project. | |
| 66 | * | |
| 67 | * @return a list of collaborators for a project. | |
| 68 | */ | |
| 69 | @Operation(summary = "List all collaborators for a project") | |
| 70 | @PreAuthorize("@ProjectSecurity.hasManagePermissions(#root, #projectId)") | |
| 71 | @GetMapping("/project") | |
| 72 | public Iterable<ProjectCollaborator> collaboratorsForProject( | |
| 73 | @Parameter(name = "projectId") @RequestParam Long projectId) throws EntityNotFoundException { | |
| 74 | projectRepository | |
| 75 | .findById(projectId) | |
| 76 |
1
1. lambda$collaboratorsForProject$1 : replaced return value with null for edu/ucsb/cs/citelines/controller/ProjectCollaboratorsController::lambda$collaboratorsForProject$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Project.class, projectId)); |
| 77 |
1
1. collaboratorsForProject : replaced return value with Collections.emptyList for edu/ucsb/cs/citelines/controller/ProjectCollaboratorsController::collaboratorsForProject → KILLED |
return projectCollaboratorRepository.findByProjectId(projectId); |
| 78 | } | |
| 79 | ||
| 80 | @Operation(summary = "Delete a collaborator") | |
| 81 | @PreAuthorize("@ProjectSecurity.hasOwnerPermissions(#root, #projectId)") | |
| 82 | @DeleteMapping("/delete") | |
| 83 | @Transactional | |
| 84 | public ResponseEntity<String> deleteProjectCollaborator( | |
| 85 | @Parameter(name = "id") @RequestParam Long id, | |
| 86 | @Parameter(name = "projectId") @RequestParam Long projectId) | |
| 87 | throws EntityNotFoundException { | |
| 88 | ProjectCollaborator collaborator = | |
| 89 | projectCollaboratorRepository | |
| 90 | .findById(id) | |
| 91 |
1
1. lambda$deleteProjectCollaborator$2 : replaced return value with null for edu/ucsb/cs/citelines/controller/ProjectCollaboratorsController::lambda$deleteProjectCollaborator$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(ProjectCollaborator.class, id)); |
| 92 | ||
| 93 |
1
1. deleteProjectCollaborator : removed call to edu/ucsb/cs/citelines/repository/ProjectCollaboratorRepository::delete → KILLED |
projectCollaboratorRepository.delete(collaborator); |
| 94 | ||
| 95 |
1
1. deleteProjectCollaborator : replaced return value with null for edu/ucsb/cs/citelines/controller/ProjectCollaboratorsController::deleteProjectCollaborator → KILLED |
return ResponseEntity.ok("Successfully deleted collaborator."); |
| 96 | } | |
| 97 | } | |
Mutations | ||
| 51 |
1.1 |
|
| 61 |
1.1 |
|
| 76 |
1.1 |
|
| 77 |
1.1 |
|
| 91 |
1.1 |
|
| 93 |
1.1 |
|
| 95 |
1.1 |