1 | package edu.ucsb.cs156.frontiers.services; | |
2 | ||
3 | import java.util.List; | |
4 | import java.util.Optional; | |
5 | ||
6 | import org.springframework.beans.factory.annotation.Autowired; | |
7 | import org.springframework.stereotype.Service; | |
8 | ||
9 | import edu.ucsb.cs156.frontiers.entities.RosterStudent; | |
10 | import edu.ucsb.cs156.frontiers.entities.User; | |
11 | import edu.ucsb.cs156.frontiers.repositories.RosterStudentRepository; | |
12 | import edu.ucsb.cs156.frontiers.repositories.UserRepository; | |
13 | ||
14 | @Service | |
15 | public class UpdateUserService { | |
16 | ||
17 | @Autowired | |
18 | private UserRepository userRepository; | |
19 | ||
20 | @Autowired | |
21 | private RosterStudentRepository rosterStudentRepository; | |
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 | /** attach roster students for all Users */ | |
39 | public void attachRosterStudentsAllUsers() { | |
40 | Iterable<User> allUsers = userRepository.findAll(); | |
41 | for (User user : allUsers) { | |
42 |
1
1. attachRosterStudentsAllUsers : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachRosterStudents → KILLED |
attachRosterStudents(user); |
43 | } | |
44 | } | |
45 | ||
46 | /** | |
47 | * This method attaches a SingleRoster student to the User based on their email. | |
48 | */ | |
49 | public void attachUserToRosterStudent(RosterStudent rosterStudent) { | |
50 | String email = rosterStudent.getEmail(); | |
51 | Optional<User> optionalUser = userRepository.findByEmail(email); | |
52 |
1
1. attachUserToRosterStudent : negated conditional → KILLED |
if (optionalUser.isPresent()) { |
53 | User matchedUser = optionalUser.get(); | |
54 |
1
1. attachUserToRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setUser → KILLED |
rosterStudent.setUser(matchedUser); |
55 | rosterStudentRepository.save(rosterStudent); | |
56 | } | |
57 | } | |
58 | } | |
Mutations | ||
30 |
1.1 2.2 |
|
32 |
1.1 |
|
42 |
1.1 |
|
52 |
1.1 |
|
54 |
1.1 |