UpdateUserService.java

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.enums.OrgStatus;
7
import edu.ucsb.cs156.frontiers.repositories.CourseStaffRepository;
8
import edu.ucsb.cs156.frontiers.repositories.RosterStudentRepository;
9
import edu.ucsb.cs156.frontiers.repositories.UserRepository;
10
import java.util.ArrayList;
11
import java.util.List;
12
import java.util.Optional;
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.stereotype.Service;
15
16
@Service
17
public class UpdateUserService {
18
19
  @Autowired private UserRepository userRepository;
20
21
  @Autowired private RosterStudentRepository rosterStudentRepository;
22
  @Autowired private CourseStaffRepository courseStaffRepository;
23
24
  /**
25
   * This method attaches the RosterStudents to the User based on their email.
26
   *
27
   * @param user The user to whom the RosterStudents will be attached
28
   */
29
  public void attachRosterStudents(User user) {
30
    List<RosterStudent> matchedStudents = rosterStudentRepository.findAllByEmail(user.getEmail());
31 2 1. attachRosterStudents : negated conditional → KILLED
2. attachRosterStudents : changed conditional boundary → KILLED
    for (int i = 0; i < matchedStudents.size(); i++) {
32
      RosterStudent matchedStudent = matchedStudents.get(i);
33 1 1. attachRosterStudents : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setUser → KILLED
      matchedStudent.setUser(user);
34
    }
35
    rosterStudentRepository.saveAll(matchedStudents);
36
  }
37
38
  /**
39
   * This method attaches the CourseStaff to the User based on their email.
40
   *
41
   * @param user The user to whom the CourseStaff will be attached
42
   */
43
  public void attachCourseStaff(User user) {
44
    List<CourseStaff> matchedStaff = courseStaffRepository.findAllByEmail(user.getEmail());
45
    for (CourseStaff matched : matchedStaff) {
46 1 1. attachCourseStaff : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setUser → KILLED
      matched.setUser(user);
47
    }
48
    courseStaffRepository.saveAll(matchedStaff);
49
  }
50
51
  /** attach roster students for all Users */
52
  public void attachRosterStudentsAllUsers() {
53
    Iterable<User> allUsers = userRepository.findAll();
54
    for (User user : allUsers) {
55 1 1. attachRosterStudentsAllUsers : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachRosterStudents → KILLED
      attachRosterStudents(user);
56
    }
57
  }
58
59
  /** This method attaches a SingleRoster student to the User based on their email. */
60
  public void attachUserToRosterStudent(RosterStudent rosterStudent) {
61
    String email = rosterStudent.getEmail();
62
    Optional<User> optionalUser = userRepository.findByEmail(email);
63 1 1. attachUserToRosterStudent : negated conditional → KILLED
    if (optionalUser.isPresent()) {
64
      User matchedUser = optionalUser.get();
65 1 1. attachUserToRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setUser → KILLED
      rosterStudent.setUser(matchedUser);
66
      rosterStudentRepository.save(rosterStudent);
67
    }
68
  }
69
70
  /** This method attaches a SingleRoster student to the User based on their email. */
71
  public void attachUsersToRosterStudents(List<RosterStudent> rosterStudents) {
72
    for (RosterStudent matchedStudent : rosterStudents) {
73 1 1. attachUsersToRosterStudents : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachUserToRosterStudent → KILLED
      attachUserToRosterStudent(matchedStudent);
74
    }
75
  }
76
77
  /** This method attaches a Single Course Staff member to the User based on their email. */
78
  public void attachUserToCourseStaff(CourseStaff courseStaff) {
79
    String email = courseStaff.getEmail();
80
    Optional<User> optionalUser = userRepository.findByEmail(email);
81 1 1. attachUserToCourseStaff : negated conditional → KILLED
    if (optionalUser.isPresent()) {
82
      User matchedUser = optionalUser.get();
83 1 1. attachUserToCourseStaff : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setUser → KILLED
      courseStaff.setUser(matchedUser);
84
      courseStaffRepository.save(courseStaff);
85
    }
86
  }
87
88
  public void resetPendingInvitations(User user) {
89
    List<RosterStudent> invitedStudents = new ArrayList<>();
90
    for (RosterStudent student : rosterStudentRepository.findAllByUser(user)) {
91 1 1. resetPendingInvitations : negated conditional → KILLED
      if (student.getOrgStatus() == OrgStatus.INVITED) {
92 1 1. resetPendingInvitations : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED
        student.setOrgStatus(OrgStatus.JOINCOURSE);
93 1 1. resetPendingInvitations : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubId → KILLED
        student.setGithubId(null);
94 1 1. resetPendingInvitations : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubLogin → KILLED
        student.setGithubLogin(null);
95
        invitedStudents.add(student);
96
      }
97
    }
98
    rosterStudentRepository.saveAll(invitedStudents);
99
100
    List<CourseStaff> invitedStaff = new ArrayList<>();
101
    for (CourseStaff staff : courseStaffRepository.findAllByUser(user)) {
102 1 1. resetPendingInvitations : negated conditional → KILLED
      if (staff.getOrgStatus() == OrgStatus.INVITED) {
103 1 1. resetPendingInvitations : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setOrgStatus → KILLED
        staff.setOrgStatus(OrgStatus.JOINCOURSE);
104 1 1. resetPendingInvitations : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setGithubId → KILLED
        staff.setGithubId(null);
105 1 1. resetPendingInvitations : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setGithubLogin → KILLED
        staff.setGithubLogin(null);
106
        invitedStaff.add(staff);
107
      }
108
    }
109
    courseStaffRepository.saveAll(invitedStaff);
110
  }
111
}

