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 | throws EntityNotFoundException { | |
79 | ||
80 | // Get Course or else throw an error | |
81 | ||
82 | Course course = | |
83 | courseRepository | |
84 | .findById(courseId) | |
85 |
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)); |
86 | ||
87 | RosterStudent rosterStudent = | |
88 | RosterStudent.builder() | |
89 | .studentId(studentId) | |
90 | .firstName(firstName) | |
91 | .lastName(lastName) | |
92 | .email(email) | |
93 | .build(); | |
94 | ||
95 | UpsertResponse upsertResponse = | |
96 | upsertStudent( | |
97 | rosterStudentRepository, updateUserService, 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 |
1
1. postRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::postRosterStudent → KILLED |
return ResponseEntity.ok(upsertResponse); |
102 | } | |
103 | } | |
104 | ||
105 | /** | |
106 | * This method returns a list of roster students for a given course. | |
107 | * | |
108 | * @return a list of all courses. | |
109 | */ | |
110 | @Operation(summary = "List all roster students for a course") | |
111 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
112 | @GetMapping("/course/{courseId}") | |
113 | public Iterable<RosterStudentDTO> rosterStudentForCourse( | |
114 | @Parameter(name = "courseId") @PathVariable Long courseId) throws EntityNotFoundException { | |
115 | courseRepository | |
116 | .findById(courseId) | |
117 |
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)); |
118 | Iterable<RosterStudent> rosterStudents = rosterStudentRepository.findByCourseId(courseId); | |
119 | Iterable<RosterStudentDTO> rosterStudentDTOs = | |
120 | () -> | |
121 |
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) |
122 | .map(RosterStudentDTO::new) | |
123 | .iterator(); | |
124 |
1
1. rosterStudentForCourse : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::rosterStudentForCourse → KILLED |
return rosterStudentDTOs; |
125 | } | |
126 | ||
127 | public static UpsertResponse upsertStudent( | |
128 | RosterStudentRepository rosterStudentRepository, | |
129 | UpdateUserService updateUserService, | |
130 | RosterStudent student, | |
131 | Course course, | |
132 | RosterStatus rosterStatus) { | |
133 | String convertedEmail = CanonicalFormConverter.convertToValidEmail(student.getEmail()); | |
134 | Optional<RosterStudent> existingStudent = | |
135 | rosterStudentRepository.findByCourseIdAndStudentId(course.getId(), student.getStudentId()); | |
136 | Optional<RosterStudent> existingStudentByEmail = | |
137 | rosterStudentRepository.findByCourseIdAndEmail(course.getId(), convertedEmail); | |
138 |
2
1. upsertStudent : negated conditional → KILLED 2. upsertStudent : negated conditional → KILLED |
if (existingStudent.isPresent() && existingStudentByEmail.isPresent()) { |
139 |
1
1. upsertStudent : negated conditional → KILLED |
if (existingStudent.get().getId().equals(existingStudentByEmail.get().getId())) { |
140 | RosterStudent existingStudentObj = existingStudent.get(); | |
141 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
existingStudentObj.setRosterStatus(rosterStatus); |
142 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setFirstName → KILLED |
existingStudentObj.setFirstName(student.getFirstName()); |
143 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setLastName → KILLED |
existingStudentObj.setLastName(student.getLastName()); |
144 | rosterStudentRepository.save(existingStudentObj); | |
145 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.UPDATED, existingStudentObj); |
146 | } else { | |
147 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.REJECTED, student); |
148 | } | |
149 |
2
1. upsertStudent : negated conditional → KILLED 2. upsertStudent : negated conditional → KILLED |
} else if (existingStudent.isPresent() || existingStudentByEmail.isPresent()) { |
150 | RosterStudent existingStudentObj = | |
151 |
1
1. upsertStudent : negated conditional → KILLED |
existingStudent.isPresent() ? existingStudent.get() : existingStudentByEmail.get(); |
152 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
existingStudentObj.setRosterStatus(rosterStatus); |
153 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setFirstName → KILLED |
existingStudentObj.setFirstName(student.getFirstName()); |
154 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setLastName → KILLED |
existingStudentObj.setLastName(student.getLastName()); |
155 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setEmail → KILLED |
existingStudentObj.setEmail(convertedEmail); |
156 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setStudentId → KILLED |
existingStudentObj.setStudentId(student.getStudentId()); |
157 | existingStudentObj = rosterStudentRepository.save(existingStudentObj); | |
158 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachUserToRosterStudent → KILLED |
updateUserService.attachUserToRosterStudent(existingStudentObj); |
159 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.UPDATED, existingStudentObj); |
160 | } else { | |
161 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setCourse → KILLED |
student.setCourse(course); |
162 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setEmail → KILLED |
student.setEmail(convertedEmail); |
163 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
student.setRosterStatus(rosterStatus); |
164 | // if an installationID exists, orgStatus should be set to JOINCOURSE. if it doesn't exist | |
165 | // (null), set orgStatus to PENDING. | |
166 |
1
1. upsertStudent : negated conditional → KILLED |
if (course.getInstallationId() != null) { |
167 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
student.setOrgStatus(OrgStatus.JOINCOURSE); |
168 | } else { | |
169 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
student.setOrgStatus(OrgStatus.PENDING); |
170 | } | |
171 | student = rosterStudentRepository.save(student); | |
172 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachUserToRosterStudent → KILLED |
updateUserService.attachUserToRosterStudent(student); |
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$3 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$updateCourseMembership$3 → 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$4 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$joinCourseOnGitHub$4 → 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.getGithubId() != null |
224 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
&& rosterStudent.getGithubLogin() != null |
225 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
&& (rosterStudent.getOrgStatus() == OrgStatus.MEMBER |
226 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
|| rosterStudent.getOrgStatus() == OrgStatus.OWNER)) { |
227 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.badRequest() |
228 | .body("This user has already linked a Github account to this course."); | |
229 | } | |
230 | ||
231 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getCourse().getOrgName() == null |
232 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
|| rosterStudent.getCourse().getInstallationId() == null) { |
233 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.badRequest() |
234 | .body("Course has not been set up. Please ask your instructor for help."); | |
235 | } | |
236 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubId → KILLED |
rosterStudent.setGithubId(currentUser.getGithubId()); |
237 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubLogin → KILLED |
rosterStudent.setGithubLogin(currentUser.getGithubLogin()); |
238 | OrgStatus status = organizationMemberService.inviteOrganizationMember(rosterStudent); | |
239 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
rosterStudent.setOrgStatus(status); |
240 | rosterStudentRepository.save(rosterStudent); | |
241 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (status == OrgStatus.INVITED) { |
242 |
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"); |
243 |
2
1. joinCourseOnGitHub : negated conditional → KILLED 2. joinCourseOnGitHub : negated conditional → KILLED |
} else if (status == OrgStatus.MEMBER || status == OrgStatus.OWNER) { |
244 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.accepted() |
245 | .body("Already in organization - set status to %s".formatted(status.toString())); | |
246 | } else { | |
247 |
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"); |
248 | } | |
249 | } | |
250 | ||
251 | @Operation(summary = "Get Associated Roster Students with a User") | |
252 | @PreAuthorize("hasRole('ROLE_USER')") | |
253 | @GetMapping("/associatedRosterStudents") | |
254 | public Iterable<RosterStudent> getAssociatedRosterStudents() { | |
255 | User currentUser = currentUserService.getUser(); | |
256 | Iterable<RosterStudent> rosterStudents = rosterStudentRepository.findAllByUser((currentUser)); | |
257 |
1
1. getAssociatedRosterStudents : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::getAssociatedRosterStudents → KILLED |
return rosterStudents; |
258 | } | |
259 | ||
260 | @Operation(summary = "Update a roster student") | |
261 | @PreAuthorize("@CourseSecurity.hasRosterStudentManagementPermissions(#root, #id)") | |
262 | @PutMapping("/update") | |
263 | public RosterStudent updateRosterStudent( | |
264 | @Parameter(name = "id") @RequestParam Long id, | |
265 | @Parameter(name = "firstName") @RequestParam(required = false) String firstName, | |
266 | @Parameter(name = "lastName") @RequestParam(required = false) String lastName, | |
267 | @Parameter(name = "studentId") @RequestParam(required = false) String studentId) | |
268 | throws EntityNotFoundException { | |
269 | ||
270 |
3
1. updateRosterStudent : negated conditional → KILLED 2. updateRosterStudent : negated conditional → KILLED 3. updateRosterStudent : negated conditional → KILLED |
if (firstName == null |
271 | || lastName == null | |
272 | || studentId == null | |
273 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| firstName.trim().isEmpty() |
274 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| lastName.trim().isEmpty() |
275 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| studentId.trim().isEmpty()) { |
276 | throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Required fields cannot be empty"); | |
277 | } | |
278 | ||
279 | RosterStudent rosterStudent = | |
280 | rosterStudentRepository | |
281 | .findById(id) | |
282 |
1
1. lambda$updateRosterStudent$5 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$updateRosterStudent$5 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RosterStudent.class, id)); |
283 | ||
284 |
1
1. updateRosterStudent : negated conditional → KILLED |
if (!rosterStudent.getStudentId().trim().equals(studentId.trim())) { |
285 | Optional<RosterStudent> existingStudent = | |
286 | rosterStudentRepository.findByCourseIdAndStudentId( | |
287 | rosterStudent.getCourse().getId(), studentId.trim()); | |
288 |
1
1. updateRosterStudent : negated conditional → KILLED |
if (existingStudent.isPresent()) { |
289 | throw new ResponseStatusException( | |
290 | HttpStatus.BAD_REQUEST, "Student ID already exists in this course"); | |
291 | } | |
292 | } | |
293 | ||
294 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setFirstName → KILLED |
rosterStudent.setFirstName(firstName.trim()); |
295 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setLastName → KILLED |
rosterStudent.setLastName(lastName.trim()); |
296 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setStudentId → KILLED |
rosterStudent.setStudentId(studentId.trim()); |
297 | ||
298 |
1
1. updateRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::updateRosterStudent → KILLED |
return rosterStudentRepository.save(rosterStudent); |
299 | } | |
300 | ||
301 | @Operation(summary = "Delete a roster student") | |
302 | @PreAuthorize("@CourseSecurity.hasRosterStudentManagementPermissions(#root, #id)") | |
303 | @DeleteMapping("/delete") | |
304 | @Transactional | |
305 | public ResponseEntity<String> deleteRosterStudent(@Parameter(name = "id") @RequestParam Long id) | |
306 | throws EntityNotFoundException { | |
307 | RosterStudent rosterStudent = | |
308 | rosterStudentRepository | |
309 | .findById(id) | |
310 |
1
1. lambda$deleteRosterStudent$6 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::lambda$deleteRosterStudent$6 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RosterStudent.class, id)); |
311 | Course course = rosterStudent.getCourse(); | |
312 | ||
313 | boolean orgRemovalAttempted = false; | |
314 | boolean orgRemovalSuccessful = false; | |
315 | String orgRemovalErrorMessage = null; | |
316 | ||
317 | // Try to remove the student from the organization if they have a GitHub login | |
318 |
1
1. deleteRosterStudent : negated conditional → KILLED |
if (rosterStudent.getGithubLogin() != null |
319 |
1
1. deleteRosterStudent : negated conditional → KILLED |
&& course.getOrgName() != null |
320 |
1
1. deleteRosterStudent : negated conditional → KILLED |
&& course.getInstallationId() != null) { |
321 | orgRemovalAttempted = true; | |
322 | try { | |
323 |
1
1. deleteRosterStudent : removed call to edu/ucsb/cs156/frontiers/services/OrganizationMemberService::removeOrganizationMember → KILLED |
organizationMemberService.removeOrganizationMember(rosterStudent); |
324 | orgRemovalSuccessful = true; | |
325 | } catch (Exception e) { | |
326 | log.error("Error removing student from organization: {}", e.getMessage()); | |
327 | orgRemovalErrorMessage = e.getMessage(); | |
328 | // Continue with deletion even if organization removal fails | |
329 | } | |
330 | } | |
331 | ||
332 |
1
1. deleteRosterStudent : negated conditional → KILLED |
if (!rosterStudent.getTeamMembers().isEmpty()) { |
333 | rosterStudent | |
334 | .getTeamMembers() | |
335 |
1
1. deleteRosterStudent : removed call to java/util/List::forEach → KILLED |
.forEach( |
336 | teamMember -> { | |
337 | teamMember.getTeam().getTeamMembers().remove(teamMember); | |
338 |
1
1. lambda$deleteRosterStudent$7 : removed call to edu/ucsb/cs156/frontiers/entities/TeamMember::setTeam → KILLED |
teamMember.setTeam(null); |
339 | }); | |
340 | } | |
341 | ||
342 | rosterStudent.getCourse().getRosterStudents().remove(rosterStudent); | |
343 |
1
1. deleteRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setCourse → KILLED |
rosterStudent.setCourse(null); |
344 |
1
1. deleteRosterStudent : removed call to edu/ucsb/cs156/frontiers/repositories/RosterStudentRepository::delete → KILLED |
rosterStudentRepository.delete(rosterStudent); |
345 | ||
346 |
1
1. deleteRosterStudent : negated conditional → KILLED |
if (!orgRemovalAttempted) { |
347 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
348 | "Successfully deleted roster student and removed him/her from the course list"); | |
349 |
1
1. deleteRosterStudent : negated conditional → KILLED |
} else if (orgRemovalSuccessful) { |
350 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
351 | "Successfully deleted roster student and removed him/her from the course list and organization"); | |
352 | } else { | |
353 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
354 | "Successfully deleted roster student but there was an error removing them from the course organization: " | |
355 | + orgRemovalErrorMessage); | |
356 | } | |
357 | } | |
358 | } | |
Mutations | ||
85 |
1.1 |
|
98 |
1.1 |
|
99 |
1.1 |
|
101 |
1.1 |
|
117 |
1.1 |
|
121 |
1.1 |
|
124 |
1.1 |
|
138 |
1.1 2.2 |
|
139 |
1.1 |
|
141 |
1.1 |
|
142 |
1.1 |
|
143 |
1.1 |
|
145 |
1.1 |
|
147 |
1.1 |
|
149 |
1.1 2.2 |
|
151 |
1.1 |
|
152 |
1.1 |
|
153 |
1.1 |
|
154 |
1.1 |
|
155 |
1.1 |
|
156 |
1.1 |
|
158 |
1.1 |
|
159 |
1.1 |
|
161 |
1.1 |
|
162 |
1.1 |
|
163 |
1.1 |
|
166 |
1.1 |
|
167 |
1.1 |
|
169 |
1.1 |
|
172 |
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 |
|
224 |
1.1 |
|
225 |
1.1 |
|
226 |
1.1 |
|
227 |
1.1 |
|
231 |
1.1 |
|
232 |
1.1 |
|
233 |
1.1 |
|
236 |
1.1 |
|
237 |
1.1 |
|
239 |
1.1 |
|
241 |
1.1 |
|
242 |
1.1 |
|
243 |
1.1 2.2 |
|
244 |
1.1 |
|
247 |
1.1 |
|
257 |
1.1 |
|
270 |
1.1 2.2 3.3 |
|
273 |
1.1 |
|
274 |
1.1 |
|
275 |
1.1 |
|
282 |
1.1 |
|
284 |
1.1 |
|
288 |
1.1 |
|
294 |
1.1 |
|
295 |
1.1 |
|
296 |
1.1 |
|
298 |
1.1 |
|
310 |
1.1 |
|
318 |
1.1 |
|
319 |
1.1 |
|
320 |
1.1 |
|
323 |
1.1 |
|
332 |
1.1 |
|
335 |
1.1 |
|
338 |
1.1 |
|
343 |
1.1 |
|
344 |
1.1 |
|
346 |
1.1 |
|
347 |
1.1 |
|
349 |
1.1 |
|
350 |
1.1 |
|
353 |
1.1 |