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