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 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setSection → KILLED |
existingStudentObj.setSection(student.getSection()); |
145 | rosterStudentRepository.save(existingStudentObj); | |
146 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.UPDATED, existingStudentObj); |
147 | } else { | |
148 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.REJECTED, student); |
149 | } | |
150 |
2
1. upsertStudent : negated conditional → KILLED 2. upsertStudent : negated conditional → KILLED |
} else if (existingStudent.isPresent() || existingStudentByEmail.isPresent()) { |
151 | RosterStudent existingStudentObj = | |
152 |
1
1. upsertStudent : negated conditional → KILLED |
existingStudent.isPresent() ? existingStudent.get() : existingStudentByEmail.get(); |
153 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setRosterStatus → KILLED |
existingStudentObj.setRosterStatus(rosterStatus); |
154 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setFirstName → KILLED |
existingStudentObj.setFirstName(student.getFirstName()); |
155 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setLastName → KILLED |
existingStudentObj.setLastName(student.getLastName()); |
156 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setSection → KILLED |
existingStudentObj.setSection(student.getSection()); |
157 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setEmail → KILLED |
existingStudentObj.setEmail(convertedEmail); |
158 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setStudentId → KILLED |
existingStudentObj.setStudentId(student.getStudentId()); |
159 | existingStudentObj = rosterStudentRepository.save(existingStudentObj); | |
160 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachUserToRosterStudent → KILLED |
updateUserService.attachUserToRosterStudent(existingStudentObj); |
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 | student = rosterStudentRepository.save(student); | |
174 |
1
1. upsertStudent : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachUserToRosterStudent → KILLED |
updateUserService.attachUserToRosterStudent(student); |
175 |
1
1. upsertStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::upsertStudent → KILLED |
return new UpsertResponse(InsertStatus.INSERTED, student); |
176 | } | |
177 | } | |
178 | ||
179 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
180 | @PostMapping("/updateCourseMembership") | |
181 | public Job updateCourseMembership( | |
182 | @Parameter(name = "courseId", description = "Course ID") @RequestParam Long courseId) | |
183 | throws NoSuchAlgorithmException, InvalidKeySpecException, JsonProcessingException { | |
184 | Course course = | |
185 | courseRepository | |
186 | .findById(courseId) | |
187 |
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)); |
188 |
2
1. updateCourseMembership : negated conditional → KILLED 2. updateCourseMembership : negated conditional → KILLED |
if (course.getInstallationId() == null || course.getOrgName() == null) { |
189 | throw new NoLinkedOrganizationException(course.getCourseName()); | |
190 | } else { | |
191 | UpdateOrgMembershipJob job = | |
192 | UpdateOrgMembershipJob.builder() | |
193 | .rosterStudentRepository(rosterStudentRepository) | |
194 | .organizationMemberService(organizationMemberService) | |
195 | .course(course) | |
196 | .build(); | |
197 | ||
198 |
1
1. updateCourseMembership : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::updateCourseMembership → KILLED |
return jobService.runAsJob(job); |
199 | } | |
200 | } | |
201 | ||
202 | @Operation( | |
203 | summary = | |
204 | "Allow roster student to join a course by generating an invitation to the linked Github Org") | |
205 | @PreAuthorize("hasRole('ROLE_USER')") | |
206 | @PutMapping("/joinCourse") | |
207 | public ResponseEntity<String> joinCourseOnGitHub( | |
208 | @Parameter( | |
209 | name = "rosterStudentId", | |
210 | description = "Roster Student joining a course on GitHub") | |
211 | @RequestParam | |
212 | Long rosterStudentId) | |
213 | throws NoSuchAlgorithmException, InvalidKeySpecException, JsonProcessingException { | |
214 | ||
215 | User currentUser = currentUserService.getUser(); | |
216 | RosterStudent rosterStudent = | |
217 | rosterStudentRepository | |
218 | .findById(rosterStudentId) | |
219 |
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)); |
220 | ||
221 |
2
1. joinCourseOnGitHub : negated conditional → KILLED 2. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getUser() == null || currentUser.getId() != rosterStudent.getUser().getId()) { |
222 | throw new AccessDeniedException("User not authorized join the course as this roster student"); | |
223 | } | |
224 | ||
225 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getGithubId() != null |
226 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
&& rosterStudent.getGithubLogin() != null |
227 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
&& (rosterStudent.getOrgStatus() == OrgStatus.MEMBER |
228 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
|| rosterStudent.getOrgStatus() == OrgStatus.OWNER)) { |
229 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.badRequest() |
230 | .body("This user has already linked a Github account to this course."); | |
231 | } | |
232 | ||
233 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (rosterStudent.getCourse().getOrgName() == null |
234 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
|| rosterStudent.getCourse().getInstallationId() == null) { |
235 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.badRequest() |
236 | .body("Course has not been set up. Please ask your instructor for help."); | |
237 | } | |
238 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubId → KILLED |
rosterStudent.setGithubId(currentUser.getGithubId()); |
239 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubLogin → KILLED |
rosterStudent.setGithubLogin(currentUser.getGithubLogin()); |
240 | OrgStatus status = organizationMemberService.inviteOrganizationMember(rosterStudent); | |
241 |
1
1. joinCourseOnGitHub : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED |
rosterStudent.setOrgStatus(status); |
242 | rosterStudentRepository.save(rosterStudent); | |
243 |
1
1. joinCourseOnGitHub : negated conditional → KILLED |
if (status == OrgStatus.INVITED) { |
244 |
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"); |
245 |
2
1. joinCourseOnGitHub : negated conditional → KILLED 2. joinCourseOnGitHub : negated conditional → KILLED |
} else if (status == OrgStatus.MEMBER || status == OrgStatus.OWNER) { |
246 |
1
1. joinCourseOnGitHub : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::joinCourseOnGitHub → KILLED |
return ResponseEntity.accepted() |
247 | .body("Already in organization - set status to %s".formatted(status.toString())); | |
248 | } else { | |
249 |
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"); |
250 | } | |
251 | } | |
252 | ||
253 | @Operation(summary = "Get Associated Roster Students with a User") | |
254 | @PreAuthorize("hasRole('ROLE_USER')") | |
255 | @GetMapping("/associatedRosterStudents") | |
256 | public Iterable<RosterStudent> getAssociatedRosterStudents() { | |
257 | User currentUser = currentUserService.getUser(); | |
258 | Iterable<RosterStudent> rosterStudents = rosterStudentRepository.findAllByUser((currentUser)); | |
259 |
1
1. getAssociatedRosterStudents : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::getAssociatedRosterStudents → KILLED |
return rosterStudents; |
260 | } | |
261 | ||
262 | @Operation(summary = "Update a roster student") | |
263 | @PreAuthorize("@CourseSecurity.hasRosterStudentManagementPermissions(#root, #id)") | |
264 | @PutMapping("/update") | |
265 | public RosterStudent updateRosterStudent( | |
266 | @Parameter(name = "id") @RequestParam Long id, | |
267 | @Parameter(name = "firstName") @RequestParam(required = false) String firstName, | |
268 | @Parameter(name = "lastName") @RequestParam(required = false) String lastName, | |
269 | @Parameter(name = "studentId") @RequestParam(required = false) String studentId) | |
270 | throws EntityNotFoundException { | |
271 | ||
272 |
3
1. updateRosterStudent : negated conditional → KILLED 2. updateRosterStudent : negated conditional → KILLED 3. updateRosterStudent : negated conditional → KILLED |
if (firstName == null |
273 | || lastName == null | |
274 | || studentId == null | |
275 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| firstName.trim().isEmpty() |
276 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| lastName.trim().isEmpty() |
277 |
1
1. updateRosterStudent : negated conditional → KILLED |
|| studentId.trim().isEmpty()) { |
278 | throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Required fields cannot be empty"); | |
279 | } | |
280 | ||
281 | RosterStudent rosterStudent = | |
282 | rosterStudentRepository | |
283 | .findById(id) | |
284 |
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)); |
285 | ||
286 |
1
1. updateRosterStudent : negated conditional → KILLED |
if (!rosterStudent.getStudentId().trim().equals(studentId.trim())) { |
287 | Optional<RosterStudent> existingStudent = | |
288 | rosterStudentRepository.findByCourseIdAndStudentId( | |
289 | rosterStudent.getCourse().getId(), studentId.trim()); | |
290 |
1
1. updateRosterStudent : negated conditional → KILLED |
if (existingStudent.isPresent()) { |
291 | throw new ResponseStatusException( | |
292 | HttpStatus.BAD_REQUEST, "Student ID already exists in this course"); | |
293 | } | |
294 | } | |
295 | ||
296 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setFirstName → KILLED |
rosterStudent.setFirstName(firstName.trim()); |
297 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setLastName → KILLED |
rosterStudent.setLastName(lastName.trim()); |
298 |
1
1. updateRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setStudentId → KILLED |
rosterStudent.setStudentId(studentId.trim()); |
299 | ||
300 |
1
1. updateRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::updateRosterStudent → KILLED |
return rosterStudentRepository.save(rosterStudent); |
301 | } | |
302 | ||
303 | @Operation(summary = "Delete a roster student") | |
304 | @PreAuthorize("@CourseSecurity.hasRosterStudentManagementPermissions(#root, #id)") | |
305 | @DeleteMapping("/delete") | |
306 | @Transactional | |
307 | public ResponseEntity<String> deleteRosterStudent(@Parameter(name = "id") @RequestParam Long id) | |
308 | throws EntityNotFoundException { | |
309 | RosterStudent rosterStudent = | |
310 | rosterStudentRepository | |
311 | .findById(id) | |
312 |
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)); |
313 | Course course = rosterStudent.getCourse(); | |
314 | ||
315 | boolean orgRemovalAttempted = false; | |
316 | boolean orgRemovalSuccessful = false; | |
317 | String orgRemovalErrorMessage = null; | |
318 | ||
319 | // Try to remove the student from the organization if they have a GitHub login | |
320 |
1
1. deleteRosterStudent : negated conditional → KILLED |
if (rosterStudent.getGithubLogin() != null |
321 |
1
1. deleteRosterStudent : negated conditional → KILLED |
&& course.getOrgName() != null |
322 |
1
1. deleteRosterStudent : negated conditional → KILLED |
&& course.getInstallationId() != null) { |
323 | orgRemovalAttempted = true; | |
324 | try { | |
325 |
1
1. deleteRosterStudent : removed call to edu/ucsb/cs156/frontiers/services/OrganizationMemberService::removeOrganizationMember → KILLED |
organizationMemberService.removeOrganizationMember(rosterStudent); |
326 | orgRemovalSuccessful = true; | |
327 | } catch (Exception e) { | |
328 | log.error("Error removing student from organization: {}", e.getMessage()); | |
329 | orgRemovalErrorMessage = e.getMessage(); | |
330 | // Continue with deletion even if organization removal fails | |
331 | } | |
332 | } | |
333 | ||
334 | course.getRosterStudents().remove(rosterStudent); | |
335 |
1
1. deleteRosterStudent : removed call to edu/ucsb/cs156/frontiers/repositories/RosterStudentRepository::delete → KILLED |
rosterStudentRepository.delete(rosterStudent); |
336 | courseRepository.save(course); | |
337 | ||
338 |
1
1. deleteRosterStudent : negated conditional → KILLED |
if (!orgRemovalAttempted) { |
339 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
340 | "Successfully deleted roster student and removed him/her from the course list"); | |
341 |
1
1. deleteRosterStudent : negated conditional → KILLED |
} else if (orgRemovalSuccessful) { |
342 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
343 | "Successfully deleted roster student and removed him/her from the course list and organization"); | |
344 | } else { | |
345 |
1
1. deleteRosterStudent : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RosterStudentsController::deleteRosterStudent → KILLED |
return ResponseEntity.ok( |
346 | "Successfully deleted roster student but there was an error removing them from the course organization: " | |
347 | + orgRemovalErrorMessage); | |
348 | } | |
349 | } | |
350 | } | |
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 |
|
144 |
1.1 |
|
146 |
1.1 |
|
148 |
1.1 |
|
150 |
1.1 2.2 |
|
152 |
1.1 |
|
153 |
1.1 |
|
154 |
1.1 |
|
155 |
1.1 |
|
156 |
1.1 |
|
157 |
1.1 |
|
158 |
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 |
|
174 |
1.1 |
|
175 |
1.1 |
|
187 |
1.1 |
|
188 |
1.1 2.2 |
|
198 |
1.1 |
|
219 |
1.1 |
|
221 |
1.1 2.2 |
|
225 |
1.1 |
|
226 |
1.1 |
|
227 |
1.1 |
|
228 |
1.1 |
|
229 |
1.1 |
|
233 |
1.1 |
|
234 |
1.1 |
|
235 |
1.1 |
|
238 |
1.1 |
|
239 |
1.1 |
|
241 |
1.1 |
|
243 |
1.1 |
|
244 |
1.1 |
|
245 |
1.1 2.2 |
|
246 |
1.1 |
|
249 |
1.1 |
|
259 |
1.1 |
|
272 |
1.1 2.2 3.3 |
|
275 |
1.1 |
|
276 |
1.1 |
|
277 |
1.1 |
|
284 |
1.1 |
|
286 |
1.1 |
|
290 |
1.1 |
|
296 |
1.1 |
|
297 |
1.1 |
|
298 |
1.1 |
|
300 |
1.1 |
|
312 |
1.1 |
|
320 |
1.1 |
|
321 |
1.1 |
|
322 |
1.1 |
|
325 |
1.1 |
|
335 |
1.1 |
|
338 |
1.1 |
|
339 |
1.1 |
|
341 |
1.1 |
|
342 |
1.1 |
|
345 |
1.1 |