| 1 | package edu.ucsb.cs156.frontiers.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | import edu.ucsb.cs156.frontiers.entities.Course; | |
| 5 | import edu.ucsb.cs156.frontiers.entities.Job; | |
| 6 | import edu.ucsb.cs156.frontiers.entities.RosterStudent; | |
| 7 | import edu.ucsb.cs156.frontiers.entities.User; | |
| 8 | import edu.ucsb.cs156.frontiers.enums.InsertStatus; | |
| 9 | import edu.ucsb.cs156.frontiers.enums.OrgStatus; | |
| 10 | import edu.ucsb.cs156.frontiers.enums.RosterStatus; | |
| 11 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
| 12 | import edu.ucsb.cs156.frontiers.errors.NoLinkedOrganizationException; | |
| 13 | import edu.ucsb.cs156.frontiers.jobs.UpdateOrgMembershipJob; | |
| 14 | import edu.ucsb.cs156.frontiers.models.RosterStudentDTO; | |
| 15 | import edu.ucsb.cs156.frontiers.models.UpsertResponse; | |
| 16 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 17 | import edu.ucsb.cs156.frontiers.repositories.RosterStudentRepository; | |
| 18 | import edu.ucsb.cs156.frontiers.services.CurrentUserService; | |
| 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 edu.ucsb.cs156.frontiers.utilities.CanonicalFormConverter; | |
| 23 | import io.swagger.v3.oas.annotations.Operation; | |
| 24 | import io.swagger.v3.oas.annotations.Parameter; | |
| 25 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 26 | import java.security.NoSuchAlgorithmException; | |
| 27 | import java.security.spec.InvalidKeySpecException; | |
| 28 | import java.util.Optional; | |
| 29 | import lombok.extern.slf4j.Slf4j; | |
| 30 | import org.springframework.beans.factory.annotation.Autowired; | |
| 31 | import org.springframework.http.HttpStatus; | |
| 32 | import org.springframework.http.ResponseEntity; | |
| 33 | import org.springframework.security.access.AccessDeniedException; | |
| 34 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 35 | import org.springframework.transaction.annotation.Transactional; | |
| 36 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 37 | import org.springframework.web.bind.annotation.GetMapping; | |
| 38 | import org.springframework.web.bind.annotation.PathVariable; | |
| 39 | import org.springframework.web.bind.annotation.PostMapping; | |
| 40 | import org.springframework.web.bind.annotation.PutMapping; | |
| 41 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 42 | import org.springframework.web.bind.annotation.RequestParam; | |
| 43 | import org.springframework.web.bind.annotation.RestController; | |
| 44 | import org.springframework.web.server.ResponseStatusException; | |
| 45 | ||
| 46 | @Tag(name = "RosterStudents") | |
| 47 | @RequestMapping("/api/rosterstudents") | |
| 48 | @RestController | |
| 49 | @Slf4j | |
| 50 | public class RosterStudentsController extends ApiController { | |
| 51 | ||
| 52 | @Autowired private JobService jobService; | |
| 53 | @Autowired private OrganizationMemberService organizationMemberService; | |
| 54 | ||
| 55 | @Autowired private RosterStudentRepository rosterStudentRepository; | |
| 56 | ||
| 57 | @Autowired private CourseRepository courseRepository; | |
| 58 | ||
| 59 | @Autowired private UpdateUserService updateUserService; | |
| 60 | ||
| 61 | @Autowired private CurrentUserService currentUserService; | |
| 62 | ||
| 63 | /** | |
| 64 | * This method creates a new RosterStudent. It is important to keep the code in this method | |
| 65 | * consistent with the code for adding multiple roster students from a CSV | |
| 66 | * | |
| 67 | * @return the created RosterStudent | |
| 68 | */ | |
| 69 | @Operation(summary = "Create a new roster student") | |
| 70 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 71 | @PostMapping("/post") | |
| 72 | public ResponseEntity<UpsertResponse> postRosterStudent( | |
| 73 | @Parameter(name = "studentId") @RequestParam String studentId, | |
| 74 | @Parameter(name = "firstName") @RequestParam String firstName, | |
| 75 | @Parameter(name = "lastName") @RequestParam String lastName, | |
| 76 | @Parameter(name = "email") @RequestParam String email, | |
| 77 | @Parameter(name = "courseId") @RequestParam Long courseId, | |
| 78 | @Parameter(name = "section") @RequestParam(required = false) String section) | |
| 79 | throws EntityNotFoundException { | |
| 80 | ||
| 81 | // Get Course or else throw an error | |
| 82 | ||
| 83 | Course course = | |
| 84 | courseRepository | |
| 85 | .findById(courseId) | |
| 86 |
1
1. lambda$postRosterStudent$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$postRosterStudent$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 87 | ||
| 88 | RosterStudent rosterStudent = | |
| 89 | RosterStudent.builder() | |
| 90 | .studentId(studentId) | |
| 91 | .firstName(firstName) | |
| 92 | .lastName(lastName) | |
| 93 | .email(email.strip()) | |
| 94 | .build(); | |
| 95 | ||
| 96 |
1
1. postRosterStudent : negated conditional → KILLED |
if (section != null) { |
| 97 |
1
1. postRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setSection → KILLED |
rosterStudent.setSection(section); |
| 98 | } | |
| 99 | ||
| 100 | UpsertResponse upsertResponse = upsertStudent(rosterStudent, course, RosterStatus.MANUAL); | |
| 101 |
1
1. postRosterStudent : negated conditional → KILLED |
if (upsertResponse.getInsertStatus() == InsertStatus.REJECTED) { |
| 102 |
1
1. postRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::postRosterStudent → KILLED |
return ResponseEntity.status(HttpStatus.CONFLICT).body(upsertResponse); |
| 103 | } else { | |
| 104 | rosterStudent = rosterStudentRepository.save(upsertResponse.rosterStudent()); | |
| 105 |
1
1. postRosterStudent : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachUserToRosterStudent → KILLED |
updateUserService.attachUserToRosterStudent(rosterStudent); |
| 106 |
1
1. postRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::postRosterStudent → KILLED |
return ResponseEntity.ok(upsertResponse); |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 110 | /** | |
| 111 | * This method returns a list of roster students for a given course. | |
| 112 | * | |
| 113 | * @return a list of all courses. | |
| 114 | */ | |
| 115 | @Operation(summary = "List all roster students for a course") | |
| 116 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 117 | @GetMapping("/course/{courseId}") | |
| 118 | public Iterable<RosterStudentDTO> rosterStudentForCourse( | |
| 119 | @Parameter(name = "courseId") @PathVariable Long courseId) throws EntityNotFoundException { | |
| 120 | courseRepository | |
| 121 | .findById(courseId) | |
| 122 |
1
1. lambda$rosterStudentForCourse$1 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$rosterStudentForCourse$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 123 | Iterable<RosterStudent> rosterStudents = rosterStudentRepository.findByCourseId(courseId); | |
| 124 | Iterable<RosterStudentDTO> rosterStudentDTOs = | |
| 125 | () -> | |
| 126 |
1
1. lambda$rosterStudentForCourse$2 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$rosterStudentForCourse$2 → KILLED |
java.util.stream.StreamSupport.stream(rosterStudents.spliterator(), false) |
| 127 | .sorted( | |
| 128 | java.util.Comparator.comparing(RosterStudent::getLastName) | |
| 129 | .thenComparing(RosterStudent::getFirstName)) | |
| 130 | .map(RosterStudentDTO::new) | |
| 131 | .iterator(); | |
| 132 |
1
1. rosterStudentForCourse : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::rosterStudentForCourse → KILLED |
return rosterStudentDTOs; |
| 133 | } | |
| 134 | ||
| 135 | public static UpsertResponse upsertStudent( | |
| 136 | RosterStudent student, Course course, RosterStatus rosterStatus) { | |
| 137 | String convertedEmail = CanonicalFormConverter.convertToValidEmail(student.getEmail().strip()); | |
| 138 | Optional<RosterStudent> existingStudent = | |
| 139 | course.getRosterStudents().stream() | |
| 140 | .filter( | |
| 141 |
2
1. lambda$upsertStudent$3 : replaced boolean return with true for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$upsertStudent$3 → KILLED 2. lambda$upsertStudent$3 : replaced boolean return with false for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$upsertStudent$3 → KILLED |
filteringStudent -> student.getStudentId().equals(filteringStudent.getStudentId())) |
| 142 | .findFirst(); | |
| 143 | Optional<RosterStudent> existingStudentByEmail = | |
| 144 | course.getRosterStudents().stream() | |
| 145 |
2
1. lambda$upsertStudent$4 : replaced boolean return with false for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$upsertStudent$4 → KILLED 2. lambda$upsertStudent$4 : replaced boolean return with true for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$upsertStudent$4 → KILLED |
.filter(filteringStudent -> convertedEmail.equals(filteringStudent.getEmail())) |
| 146 | .findFirst(); | |
| 147 |
2
1. upsertStudent : negated conditional → KILLED 2. upsertStudent : negated conditional → KILLED |
if (existingStudent.isPresent() && existingStudentByEmail.isPresent()) { |
| 148 |
1
1. upsertStudent : negated conditional → KILLED |
if (existingStudent.get().getId().equals(existingStudentByEmail.get().getId())) { |
| 149 | RosterStudent existingStudentObj = existingStudent.get(); | |
| 150 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
existingStudentObj.setRosterStatus(rosterStatus); |
| 151 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setFirstName → KILLED |
existingStudentObj.setFirstName(student.getFirstName()); |
| 152 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setLastName → KILLED |
existingStudentObj.setLastName(student.getLastName()); |
| 153 |
1
1. upsertStudent : negated conditional → KILLED |
if (student.getSection() != null) { |
| 154 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setSection → KILLED |
existingStudentObj.setSection(student.getSection()); |
| 155 | } | |
| 156 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.UPDATED, existingStudentObj); |
| 157 | } else { | |
| 158 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.REJECTED, student); |
| 159 | } | |
| 160 |
2
1. upsertStudent : negated conditional → KILLED 2. upsertStudent : negated conditional → KILLED |
} else if (existingStudent.isPresent() || existingStudentByEmail.isPresent()) { |
| 161 | RosterStudent existingStudentObj = | |
| 162 |
1
1. upsertStudent : negated conditional → KILLED |
existingStudent.isPresent() ? existingStudent.get() : existingStudentByEmail.get(); |
| 163 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
existingStudentObj.setRosterStatus(rosterStatus); |
| 164 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setFirstName → KILLED |
existingStudentObj.setFirstName(student.getFirstName()); |
| 165 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setLastName → KILLED |
existingStudentObj.setLastName(student.getLastName()); |
| 166 |
1
1. upsertStudent : negated conditional → KILLED |
if (student.getSection() != null) { |
| 167 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setSection → KILLED |
existingStudentObj.setSection(student.getSection()); |
| 168 | } | |
| 169 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setEmail → KILLED |
existingStudentObj.setEmail(convertedEmail.strip()); |
| 170 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setStudentId → KILLED |
existingStudentObj.setStudentId(student.getStudentId()); |
| 171 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.UPDATED, existingStudentObj); |
| 172 | } else { | |
| 173 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setCourse → KILLED |
student.setCourse(course); |
| 174 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setEmail → KILLED |
student.setEmail(convertedEmail.strip()); |
| 175 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
student.setRosterStatus(rosterStatus); |
| 176 | // if an installationID exists, orgStatus should be set to JOINCOURSE. if it | |
| 177 | // doesn't exist | |
| 178 | // (null), set orgStatus to PENDING. | |
| 179 |
1
1. upsertStudent : negated conditional → KILLED |
if (course.getInstallationId() != null) { |
| 180 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
student.setOrgStatus(OrgStatus.JOINCOURSE); |
| 181 | } else { | |
| 182 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
student.setOrgStatus(OrgStatus.PENDING); |
| 183 | } | |
| 184 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.INSERTED, student); |
| 185 | } | |
| 186 | } | |
| 187 | ||
| 188 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 189 | @PostMapping("/updateCourseMembership") | |
| 190 | public Job updateCourseMembership( | |
| 191 | @Parameter(name = "courseId", description = "Course ID") @RequestParam Long courseId) | |
| 192 | throws NoSuchAlgorithmException, InvalidKeySpecException, JsonProcessingException { | |
| 193 | Course course = | |
| 194 | courseRepository | |
| 195 | .findById(courseId) | |
| 196 |
1
1. lambda$updateCourseMembership$5 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$updateCourseMembership$5 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 197 |
2
1. updateCourseMembership : negated conditional → KILLED 2. updateCourseMembership : negated conditional → KILLED |
if (course.getInstallationId() == null || course.getOrgName() == null) { |
| 198 | throw new NoLinkedOrganizationException(course.getCourseName()); | |
| 199 | } else { | |
| 200 | UpdateOrgMembershipJob job = | |
| 201 | UpdateOrgMembershipJob.builder() | |
| 202 | .rosterStudentRepository(rosterStudentRepository) | |
| 203 | .organizationMemberService(organizationMemberService) | |
| 204 | .course(course) | |
| 205 | .build(); | |
| 206 | ||
| 207 |
1
1. updateCourseMembership : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::updateCourseMembership → KILLED |
return jobService.runAsJob(job); |
| 208 | } | |
| 209 | } | |
| 210 | ||
| 211 | @Operation( | |
| 212 | summary = | |
| 213 | "Allow roster student to join a course by generating an invitation to the linked Github Org") | |
| 214 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 215 | @PutMapping("/joinCourse") | |
| 216 | public ResponseEntity<String> joinCourseOnGitHub( | |
| 217 | @Parameter( | |
| 218 | name = "rosterStudentId", | |
| 219 | description = "Roster Student joining a course on GitHub") | |
| 220 | @RequestParam | |
| 221 | Long rosterStudentId) | |
| 222 | throws NoSuchAlgorithmException, InvalidKeySpecException, JsonProcessingException { | |
| 223 | ||
| 224 | User currentUser = currentUserService.getUser(); | |
| 225 | RosterStudent rosterStudent = | |
| 226 | rosterStudentRepository | |
| 227 | .findById(rosterStudentId) | |
| 228 |
1
1. lambda$joinCourseOnGitHub$6 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$joinCourseOnGitHub$6 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RosterStudent.class, rosterStudentId)); |
| 229 | ||
| 230 |
2
1. joinCourseOnGitHub : negated conditional → KILLED 2. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getUser() == null || currentUser.getId() != rosterStudent.getUser().getId()) { |
| 231 | throw new AccessDeniedException("User not authorized join the course as this roster student"); | |
| 232 | } | |
| 233 | ||
| 234 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getRosterStatus() == RosterStatus.DROPPED) { |
| 235 | throw new AccessDeniedException( | |
| 236 | "You have dropped this course. Please contact your instructor."); | |
| 237 | } | |
| 238 | ||
| 239 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getGithubId() != null |
| 240 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
&& rosterStudent.getGithubLogin() != null |
| 241 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
&& (rosterStudent.getOrgStatus() == OrgStatus.MEMBER |
| 242 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
|| rosterStudent.getOrgStatus() == OrgStatus.OWNER)) { |
| 243 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.badRequest() |
| 244 | .body("This user has already linked a Github account to this course."); | |
| 245 | } | |
| 246 | ||
| 247 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getCourse().getOrgName() == null |
| 248 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
|| rosterStudent.getCourse().getInstallationId() == null) { |
| 249 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.badRequest() |
| 250 | .body("Course has not been set up. Please ask your instructor for help."); | |
| 251 | } | |
| 252 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubId → KILLED |
rosterStudent.setGithubId(currentUser.getGithubId()); |
| 253 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubLogin → KILLED |
rosterStudent.setGithubLogin(currentUser.getGithubLogin()); |
| 254 | OrgStatus status = organizationMemberService.inviteOrganizationMember(rosterStudent); | |
| 255 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
rosterStudent.setOrgStatus(status); |
| 256 | rosterStudentRepository.save(rosterStudent); | |
| 257 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (status == OrgStatus.INVITED) { |
| 258 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.accepted().body("Successfully invited student to Organization"); |
| 259 |
2
1. joinCourseOnGitHub : negated conditional → KILLED 2. joinCourseOnGitHub : negated conditional → KILLED |
} else if (status == OrgStatus.MEMBER || status == OrgStatus.OWNER) { |
| 260 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.accepted() |
| 261 | .body("Already in organization - set status to %s".formatted(status.toString())); | |
| 262 | } else { | |
| 263 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.internalServerError().body("Could not invite student to Organization"); |
| 264 | } | |
| 265 | } | |
| 266 | ||
| 267 | @Operation(summary = "Get Associated Roster Students with a User") | |
| 268 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 269 | @GetMapping("/associatedRosterStudents") | |
| 270 | public Iterable<RosterStudent> getAssociatedRosterStudents() { | |
| 271 | User currentUser = currentUserService.getUser(); | |
| 272 | Iterable<RosterStudent> rosterStudents = rosterStudentRepository.findAllByUser((currentUser)); | |
| 273 |
1
1. getAssociatedRosterStudents : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::getAssociatedRosterStudents → KILLED |
return rosterStudents; |
| 274 | } | |
| 275 | ||
| 276 | @Operation(summary = "Update a roster student") | |
| 277 | @PreAuthorize("@CourseSecurity.hasRosterStudentManagementPermissions(#root, #id)") | |
| 278 | @PutMapping("/update") | |
| 279 | public RosterStudent updateRosterStudent( | |
| 280 | @Parameter(name = "id") @RequestParam Long id, | |
| 281 | @Parameter(name = "firstName") @RequestParam(required = false) String firstName, | |
| 282 | @Parameter(name = "lastName") @RequestParam(required = false) String lastName, | |
| 283 | @Parameter(name = "studentId") @RequestParam(required = false) String studentId, | |
| 284 | @Parameter(name = "section") @RequestParam(required = false) String section) | |
| 285 | throws EntityNotFoundException { | |
| 286 | ||
| 287 |
3
1. updateRosterStudent : negated conditional → KILLED 2. updateRosterStudent : negated conditional → KILLED 3. updateRosterStudent : negated conditional → KILLED |
if (firstName == null |
| 288 | || lastName == null | |
| 289 | || studentId == null | |
| 290 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| firstName.trim().isEmpty() |
| 291 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| lastName.trim().isEmpty() |
| 292 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| studentId.trim().isEmpty()) { |
| 293 | throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Required fields cannot be empty"); | |
| 294 | } | |
| 295 | ||
| 296 | RosterStudent rosterStudent = | |
| 297 | rosterStudentRepository | |
| 298 | .findById(id) | |
| 299 |
1
1. lambda$updateRosterStudent$7 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$updateRosterStudent$7 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RosterStudent.class, id)); |
| 300 | ||
| 301 |
1
1. updateRosterStudent : negated conditional → KILLED |
if (!rosterStudent.getStudentId().trim().equals(studentId.trim())) { |
| 302 | Optional<RosterStudent> existingStudent = | |
| 303 | rosterStudentRepository.findByCourseIdAndStudentId( | |
| 304 | rosterStudent.getCourse().getId(), studentId.trim()); | |
| 305 |
1
1. updateRosterStudent : negated conditional → KILLED |
if (existingStudent.isPresent()) { |
| 306 | throw new ResponseStatusException( | |
| 307 | HttpStatus.BAD_REQUEST, "Student ID already exists in this course"); | |
| 308 | } | |
| 309 | } | |
| 310 | ||
| 311 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setFirstName → KILLED |
rosterStudent.setFirstName(firstName.trim()); |
| 312 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setLastName → KILLED |
rosterStudent.setLastName(lastName.trim()); |
| 313 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setStudentId → KILLED |
rosterStudent.setStudentId(studentId.trim()); |
| 314 | ||
| 315 |
1
1. updateRosterStudent : negated conditional → KILLED |
if (section != null) { |
| 316 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setSection → KILLED |
rosterStudent.setSection(section); |
| 317 | } | |
| 318 | ||
| 319 |
1
1. updateRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::updateRosterStudent → KILLED |
return rosterStudentRepository.save(rosterStudent); |
| 320 | } | |
| 321 | ||
| 322 | @Operation( | |
| 323 | summary = "Restore a roster student", | |
| 324 | description = "Makes a student who previously dropped the course able to join and interact") | |
| 325 | @PreAuthorize("@CourseSecurity.hasRosterStudentManagementPermissions(#root, #id)") | |
| 326 | @PutMapping("/restore") | |
| 327 | public RosterStudent restoreRosterStudent(@Parameter(name = "id") @RequestParam Long id) | |
| 328 | throws EntityNotFoundException { | |
| 329 | RosterStudent rosterStudent = | |
| 330 | rosterStudentRepository | |
| 331 | .findById(id) | |
| 332 |
1
1. lambda$restoreRosterStudent$8 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$restoreRosterStudent$8 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RosterStudent.class, id)); |
| 333 |
1
1. restoreRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
rosterStudent.setRosterStatus(RosterStatus.MANUAL); |
| 334 |
1
1. restoreRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::restoreRosterStudent → KILLED |
return rosterStudentRepository.save(rosterStudent); |
| 335 | } | |
| 336 | ||
| 337 | @Operation(summary = "Delete a roster student") | |
| 338 | @PreAuthorize("@CourseSecurity.hasRosterStudentManagementPermissions(#root, #id)") | |
| 339 | @DeleteMapping("/delete") | |
| 340 | @Transactional | |
| 341 | public ResponseEntity<String> deleteRosterStudent( | |
| 342 | @Parameter(name = "id") @RequestParam Long id, | |
| 343 | @Parameter( | |
| 344 | name = "removeFromOrg", | |
| 345 | description = "Whether to remove student from GitHub organization") | |
| 346 | @RequestParam(defaultValue = "true") | |
| 347 | boolean removeFromOrg) | |
| 348 | throws EntityNotFoundException { | |
| 349 | RosterStudent rosterStudent = | |
| 350 | rosterStudentRepository | |
| 351 | .findById(id) | |
| 352 |
1
1. lambda$deleteRosterStudent$9 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$deleteRosterStudent$9 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RosterStudent.class, id)); |
| 353 | Course course = rosterStudent.getCourse(); | |
| 354 | ||
| 355 | boolean orgRemovalAttempted = false; | |
| 356 | boolean orgRemovalSuccessful = false; | |
| 357 | String orgRemovalErrorMessage = null; | |
| 358 | ||
| 359 | // Try to remove the student from the organization if they have a GitHub login | |
| 360 | // and removeFromOrg parameter is true | |
| 361 |
1
1. deleteRosterStudent : negated conditional → KILLED |
if (removeFromOrg |
| 362 |
1
1. deleteRosterStudent : negated conditional → KILLED |
&& rosterStudent.getGithubLogin() != null |
| 363 |
1
1. deleteRosterStudent : negated conditional → KILLED |
&& course.getOrgName() != null |
| 364 |
1
1. deleteRosterStudent : negated conditional → KILLED |
&& course.getInstallationId() != null) { |
| 365 | orgRemovalAttempted = true; | |
| 366 | try { | |
| 367 |
1
1. deleteRosterStudent : removed call to edu/ucsb/cs156/frontiers/services/OrganizationMemberService::removeOrganizationMember → KILLED |
organizationMemberService.removeOrganizationMember(rosterStudent); |
| 368 | orgRemovalSuccessful = true; | |
| 369 | } catch (Exception e) { | |
| 370 | log.error("Error removing student from organization: {}", e.getMessage()); | |
| 371 | orgRemovalErrorMessage = e.getMessage(); | |
| 372 | // Continue with deletion even if organization removal fails | |
| 373 | } | |
| 374 | } | |
| 375 | ||
| 376 |
1
1. deleteRosterStudent : negated conditional → KILLED |
if (!rosterStudent.getTeamMembers().isEmpty()) { |
| 377 | rosterStudent | |
| 378 | .getTeamMembers() | |
| 379 |
1
1. deleteRosterStudent : removed call to java/util/List::forEach → KILLED |
.forEach( |
| 380 | teamMember -> { | |
| 381 | teamMember.getTeam().getTeamMembers().remove(teamMember); | |
| 382 |
1
1. lambda$deleteRosterStudent$10 : removed call to edu/ucsb/cs156/frontiers/entities/TeamMember::setTeam → KILLED |
teamMember.setTeam(null); |
| 383 | }); | |
| 384 | } | |
| 385 | ||
| 386 | rosterStudent.getCourse().getRosterStudents().remove(rosterStudent); | |
| 387 |
1
1. deleteRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setCourse → KILLED |
rosterStudent.setCourse(null); |
| 388 |
1
1. deleteRosterStudent : removed call to edu/ucsb/cs156/frontiers/repositories/RosterStudentRepository::delete → KILLED |
rosterStudentRepository.delete(rosterStudent); |
| 389 | ||
| 390 |
1
1. deleteRosterStudent : negated conditional → KILLED |
if (!orgRemovalAttempted) { |
| 391 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
| 392 | "Successfully deleted roster student and removed him/her from the course list"); | |
| 393 |
1
1. deleteRosterStudent : negated conditional → KILLED |
} else if (orgRemovalSuccessful) { |
| 394 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
| 395 | "Successfully deleted roster student and removed him/her from the course list and organization"); | |
| 396 | } else { | |
| 397 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
| 398 | "Successfully deleted roster student but there was an error removing them from the course organization: " | |
| 399 | + orgRemovalErrorMessage); | |
| 400 | } | |
| 401 | } | |
| 402 | } | |
Mutations | ||
| 86 |
1.1 |
|
| 96 |
1.1 |
|
| 97 |
1.1 |
|
| 101 |
1.1 |
|
| 102 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 122 |
1.1 |
|
| 126 |
1.1 |
|
| 132 |
1.1 |
|
| 141 |
1.1 2.2 |
|
| 145 |
1.1 2.2 |
|
| 147 |
1.1 2.2 |
|
| 148 |
1.1 |
|
| 150 |
1.1 |
|
| 151 |
1.1 |
|
| 152 |
1.1 |
|
| 153 |
1.1 |
|
| 154 |
1.1 |
|
| 156 |
1.1 |
|
| 158 |
1.1 |
|
| 160 |
1.1 2.2 |
|
| 162 |
1.1 |
|
| 163 |
1.1 |
|
| 164 |
1.1 |
|
| 165 |
1.1 |
|
| 166 |
1.1 |
|
| 167 |
1.1 |
|
| 169 |
1.1 |
|
| 170 |
1.1 |
|
| 171 |
1.1 |
|
| 173 |
1.1 |
|
| 174 |
1.1 |
|
| 175 |
1.1 |
|
| 179 |
1.1 |
|
| 180 |
1.1 |
|
| 182 |
1.1 |
|
| 184 |
1.1 |
|
| 196 |
1.1 |
|
| 197 |
1.1 2.2 |
|
| 207 |
1.1 |
|
| 228 |
1.1 |
|
| 230 |
1.1 2.2 |
|
| 234 |
1.1 |
|
| 239 |
1.1 |
|
| 240 |
1.1 |
|
| 241 |
1.1 |
|
| 242 |
1.1 |
|
| 243 |
1.1 |
|
| 247 |
1.1 |
|
| 248 |
1.1 |
|
| 249 |
1.1 |
|
| 252 |
1.1 |
|
| 253 |
1.1 |
|
| 255 |
1.1 |
|
| 257 |
1.1 |
|
| 258 |
1.1 |
|
| 259 |
1.1 2.2 |
|
| 260 |
1.1 |
|
| 263 |
1.1 |
|
| 273 |
1.1 |
|
| 287 |
1.1 2.2 3.3 |
|
| 290 |
1.1 |
|
| 291 |
1.1 |
|
| 292 |
1.1 |
|
| 299 |
1.1 |
|
| 301 |
1.1 |
|
| 305 |
1.1 |
|
| 311 |
1.1 |
|
| 312 |
1.1 |
|
| 313 |
1.1 |
|
| 315 |
1.1 |
|
| 316 |
1.1 |
|
| 319 |
1.1 |
|
| 332 |
1.1 |
|
| 333 |
1.1 |
|
| 334 |
1.1 |
|
| 352 |
1.1 |
|
| 361 |
1.1 |
|
| 362 |
1.1 |
|
| 363 |
1.1 |
|
| 364 |
1.1 |
|
| 367 |
1.1 |
|
| 376 |
1.1 |
|
| 379 |
1.1 |
|
| 382 |
1.1 |
|
| 387 |
1.1 |
|
| 388 |
1.1 |
|
| 390 |
1.1 |
|
| 391 |
1.1 |
|
| 393 |
1.1 |
|
| 394 |
1.1 |
|
| 397 |
1.1 |