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