Mutations

31

1.1
Location : attachRosterStudents
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachRosterStudents()]
negated conditional → KILLED

2.2
Location : attachRosterStudents
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachRosterStudents()]
changed conditional boundary → KILLED

33

1.1
Location : attachRosterStudents
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachRosterStudents()]
removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setUser → KILLED

46

1.1
Location : attachCourseStaff
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachCourseStaff()]
removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setUser → KILLED

55

1.1
Location : attachRosterStudentsAllUsers
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachRosterStudentsAllUsers()]
removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachRosterStudents → KILLED

63

1.1
Location : attachUserToRosterStudent
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachUserToRosterStudent_userDoesNotExist()]
negated conditional → KILLED

65

1.1
Location : attachUserToRosterStudent
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachUserToRosterStudent_userExists()]
removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setUser → KILLED

73

1.1
Location : attachUsersToRosterStudents
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachUsesrToRosterStudents_userExists()]
removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachUserToRosterStudent → KILLED

81

1.1
Location : attachUserToCourseStaff
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachUserToCourseStaff_userDoesNotExist()]
negated conditional → KILLED

83

1.1
Location : attachUserToCourseStaff
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachUserToCourseStaff_userExists()]
removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setUser → KILLED

91

1.1
Location : resetPendingInvitations
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testResetPendingInvitations_resetsOnlyInvitedStudentsAndStaff()]
negated conditional → KILLED

92

1.1
Location : resetPendingInvitations
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testResetPendingInvitations_resetsOnlyInvitedStudentsAndStaff()]
removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setOrgStatus → KILLED

93

1.1
Location : resetPendingInvitations
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testResetPendingInvitations_resetsOnlyInvitedStudentsAndStaff()]
removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubId → KILLED

94

1.1
Location : resetPendingInvitations
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testResetPendingInvitations_resetsOnlyInvitedStudentsAndStaff()]
removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setGithubLogin → KILLED

102

1.1
Location : resetPendingInvitations
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testResetPendingInvitations_resetsOnlyInvitedStudentsAndStaff()]
negated conditional → KILLED

103

1.1
Location : resetPendingInvitations
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testResetPendingInvitations_resetsOnlyInvitedStudentsAndStaff()]
removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setOrgStatus → KILLED

104

1.1
Location : resetPendingInvitations
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testResetPendingInvitations_resetsOnlyInvitedStudentsAndStaff()]
removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setGithubId → KILLED

105

1.1
Location : resetPendingInvitations
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testResetPendingInvitations_resetsOnlyInvitedStudentsAndStaff()]
removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setGithubLogin → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support