1 | package edu.ucsb.cs156.frontiers.services; | |
2 | ||
3 | import edu.ucsb.cs156.frontiers.entities.CourseStaff; | |
4 | import edu.ucsb.cs156.frontiers.entities.RosterStudent; | |
5 | import edu.ucsb.cs156.frontiers.entities.User; | |
6 | import edu.ucsb.cs156.frontiers.repositories.CourseStaffRepository; | |
7 | import edu.ucsb.cs156.frontiers.repositories.RosterStudentRepository; | |
8 | import edu.ucsb.cs156.frontiers.repositories.UserRepository; | |
9 | import java.util.List; | |
10 | import java.util.Optional; | |
11 | import org.springframework.beans.factory.annotation.Autowired; | |
12 | import org.springframework.stereotype.Service; | |
13 | ||
14 | @Service | |
15 | public class UpdateUserService { | |
16 | ||
17 | @Autowired private UserRepository userRepository; | |
18 | ||
19 | @Autowired private RosterStudentRepository rosterStudentRepository; | |
20 | @Autowired private CourseStaffRepository courseStaffRepository; | |
21 | ||
22 | /** | |
23 | * This method attaches the RosterStudents to the User based on their email. | |
24 | * | |
25 | * @param user The user to whom the RosterStudents will be attached | |
26 | */ | |
27 | public void attachRosterStudents(User user) { | |
28 | List<RosterStudent> matchedStudents = rosterStudentRepository.findAllByEmail(user.getEmail()); | |
29 |
2
1. attachRosterStudents : negated conditional → KILLED 2. attachRosterStudents : changed conditional boundary → KILLED |
for (int i = 0; i < matchedStudents.size(); i++) { |
30 | RosterStudent matchedStudent = matchedStudents.get(i); | |
31 |
1
1. attachRosterStudents : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setUser → KILLED |
matchedStudent.setUser(user); |
32 | } | |
33 | rosterStudentRepository.saveAll(matchedStudents); | |
34 | } | |
35 | ||
36 | /** | |
37 | * This method attaches the CourseStaff to the User based on their email. | |
38 | * | |
39 | * @param user The user to whom the RosterStudents will be attached | |
40 | */ | |
41 | public void attachCourseStaff(User user) { | |
42 | List<CourseStaff> matchedStaff = courseStaffRepository.findAllByEmail(user.getEmail()); | |
43 | for (CourseStaff matched : matchedStaff) { | |
44 |
1
1. attachCourseStaff : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setUser → KILLED |
matched.setUser(user); |
45 | } | |
46 | courseStaffRepository.saveAll(matchedStaff); | |
47 | } | |
48 | ||
49 | /** attach roster students for all Users */ | |
50 | public void attachRosterStudentsAllUsers() { | |
51 | Iterable<User> allUsers = userRepository.findAll(); | |
52 | for (User user : allUsers) { | |
53 |
1
1. attachRosterStudentsAllUsers : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachRosterStudents → KILLED |
attachRosterStudents(user); |
54 | } | |
55 | } | |
56 | ||
57 | /** This method attaches a SingleRoster student to the User based on their email. */ | |
58 | public void attachUserToRosterStudent(RosterStudent rosterStudent) { | |
59 | String email = rosterStudent.getEmail(); | |
60 | Optional<User> optionalUser = userRepository.findByEmail(email); | |
61 |
1
1. attachUserToRosterStudent : negated conditional → KILLED |
if (optionalUser.isPresent()) { |
62 | User matchedUser = optionalUser.get(); | |
63 |
1
1. attachUserToRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setUser → KILLED |
rosterStudent.setUser(matchedUser); |
64 | rosterStudentRepository.save(rosterStudent); | |
65 | } | |
66 | } | |
67 | ||
68 | /** This method attaches a SingleRoster student to the User based on their email. */ | |
69 | public void attachUserToCourseStaff(CourseStaff courseStaff) { | |
70 | String email = courseStaff.getEmail(); | |
71 | Optional<User> optionalUser = userRepository.findByEmail(email); | |
72 |
1
1. attachUserToCourseStaff : negated conditional → KILLED |
if (optionalUser.isPresent()) { |
73 | User matchedUser = optionalUser.get(); | |
74 |
1
1. attachUserToCourseStaff : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setUser → KILLED |
courseStaff.setUser(matchedUser); |
75 | courseStaffRepository.save(courseStaff); | |
76 | } | |
77 | } | |
78 | } | |
Mutations | ||
29 |
1.1 2.2 |
|
31 |
1.1 |
|
44 |
1.1 |
|
53 |
1.1 |
|
61 |
1.1 |
|
63 |
1.1 |
|
72 |
1.1 |
|
74 |
1.1 |