| 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 = "section") @RequestParam(required = false) String section, | |
| 78 | @Parameter(name = "courseId") @RequestParam Long courseId) | |
| 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) | |
| 94 |
1
1. postRosterStudent : negated conditional → KILLED |
.section(section != null ? section : "") |
| 95 | .build(); | |
| 96 | ||
| 97 | UpsertResponse upsertResponse = upsertStudent(rosterStudent, course, RosterStatus.MANUAL); | |
| 98 |
1
1. postRosterStudent : negated conditional → KILLED |
if (upsertResponse.getInsertStatus() == InsertStatus.REJECTED) { |
| 99 |
1
1. postRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::postRosterStudent → KILLED |
return ResponseEntity.status(HttpStatus.CONFLICT).body(upsertResponse); |
| 100 | } else { | |
| 101 | rosterStudent = rosterStudentRepository.save(upsertResponse.rosterStudent()); | |
| 102 |
1
1. postRosterStudent : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachUserToRosterStudent → KILLED |
updateUserService.attachUserToRosterStudent(rosterStudent); |
| 103 |
1
1. postRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::postRosterStudent → KILLED |
return ResponseEntity.ok(upsertResponse); |
| 104 | } | |
| 105 | } | |
| 106 | ||
| 107 | /** | |
| 108 | * This method returns a list of roster students for a given course. | |
| 109 | * | |
| 110 | * @return a list of all courses. | |
| 111 | */ | |
| 112 | @Operation(summary = "List all roster students for a course") | |
| 113 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 114 | @GetMapping("/course/{courseId}") | |
| 115 | public Iterable<RosterStudentDTO> rosterStudentForCourse( | |
| 116 | @Parameter(name = "courseId") @PathVariable Long courseId) throws EntityNotFoundException { | |
| 117 | courseRepository | |
| 118 | .findById(courseId) | |
| 119 |
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)); |
| 120 | Iterable<RosterStudent> rosterStudents = rosterStudentRepository.findByCourseId(courseId); | |
| 121 | Iterable<RosterStudentDTO> rosterStudentDTOs = | |
| 122 | () -> | |
| 123 |
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) |
| 124 | .map(RosterStudentDTO::new) | |
| 125 | .sorted( | |
| 126 | java.util.Comparator.comparing(RosterStudentDTO::lastName) | |
| 127 | .thenComparing(RosterStudentDTO::firstName)) | |
| 128 | .iterator(); | |
| 129 |
1
1. rosterStudentForCourse : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::rosterStudentForCourse → KILLED |
return rosterStudentDTOs; |
| 130 | } | |
| 131 | ||
| 132 | public static UpsertResponse upsertStudent( | |
| 133 | RosterStudent student, Course course, RosterStatus rosterStatus) { | |
| 134 | String convertedEmail = CanonicalFormConverter.convertToValidEmail(student.getEmail()); | |
| 135 | Optional<RosterStudent> existingStudent = | |
| 136 | course.getRosterStudents().stream() | |
| 137 | .filter( | |
| 138 |
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())) |
| 139 | .findFirst(); | |
| 140 | Optional<RosterStudent> existingStudentByEmail = | |
| 141 | course.getRosterStudents().stream() | |
| 142 |
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())) |
| 143 | .findFirst(); | |
| 144 |
2
1. upsertStudent : negated conditional → KILLED 2. upsertStudent : negated conditional → KILLED |
if (existingStudent.isPresent() && existingStudentByEmail.isPresent()) { |
| 145 |
1
1. upsertStudent : negated conditional → KILLED |
if (existingStudent.get().getId().equals(existingStudentByEmail.get().getId())) { |
| 146 | RosterStudent existingStudentObj = existingStudent.get(); | |
| 147 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
existingStudentObj.setRosterStatus(rosterStatus); |
| 148 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setFirstName → KILLED |
existingStudentObj.setFirstName(student.getFirstName()); |
| 149 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setLastName → KILLED |
existingStudentObj.setLastName(student.getLastName()); |
| 150 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setSection → KILLED |
existingStudentObj.setSection(student.getSection()); |
| 151 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.UPDATED, existingStudentObj); |
| 152 | } else { | |
| 153 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.REJECTED, student); |
| 154 | } | |
| 155 |
2
1. upsertStudent : negated conditional → KILLED 2. upsertStudent : negated conditional → KILLED |
} else if (existingStudent.isPresent() || existingStudentByEmail.isPresent()) { |
| 156 | RosterStudent existingStudentObj = | |
| 157 |
1
1. upsertStudent : negated conditional → KILLED |
existingStudent.isPresent() ? existingStudent.get() : existingStudentByEmail.get(); |
| 158 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
existingStudentObj.setRosterStatus(rosterStatus); |
| 159 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setFirstName → KILLED |
existingStudentObj.setFirstName(student.getFirstName()); |
| 160 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setLastName → KILLED |
existingStudentObj.setLastName(student.getLastName()); |
| 161 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setSection → KILLED |
existingStudentObj.setSection(student.getSection()); |
| 162 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setEmail → KILLED |
existingStudentObj.setEmail(convertedEmail); |
| 163 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setStudentId → KILLED |
existingStudentObj.setStudentId(student.getStudentId()); |
| 164 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.UPDATED, existingStudentObj); |
| 165 | } else { | |
| 166 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setCourse → KILLED |
student.setCourse(course); |
| 167 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setEmail → KILLED |
student.setEmail(convertedEmail); |
| 168 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
student.setRosterStatus(rosterStatus); |
| 169 | // if an installationID exists, orgStatus should be set to JOINCOURSE. if it doesn't exist | |
| 170 | // (null), set orgStatus to PENDING. | |
| 171 |
1
1. upsertStudent : negated conditional → KILLED |
if (course.getInstallationId() != null) { |
| 172 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
student.setOrgStatus(OrgStatus.JOINCOURSE); |
| 173 | } else { | |
| 174 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
student.setOrgStatus(OrgStatus.PENDING); |
| 175 | } | |
| 176 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.INSERTED, student); |
| 177 | } | |
| 178 | } | |
| 179 | ||
| 180 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 181 | @PostMapping("/updateCourseMembership") | |
| 182 | public Job updateCourseMembership( | |
| 183 | @Parameter(name = "courseId", description = "Course ID") @RequestParam Long courseId) | |
| 184 | throws NoSuchAlgorithmException, InvalidKeySpecException, JsonProcessingException { | |
| 185 | Course course = | |
| 186 | courseRepository | |
| 187 | .findById(courseId) | |
| 188 |
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)); |
| 189 |
2
1. updateCourseMembership : negated conditional → KILLED 2. updateCourseMembership : negated conditional → KILLED |
if (course.getInstallationId() == null || course.getOrgName() == null) { |
| 190 | throw new NoLinkedOrganizationException(course.getCourseName()); | |
| 191 | } else { | |
| 192 | UpdateOrgMembershipJob job = | |
| 193 | UpdateOrgMembershipJob.builder() | |
| 194 | .rosterStudentRepository(rosterStudentRepository) | |
| 195 | .organizationMemberService(organizationMemberService) | |
| 196 | .course(course) | |
| 197 | .build(); | |
| 198 | ||
| 199 |
1
1. updateCourseMembership : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::updateCourseMembership → KILLED |
return jobService.runAsJob(job); |
| 200 | } | |
| 201 | } | |
| 202 | ||
| 203 | @Operation( | |
| 204 | summary = | |
| 205 | "Allow roster student to join a course by generating an invitation to the linked Github Org") | |
| 206 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 207 | @PutMapping("/joinCourse") | |
| 208 | public ResponseEntity<String> joinCourseOnGitHub( | |
| 209 | @Parameter( | |
| 210 | name = "rosterStudentId", | |
| 211 | description = "Roster Student joining a course on GitHub") | |
| 212 | @RequestParam | |
| 213 | Long rosterStudentId) | |
| 214 | throws NoSuchAlgorithmException, InvalidKeySpecException, JsonProcessingException { | |
| 215 | ||
| 216 | User currentUser = currentUserService.getUser(); | |
| 217 | RosterStudent rosterStudent = | |
| 218 | rosterStudentRepository | |
| 219 | .findById(rosterStudentId) | |
| 220 |
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)); |
| 221 | ||
| 222 |
2
1. joinCourseOnGitHub : negated conditional → KILLED 2. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getUser() == null || currentUser.getId() != rosterStudent.getUser().getId()) { |
| 223 | throw new AccessDeniedException("User not authorized join the course as this roster student"); | |
| 224 | } | |
| 225 | ||
| 226 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getRosterStatus() == RosterStatus.DROPPED) { |
| 227 | throw new AccessDeniedException( | |
| 228 | "You have dropped this course. Please contact your instructor."); | |
| 229 | } | |
| 230 | ||
| 231 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getGithubId() != null |
| 232 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
&& rosterStudent.getGithubLogin() != null |
| 233 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
&& (rosterStudent.getOrgStatus() == OrgStatus.MEMBER |
| 234 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
|| rosterStudent.getOrgStatus() == OrgStatus.OWNER)) { |
| 235 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.badRequest() |
| 236 | .body("This user has already linked a Github account to this course."); | |
| 237 | } | |
| 238 | ||
| 239 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getCourse().getOrgName() == null |
| 240 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
|| rosterStudent.getCourse().getInstallationId() == null) { |
| 241 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.badRequest() |
| 242 | .body("Course has not been set up. Please ask your instructor for help."); | |
| 243 | } | |
| 244 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubId → KILLED |
rosterStudent.setGithubId(currentUser.getGithubId()); |
| 245 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubLogin → KILLED |
rosterStudent.setGithubLogin(currentUser.getGithubLogin()); |
| 246 | OrgStatus status = organizationMemberService.inviteOrganizationMember(rosterStudent); | |
| 247 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
rosterStudent.setOrgStatus(status); |
| 248 | rosterStudentRepository.save(rosterStudent); | |
| 249 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (status == OrgStatus.INVITED) { |
| 250 |
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"); |
| 251 |
2
1. joinCourseOnGitHub : negated conditional → KILLED 2. joinCourseOnGitHub : negated conditional → KILLED |
} else if (status == OrgStatus.MEMBER || status == OrgStatus.OWNER) { |
| 252 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.accepted() |
| 253 | .body("Already in organization - set status to %s".formatted(status.toString())); | |
| 254 | } else { | |
| 255 |
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"); |
| 256 | } | |
| 257 | } | |
| 258 | ||
| 259 | @Operation(summary = "Get Associated Roster Students with a User") | |
| 260 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 261 | @GetMapping("/associatedRosterStudents") | |
| 262 | public Iterable<RosterStudent> getAssociatedRosterStudents() { | |
| 263 | User currentUser = currentUserService.getUser(); | |
| 264 | Iterable<RosterStudent> rosterStudents = rosterStudentRepository.findAllByUser((currentUser)); | |
| 265 |
1
1. getAssociatedRosterStudents : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::getAssociatedRosterStudents → KILLED |
return rosterStudents; |
| 266 | } | |
| 267 | ||
| 268 | @Operation(summary = "Update a roster student") | |
| 269 | @PreAuthorize("@CourseSecurity.hasRosterStudentManagementPermissions(#root, #id)") | |
| 270 | @PutMapping("/update") | |
| 271 | public RosterStudent updateRosterStudent( | |
| 272 | @Parameter(name = "id") @RequestParam Long id, | |
| 273 | @Parameter(name = "firstName") @RequestParam(required = false) String firstName, | |
| 274 | @Parameter(name = "lastName") @RequestParam(required = false) String lastName, | |
| 275 | @Parameter(name = "studentId") @RequestParam(required = false) String studentId, | |
| 276 | @Parameter(name = "section") @RequestParam(required = false) String section) | |
| 277 | throws EntityNotFoundException { | |
| 278 | ||
| 279 |
3
1. updateRosterStudent : negated conditional → KILLED 2. updateRosterStudent : negated conditional → KILLED 3. updateRosterStudent : negated conditional → KILLED |
if (firstName == null |
| 280 | || lastName == null | |
| 281 | || studentId == null | |
| 282 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| firstName.trim().isEmpty() |
| 283 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| lastName.trim().isEmpty() |
| 284 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| studentId.trim().isEmpty()) { |
| 285 | throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Required fields cannot be empty"); | |
| 286 | } | |
| 287 | ||
| 288 | RosterStudent rosterStudent = | |
| 289 | rosterStudentRepository | |
| 290 | .findById(id) | |
| 291 |
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)); |
| 292 | ||
| 293 |
1
1. updateRosterStudent : negated conditional → KILLED |
if (!rosterStudent.getStudentId().trim().equals(studentId.trim())) { |
| 294 | Optional<RosterStudent> existingStudent = | |
| 295 | rosterStudentRepository.findByCourseIdAndStudentId( | |
| 296 | rosterStudent.getCourse().getId(), studentId.trim()); | |
| 297 |
1
1. updateRosterStudent : negated conditional → KILLED |
if (existingStudent.isPresent()) { |
| 298 | throw new ResponseStatusException( | |
| 299 | HttpStatus.BAD_REQUEST, "Student ID already exists in this course"); | |
| 300 | } | |
| 301 | } | |
| 302 | ||
| 303 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setFirstName → KILLED |
rosterStudent.setFirstName(firstName.trim()); |
| 304 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setLastName → KILLED |
rosterStudent.setLastName(lastName.trim()); |
| 305 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setStudentId → KILLED |
rosterStudent.setStudentId(studentId.trim()); |
| 306 | ||
| 307 |
1
1. updateRosterStudent : negated conditional → KILLED |
if (section != null) { |
| 308 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setSection → KILLED |
rosterStudent.setSection(section.trim()); |
| 309 | } | |
| 310 | ||
| 311 |
1
1. updateRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::updateRosterStudent → KILLED |
return rosterStudentRepository.save(rosterStudent); |
| 312 | } | |
| 313 | ||
| 314 | @Operation( | |
| 315 | summary = "Restore a roster student", | |
| 316 | description = "Makes a student who previously dropped the course able to join and interact") | |
| 317 | @PreAuthorize("@CourseSecurity.hasRosterStudentManagementPermissions(#root, #id)") | |
| 318 | @PutMapping("/restore") | |
| 319 | public RosterStudent restoreRosterStudent(@Parameter(name = "id") @RequestParam Long id) | |
| 320 | throws EntityNotFoundException { | |
| 321 | RosterStudent rosterStudent = | |
| 322 | rosterStudentRepository | |
| 323 | .findById(id) | |
| 324 |
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)); |
| 325 |
1
1. restoreRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
rosterStudent.setRosterStatus(RosterStatus.MANUAL); |
| 326 |
1
1. restoreRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::restoreRosterStudent → KILLED |
return rosterStudentRepository.save(rosterStudent); |
| 327 | } | |
| 328 | ||
| 329 | @Operation(summary = "Delete a roster student") | |
| 330 | @PreAuthorize("@CourseSecurity.hasRosterStudentManagementPermissions(#root, #id)") | |
| 331 | @DeleteMapping("/delete") | |
| 332 | @Transactional | |
| 333 | public ResponseEntity<String> deleteRosterStudent( | |
| 334 | @Parameter(name = "id") @RequestParam Long id, | |
| 335 | @Parameter( | |
| 336 | name = "removeFromOrg", | |
| 337 | description = "Whether to remove student from GitHub organization") | |
| 338 | @RequestParam(defaultValue = "true") | |
| 339 | boolean removeFromOrg) | |
| 340 | throws EntityNotFoundException { | |
| 341 | RosterStudent rosterStudent = | |
| 342 | rosterStudentRepository | |
| 343 | .findById(id) | |
| 344 |
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)); |
| 345 | Course course = rosterStudent.getCourse(); | |
| 346 | ||
| 347 | boolean orgRemovalAttempted = false; | |
| 348 | boolean orgRemovalSuccessful = false; | |
| 349 | String orgRemovalErrorMessage = null; | |
| 350 | ||
| 351 | // Try to remove the student from the organization if they have a GitHub login | |
| 352 | // and removeFromOrg parameter is true | |
| 353 |
1
1. deleteRosterStudent : negated conditional → KILLED |
if (removeFromOrg |
| 354 |
1
1. deleteRosterStudent : negated conditional → KILLED |
&& rosterStudent.getGithubLogin() != null |
| 355 |
1
1. deleteRosterStudent : negated conditional → KILLED |
&& course.getOrgName() != null |
| 356 |
1
1. deleteRosterStudent : negated conditional → KILLED |
&& course.getInstallationId() != null) { |
| 357 | orgRemovalAttempted = true; | |
| 358 | try { | |
| 359 |
1
1. deleteRosterStudent : removed call to edu/ucsb/cs156/frontiers/services/OrganizationMemberService::removeOrganizationMember → KILLED |
organizationMemberService.removeOrganizationMember(rosterStudent); |
| 360 | orgRemovalSuccessful = true; | |
| 361 | } catch (Exception e) { | |
| 362 | log.error("Error removing student from organization: {}", e.getMessage()); | |
| 363 | orgRemovalErrorMessage = e.getMessage(); | |
| 364 | // Continue with deletion even if organization removal fails | |
| 365 | } | |
| 366 | } | |
| 367 | ||
| 368 |
1
1. deleteRosterStudent : negated conditional → KILLED |
if (!rosterStudent.getTeamMembers().isEmpty()) { |
| 369 | rosterStudent | |
| 370 | .getTeamMembers() | |
| 371 |
1
1. deleteRosterStudent : removed call to java/util/List::forEach → KILLED |
.forEach( |
| 372 | teamMember -> { | |
| 373 | teamMember.getTeam().getTeamMembers().remove(teamMember); | |
| 374 |
1
1. lambda$deleteRosterStudent$10 : removed call to edu/ucsb/cs156/frontiers/entities/TeamMember::setTeam → KILLED |
teamMember.setTeam(null); |
| 375 | }); | |
| 376 | } | |
| 377 | ||
| 378 | rosterStudent.getCourse().getRosterStudents().remove(rosterStudent); | |
| 379 |
1
1. deleteRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setCourse → KILLED |
rosterStudent.setCourse(null); |
| 380 |
1
1. deleteRosterStudent : removed call to edu/ucsb/cs156/frontiers/repositories/RosterStudentRepository::delete → KILLED |
rosterStudentRepository.delete(rosterStudent); |
| 381 | ||
| 382 |
1
1. deleteRosterStudent : negated conditional → KILLED |
if (!orgRemovalAttempted) { |
| 383 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
| 384 | "Successfully deleted roster student and removed him/her from the course list"); | |
| 385 |
1
1. deleteRosterStudent : negated conditional → KILLED |
} else if (orgRemovalSuccessful) { |
| 386 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
| 387 | "Successfully deleted roster student and removed him/her from the course list and organization"); | |
| 388 | } else { | |
| 389 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
| 390 | "Successfully deleted roster student but there was an error removing them from the course organization: " | |
| 391 | + orgRemovalErrorMessage); | |
| 392 | } | |
| 393 | } | |
| 394 | } | |
Mutations | ||
| 86 |
1.1 |
|
| 94 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 102 |
1.1 |
|
| 103 |
1.1 |
|
| 119 |
1.1 |
|
| 123 |
1.1 |
|
| 129 |
1.1 |
|
| 138 |
1.1 2.2 |
|
| 142 |
1.1 2.2 |
|
| 144 |
1.1 2.2 |
|
| 145 |
1.1 |
|
| 147 |
1.1 |
|
| 148 |
1.1 |
|
| 149 |
1.1 |
|
| 150 |
1.1 |
|
| 151 |
1.1 |
|
| 153 |
1.1 |
|
| 155 |
1.1 2.2 |
|
| 157 |
1.1 |
|
| 158 |
1.1 |
|
| 159 |
1.1 |
|
| 160 |
1.1 |
|
| 161 |
1.1 |
|
| 162 |
1.1 |
|
| 163 |
1.1 |
|
| 164 |
1.1 |
|
| 166 |
1.1 |
|
| 167 |
1.1 |
|
| 168 |
1.1 |
|
| 171 |
1.1 |
|
| 172 |
1.1 |
|
| 174 |
1.1 |
|
| 176 |
1.1 |
|
| 188 |
1.1 |
|
| 189 |
1.1 2.2 |
|
| 199 |
1.1 |
|
| 220 |
1.1 |
|
| 222 |
1.1 2.2 |
|
| 226 |
1.1 |
|
| 231 |
1.1 |
|
| 232 |
1.1 |
|
| 233 |
1.1 |
|
| 234 |
1.1 |
|
| 235 |
1.1 |
|
| 239 |
1.1 |
|
| 240 |
1.1 |
|
| 241 |
1.1 |
|
| 244 |
1.1 |
|
| 245 |
1.1 |
|
| 247 |
1.1 |
|
| 249 |
1.1 |
|
| 250 |
1.1 |
|
| 251 |
1.1 2.2 |
|
| 252 |
1.1 |
|
| 255 |
1.1 |
|
| 265 |
1.1 |
|
| 279 |
1.1 2.2 3.3 |
|
| 282 |
1.1 |
|
| 283 |
1.1 |
|
| 284 |
1.1 |
|
| 291 |
1.1 |
|
| 293 |
1.1 |
|
| 297 |
1.1 |
|
| 303 |
1.1 |
|
| 304 |
1.1 |
|
| 305 |
1.1 |
|
| 307 |
1.1 |
|
| 308 |
1.1 |
|
| 311 |
1.1 |
|
| 324 |
1.1 |
|
| 325 |
1.1 |
|
| 326 |
1.1 |
|
| 344 |
1.1 |
|
| 353 |
1.1 |
|
| 354 |
1.1 |
|
| 355 |
1.1 |
|
| 356 |
1.1 |
|
| 359 |
1.1 |
|
| 368 |
1.1 |
|
| 371 |
1.1 |
|
| 374 |
1.1 |
|
| 379 |
1.1 |
|
| 380 |
1.1 |
|
| 382 |
1.1 |
|
| 383 |
1.1 |
|
| 385 |
1.1 |
|
| 386 |
1.1 |
|
| 389 |
1.1 |